mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 12:44: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 {
|
class EmojiHoarder: BaseHoarder {
|
||||||
static let container: URL = library.appendingPathComponent("Emojis", conformingTo: .directory)
|
static let container: URL = library.appendingPathComponent("Emojis", conformingTo: .directory)
|
||||||
nonisolated static let localEmojiDB: URL = EmojiHoarder.library.appendingPathComponent("_____localEmojiDB.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 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")!
|
let endpoint: URL = URL(string: "https://cachet.dunkirk.sh/emojis")!
|
||||||
|
|
||||||
@Published var emojis: [Emoji] = []
|
@Published var emojis: [Emoji] = []
|
||||||
@@ -37,6 +38,8 @@ class EmojiHoarder: BaseHoarder {
|
|||||||
try! FileManager.default.createDirectory(at: EmojiHoarder.container, withIntermediateDirectories: true)
|
try! FileManager.default.createDirectory(at: EmojiHoarder.container, withIntermediateDirectories: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadEmojiPacks()
|
||||||
|
|
||||||
self.emojis = loadLocalDB()
|
self.emojis = loadLocalDB()
|
||||||
loadTrie()
|
loadTrie()
|
||||||
|
|
||||||
@@ -247,7 +250,9 @@ class EmojiHoarder: BaseHoarder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func loadEmojiPacks() {
|
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() {
|
func saveEmojiPacks() {
|
||||||
@@ -255,8 +260,26 @@ class EmojiHoarder: BaseHoarder {
|
|||||||
for pack in emojiPacks {
|
for pack in emojiPacks {
|
||||||
toStore.append(pack.shareLink())
|
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() {
|
func generateLetterStats() {
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ struct EmojiPackDetailView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onDisappear {
|
.onDisappear {
|
||||||
hoarder.
|
hoarder.saveEmojiPacks()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,7 @@ struct EmojiPackImporterView: View {
|
|||||||
EmojiPackDetailView(hoarder: emojiHoarder, pack: $pack)
|
EmojiPackDetailView(hoarder: emojiHoarder, pack: $pack)
|
||||||
.overlay(alignment: .bottomLeading) {
|
.overlay(alignment: .bottomLeading) {
|
||||||
Button {
|
Button {
|
||||||
withAnimation {
|
|
||||||
emojiHoarder.emojiPacks.append(pack)
|
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
|
||||||
} label: {
|
} label: {
|
||||||
Text("Cancel")
|
Text("Cancel")
|
||||||
.font(.title3)
|
.font(.title3)
|
||||||
@@ -31,10 +28,8 @@ struct EmojiPackImporterView: View {
|
|||||||
}
|
}
|
||||||
.overlay(alignment: .bottomTrailing) {
|
.overlay(alignment: .bottomTrailing) {
|
||||||
Button {
|
Button {
|
||||||
withAnimation {
|
emojiHoarder.addEmojiPack(pack)
|
||||||
emojiHoarder.emojiPacks.append(pack)
|
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
|
||||||
} label: {
|
} label: {
|
||||||
Text("Add")
|
Text("Add")
|
||||||
.font(.title3)
|
.font(.title3)
|
||||||
|
|||||||
@@ -21,9 +21,7 @@ struct EmojiPackManager: View {
|
|||||||
}
|
}
|
||||||
.swipeActions(edge: .trailing) {
|
.swipeActions(edge: .trailing) {
|
||||||
Button {
|
Button {
|
||||||
withAnimation {
|
hoarder.removeEmojiPack(pack)
|
||||||
hoarder.emojiPacks.removeAll { $0.id == pack.id }
|
|
||||||
}
|
|
||||||
} label: {
|
} label: {
|
||||||
Label("Delete", systemImage: "trash")
|
Label("Delete", systemImage: "trash")
|
||||||
}
|
}
|
||||||
@@ -42,9 +40,7 @@ struct EmojiPackManager: View {
|
|||||||
.toolbar {
|
.toolbar {
|
||||||
ToolbarItem {
|
ToolbarItem {
|
||||||
Button {
|
Button {
|
||||||
withAnimation {
|
hoarder.newEmojiPack()
|
||||||
hoarder.emojiPacks.append(.new())
|
|
||||||
}
|
|
||||||
} label: {
|
} label: {
|
||||||
Image(systemName: "plus")
|
Image(systemName: "plus")
|
||||||
}
|
}
|
||||||
|
|||||||