mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 12:44:51 +00:00
fix state issues for packs
fix crash
This commit is contained in:
4 files changed
+9
-37
No files matched your search
@@ -15,7 +15,6 @@ extension EmojiHoarder {
|
||||
self.emojiPacks = decoded.map {
|
||||
EmojiPack(fromShareLink: $0) ?? .new()
|
||||
}
|
||||
sendChangeNotif(for: .emojiPacks)
|
||||
}
|
||||
|
||||
func saveEmojiPacks() {
|
||||
@@ -39,7 +38,6 @@ extension EmojiHoarder {
|
||||
withAnimation {
|
||||
emojiPacks.append(packToAdd)
|
||||
}
|
||||
sendChangeNotif(for: .emojiPacks)
|
||||
saveEmojiPacks()
|
||||
}
|
||||
|
||||
@@ -47,8 +45,6 @@ extension EmojiHoarder {
|
||||
withAnimation {
|
||||
emojiPacks.removeAll { $0.id == packToRemove.id }
|
||||
}
|
||||
sendChangeNotif(for: .emojiPack(packToRemove.id))
|
||||
sendChangeNotif(for: .emojiPacks)
|
||||
saveEmojiPacks()
|
||||
}
|
||||
|
||||
@@ -56,7 +52,6 @@ extension EmojiHoarder {
|
||||
withAnimation {
|
||||
emojiPacks.remove(atOffsets: offset)
|
||||
}
|
||||
sendChangeNotif(for: .emojiPacks)
|
||||
saveEmojiPacks()
|
||||
}
|
||||
|
||||
@@ -65,7 +60,6 @@ extension EmojiHoarder {
|
||||
withAnimation {
|
||||
self.emojiPacks[index] = updatedPack
|
||||
}
|
||||
sendChangeNotif(for: .emojiPacks)
|
||||
saveEmojiPacks()
|
||||
}
|
||||
|
||||
@@ -73,7 +67,6 @@ extension EmojiHoarder {
|
||||
withAnimation {
|
||||
emojiPacks.move(fromOffsets: fromOffsets, toOffset: toOffset)
|
||||
}
|
||||
sendChangeNotif(for: .emojiPacks)
|
||||
saveEmojiPacks()
|
||||
}
|
||||
}
|
||||
@@ -269,8 +269,6 @@ class EmojiHoarder: BaseHoarder {
|
||||
enum NotifCategory {
|
||||
case emojis
|
||||
case downloadedEmojis
|
||||
case emojiPacks
|
||||
case emojiPack(UUID)
|
||||
|
||||
var name: Notification.Name {
|
||||
switch self {
|
||||
@@ -278,10 +276,6 @@ class EmojiHoarder: BaseHoarder {
|
||||
Notification.Name("EmojiHoarder.notif.emojis")
|
||||
case .downloadedEmojis:
|
||||
Notification.Name("EmojiHoarder.notif.downloadedEmojis")
|
||||
case .emojiPacks:
|
||||
Notification.Name("EmojiHoarder.notif.emojiPacks")
|
||||
case .emojiPack(let emojiPackID):
|
||||
Notification.Name("EmojiHoarder.notif.emojiPack.\(emojiPackID)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,27 +105,12 @@ class EmojiPackDetailViewController: UIViewController {
|
||||
let x = UIBarButtonItem(title: "menu", image: UIImage(systemName: "ellipsis"), primaryAction: nil, menu: UIMenu(children: [shareButton2, downloadButton2]))
|
||||
|
||||
self.navigationItem.rightBarButtonItems = [collectionView.editButtonItem, x]
|
||||
|
||||
// NotificationCenter.default.addObserver(
|
||||
// self,
|
||||
// selector: #selector(packChanged),
|
||||
// name: EmojiHoarder.NotifCategory.emojiPack(pack.id).name,
|
||||
// object: nil
|
||||
// )
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
@objc func packChanged(_ notification: Notification) {
|
||||
guard notification.name == EmojiHoarder.NotifCategory.emojiPack(pack.id).name else { return }
|
||||
guard let updatedPack = hoarder.emojiPacks.first(where: { $0.id == pack.id }) else { return }
|
||||
self.pack = updatedPack
|
||||
self.navigationItem.title = pack.name
|
||||
collectionView.refreshUI(with: pack.items)
|
||||
}
|
||||
|
||||
@objc func showSheet() {
|
||||
if let sheet = searchView.sheetPresentationController {
|
||||
sheet.detents = [.medium(), .large()]
|
||||
@@ -167,7 +152,10 @@ class EmojiPackDetailViewController: UIViewController {
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
NotificationCenter.default.post(name: EmojiHoarder.NotifCategory.emojiPack(pack.id).name, object: nil)
|
||||
guard let updatedPack = hoarder.emojiPacks.first(where: { $0.id == pack.id }) else { return }
|
||||
self.pack = updatedPack
|
||||
self.navigationItem.title = pack.name
|
||||
collectionView.refreshUI(with: pack.items)
|
||||
}
|
||||
|
||||
override func viewWillDisappear(_ animated: Bool) {
|
||||
|
||||
@@ -29,13 +29,6 @@ class EmojiPackListView: UITableViewController {
|
||||
self.multiDeleteButton = UIBarButtonItem(image: UIImage(systemName: "trash"), style: .plain, target: self, action: #selector(multiDelete))
|
||||
self.setToolbarItems([multiDeleteButton], animated: true)
|
||||
|
||||
NotificationCenter.default.addObserver(
|
||||
self,
|
||||
selector: #selector(refresh),
|
||||
name: EmojiHoarder.NotifCategory.emojiPacks.name,
|
||||
object: nil
|
||||
)
|
||||
|
||||
self.navigationItem.leftBarButtonItem = UIBarButtonItem(
|
||||
image: UIImage(systemName: "plus"),
|
||||
style: .plain,
|
||||
@@ -149,6 +142,10 @@ class EmojiPackListView: UITableViewController {
|
||||
return UISwipeActionsConfiguration(actions: [delete, share, dupButton])
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
self.tableView.reloadData()
|
||||
}
|
||||
|
||||
override func setEditing(_ editing: Bool, animated: Bool) {
|
||||
super.setEditing(editing, animated: animated)
|
||||
self.navigationController?.setToolbarHidden(!editing, animated: true)
|
||||
@@ -163,7 +160,7 @@ class EmojiPackListView: UITableViewController {
|
||||
}
|
||||
|
||||
@objc func refresh(_ notification: Notification) {
|
||||
self.tableView.reloadData()
|
||||
// self.tableView.reloadData()
|
||||
}
|
||||
|
||||
func delete(_ indexPath: IndexPath) {
|
||||
|
||||