mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 20:54:51 +00:00
emojipacks should save and load
extracted logic into emojhoarder
This commit is contained in:
4 files changed
+31
-17
No files matched your search
@@ -13,8 +13,9 @@ import Haptics
|
||||
|
||||
class EmojiHoarder: BaseHoarder {
|
||||
static let container: URL = library.appendingPathComponent("Emojis", conformingTo: .directory)
|
||||
nonisolated static let localEmojiDB: URL = EmojiHoarder.library.appendingPathComponent("_____localEmojiDB.json", conformingTo: .fileURL)
|
||||
nonisolated static let localTrieDict: URL = EmojiHoarder.library.appendingPathComponent("_____localTrieDict.json", conformingTo: .fileURL)
|
||||
nonisolated static let localEmojiDB: URL = EmojiHoarder.library.appendingPathComponent("localEmojiDB.json", conformingTo: .fileURL)
|
||||
nonisolated static let localTrieDict: URL = EmojiHoarder.library.appendingPathComponent("localTrieDict.json", conformingTo: .fileURL)
|
||||
nonisolated static let packStore: URL = EmojiHoarder.library.appendingPathComponent("packStore.json", conformingTo: .fileURL)
|
||||
let endpoint: URL = URL(string: "https://cachet.dunkirk.sh/emojis")!
|
||||
|
||||
@Published var emojis: [Emoji] = []
|
||||
@@ -37,6 +38,8 @@ class EmojiHoarder: BaseHoarder {
|
||||
try! FileManager.default.createDirectory(at: EmojiHoarder.container, withIntermediateDirectories: true)
|
||||
}
|
||||
|
||||
loadEmojiPacks()
|
||||
|
||||
self.emojis = loadLocalDB()
|
||||
loadTrie()
|
||||
|
||||
@@ -247,7 +250,9 @@ class EmojiHoarder: BaseHoarder {
|
||||
}
|
||||
|
||||
func loadEmojiPacks() {
|
||||
|
||||
guard let data = try? Data(contentsOf: Self.packStore),
|
||||
let decoded = try? decoder.decode([URL].self, from: data) else { return }
|
||||
self.emojiPacks = decoded.map { EmojiPack(fromShareLink: $0) }
|
||||
}
|
||||
|
||||
func saveEmojiPacks() {
|
||||
@@ -255,8 +260,26 @@ class EmojiHoarder: BaseHoarder {
|
||||
for pack in emojiPacks {
|
||||
toStore.append(pack.shareLink())
|
||||
}
|
||||
guard let encoded = try? JSONEncoder().encode(toStore) else { return }
|
||||
guard let encoded = try? encoder.encode(toStore) else { return }
|
||||
try? encoded.write(to: Self.packStore)
|
||||
}
|
||||
|
||||
func newEmojiPack() {
|
||||
addEmojiPack(.new())
|
||||
}
|
||||
|
||||
func addEmojiPack(_ packToAdd: EmojiPack) {
|
||||
withAnimation {
|
||||
emojiPacks.append(packToAdd)
|
||||
}
|
||||
saveEmojiPacks()
|
||||
}
|
||||
|
||||
func removeEmojiPack(_ packToRemove: EmojiPack) {
|
||||
withAnimation {
|
||||
emojiPacks.removeAll { $0.id == packToRemove.id }
|
||||
}
|
||||
saveEmojiPacks()
|
||||
}
|
||||
|
||||
func generateLetterStats() {
|
||||
|
||||
@@ -173,7 +173,7 @@ struct EmojiPackDetailView: View {
|
||||
}
|
||||
}
|
||||
.onDisappear {
|
||||
hoarder.
|
||||
hoarder.saveEmojiPacks()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,7 @@ struct EmojiPackImporterView: View {
|
||||
EmojiPackDetailView(hoarder: emojiHoarder, pack: $pack)
|
||||
.overlay(alignment: .bottomLeading) {
|
||||
Button {
|
||||
withAnimation {
|
||||
emojiHoarder.emojiPacks.append(pack)
|
||||
dismiss()
|
||||
}
|
||||
} label: {
|
||||
Text("Cancel")
|
||||
.font(.title3)
|
||||
@@ -31,10 +28,8 @@ struct EmojiPackImporterView: View {
|
||||
}
|
||||
.overlay(alignment: .bottomTrailing) {
|
||||
Button {
|
||||
withAnimation {
|
||||
emojiHoarder.emojiPacks.append(pack)
|
||||
emojiHoarder.addEmojiPack(pack)
|
||||
dismiss()
|
||||
}
|
||||
} label: {
|
||||
Text("Add")
|
||||
.font(.title3)
|
||||
|
||||
@@ -21,9 +21,7 @@ struct EmojiPackManager: View {
|
||||
}
|
||||
.swipeActions(edge: .trailing) {
|
||||
Button {
|
||||
withAnimation {
|
||||
hoarder.emojiPacks.removeAll { $0.id == pack.id }
|
||||
}
|
||||
hoarder.removeEmojiPack(pack)
|
||||
} label: {
|
||||
Label("Delete", systemImage: "trash")
|
||||
}
|
||||
@@ -42,9 +40,7 @@ struct EmojiPackManager: View {
|
||||
.toolbar {
|
||||
ToolbarItem {
|
||||
Button {
|
||||
withAnimation {
|
||||
hoarder.emojiPacks.append(.new())
|
||||
}
|
||||
hoarder.newEmojiPack()
|
||||
} label: {
|
||||
Image(systemName: "plus")
|
||||
}
|
||||
|
||||