fix crash when deleting from downloaded view

This commit is contained in:
neon443 committed 2026-06-12 22:43:41 +01:00
1 parent ef1aa61728
commit e4ecf31c39
1 file changed
+2 -14
@@ -213,14 +213,6 @@ struct EmojiCollectionView: UIViewRepresentable {
var menuChildrem: [UIMenuElement] = [] var menuChildrem: [UIMenuElement] = []
let emojiName = self.items[indexPath.row] let emojiName = self.items[indexPath.row]
// if let localImagePath = hoarder.trie.dict[emojiName]?.localImageURLString,
// let attrs = try? FileManager.default.attributesOfItem(atPath: localImagePath),
// let size = attrs[FileAttributeKey("NSFileSize")] {
// print(size, "bytes")
// let sizeLabel = UIAction(title: "\(size as! Int/1000) KB", image: nil, identifier: nil, discoverabilityTitle: nil, attributes: .disabled) { _ in }
// menuChildrem.append(sizeLabel)
// }
let packMenuItem: (EmojiHoarder, Int) -> UIAction = { hoarder, packIndex in let packMenuItem: (EmojiHoarder, Int) -> UIAction = { hoarder, packIndex in
let pack = hoarder.emojiPacks[packIndex] let pack = hoarder.emojiPacks[packIndex]
return UIAction( return UIAction(
@@ -245,7 +237,6 @@ struct EmojiCollectionView: UIViewRepresentable {
] ]
) )
packMenuItems.append(createNewPackMenu) packMenuItems.append(createNewPackMenu)
// let addToPackMenu = UIMenu(title: "Add to Pack", image: UIImage(systemName: "square.stack.3d.up.fill"), children: packMenuItems)
menuChildrem.append(UIMenu(title: "Add to Pack", image: UIImage(systemName: "square.stack.3d.up.fill"), children: packMenuItems)) menuChildrem.append(UIMenu(title: "Add to Pack", image: UIImage(systemName: "square.stack.3d.up.fill"), children: packMenuItems))
let copyName = UIAction(title: "Copy Name", image: UIImage(systemName: "doc.on.clipboard")) { action in let copyName = UIAction(title: "Copy Name", image: UIImage(systemName: "doc.on.clipboard")) { action in
@@ -259,7 +250,6 @@ struct EmojiCollectionView: UIViewRepresentable {
let share = UIAction(title: "Share", image: UIImage(systemName: "square.and.arrow.up")) { action in let share = UIAction(title: "Share", image: UIImage(systemName: "square.and.arrow.up")) { action in
} }
// let sharingMenu = UIMenu(options: .displayInline, children: [copyName, copyImage, share])
menuChildrem.append(UIMenu(options: .displayInline, children: [copyName, copyImage, share])) menuChildrem.append(UIMenu(options: .displayInline, children: [copyName, copyImage, share]))
let delete = UIAction(title: "Delete", image: UIImage(systemName: "trash")) { action in let delete = UIAction(title: "Delete", image: UIImage(systemName: "trash")) { action in
@@ -267,15 +257,13 @@ struct EmojiCollectionView: UIViewRepresentable {
await self.hoarder.delete(emoji: self.hoarder.trie.dict[emojiName]) await self.hoarder.delete(emoji: self.hoarder.trie.dict[emojiName])
} }
self.items.remove(at: indexPath.row) self.items.remove(at: indexPath.row)
collectionView.performBatchUpdates { Task.detached {
collectionView.deleteItems(at: [indexPath]) await self.applySnapshot(animated: true)
} }
} }
delete.attributes.update(with: .destructive) delete.attributes.update(with: .destructive)
// let destructiveMenu = UIMenu(options: .displayInline, children: [delete])
menuChildrem.append(UIMenu(options: .displayInline, children: [delete])) menuChildrem.append(UIMenu(options: .displayInline, children: [delete]))
// let menu = UIMenu(title: emojiName, children: [addToPackMenu, sharingMenu, destructiveMenu])
let menu = UIMenu(title: emojiName, children: menuChildrem) let menu = UIMenu(title: emojiName, children: menuChildrem)
return UIContextMenuConfiguration( return UIContextMenuConfiguration(
identifier: nil, identifier: nil,
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.