From 68b63083a54577efb9c663e349b06c773fe9755b Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Thu, 9 Apr 2026 00:58:59 +0100 Subject: [PATCH] extracted logic for packs, reorg --- StickerSlack.xcodeproj/project.pbxproj | 46 +++++++++++-------- .../Emoji/Categorisation/EmojiPack.swift | 17 +++++++ .../EmojiPackDetailView.swift | 9 +--- .../EmojiPacks}/EmojiPackManager.swift | 0 StickerSlack/SwiftUI/{ => Misc}/ListRow.swift | 0 .../SwiftUI/{ => Misc}/NoStickersView.swift | 0 .../SwiftUI/{ => Misc}/ViewModifiers.swift | 0 .../SwiftUI/{ => Shared}/StickerPreview.swift | 0 .../SwiftUI/{ => Shared}/StickerRow.swift | 0 9 files changed, 46 insertions(+), 26 deletions(-) rename StickerSlack/SwiftUI/{Emoji => EmojiPacks}/EmojiPackDetailView.swift (96%) rename StickerSlack/{Emoji/Categorisation => SwiftUI/EmojiPacks}/EmojiPackManager.swift (100%) rename StickerSlack/SwiftUI/{ => Misc}/ListRow.swift (100%) rename StickerSlack/SwiftUI/{ => Misc}/NoStickersView.swift (100%) rename StickerSlack/SwiftUI/{ => Misc}/ViewModifiers.swift (100%) rename StickerSlack/SwiftUI/{ => Shared}/StickerPreview.swift (100%) rename StickerSlack/SwiftUI/{ => Shared}/StickerRow.swift (100%) diff --git a/StickerSlack.xcodeproj/project.pbxproj b/StickerSlack.xcodeproj/project.pbxproj index af86e12..1165026 100644 --- a/StickerSlack.xcodeproj/project.pbxproj +++ b/StickerSlack.xcodeproj/project.pbxproj @@ -286,36 +286,32 @@ isa = PBXGroup; children = ( A9D15B892EB1142C00404792 /* EmojiPack.swift */, - A9CD6C372EDDE37500B7F421 /* EmojiPackManager.swift */, A935437A2EB2A3C800BB80A4 /* FilterCategory.swift */, ); path = Categorisation; sourceTree = ""; }; - A91C098C2EBBD7AB00210C34 /* Emoji */ = { + A91C098C2EBBD7AB00210C34 /* EmojiPacks */ = { isa = PBXGroup; children = ( A9CD6C342EDDE22800B7F421 /* EmojiPackDetailView.swift */, + A9CD6C372EDDE37500B7F421 /* EmojiPackManager.swift */, ); - path = Emoji; + path = EmojiPacks; sourceTree = ""; }; A91C098D2EBBD7C100210C34 /* SwiftUI */ = { isa = PBXGroup; children = ( - A9A7A4602F69597000BB84C6 /* Gifs */, A949B1F02EA04E8200215164 /* ContentView.swift */, - A9BBC5172EB8FA4500FFE82F /* ViewModifiers.swift */, - A91C098C2EBBD7AB00210C34 /* Emoji */, - A921C2E12ED071C900E57B1A /* ListRow.swift */, + A91C098C2EBBD7AB00210C34 /* EmojiPacks */, + A9F423C32F87229100C0BE3B /* Shared */, + A9F423C42F8722AA00C0BE3B /* Misc */, A921C2DE2ED067BB00E57B1A /* WelcomeView.swift */, - A9EB72462EB948C400658CEB /* StickerRow.swift */, + A955B3F02EC22E9700E1732D /* BrowseView.swift */, + A955B3EC2EC22C4A00E1732D /* DownloadedView.swift */, A957C1732ECCE2CE00EA3EE9 /* SettingsView.swift */, A955B3F42EC22EE900E1732D /* SearchView.swift */, - A955B3F02EC22E9700E1732D /* BrowseView.swift */, - A9BDEADD2F82BC93002798DF /* NoStickersView.swift */, - A955B3EC2EC22C4A00E1732D /* DownloadedView.swift */, - A9773C2E2EA54AF000F3B753 /* StickerPreview.swift */, ); path = SwiftUI; sourceTree = ""; @@ -434,13 +430,6 @@ path = Cachet; sourceTree = ""; }; - A9A7A4602F69597000BB84C6 /* Gifs */ = { - isa = PBXGroup; - children = ( - ); - path = Gifs; - sourceTree = ""; - }; A9B9A82D2EB2CCBE004C9245 /* StickerSlackTests */ = { isa = PBXGroup; children = ( @@ -468,6 +457,25 @@ path = Stickers; sourceTree = ""; }; + A9F423C32F87229100C0BE3B /* Shared */ = { + isa = PBXGroup; + children = ( + A9EB72462EB948C400658CEB /* StickerRow.swift */, + A9773C2E2EA54AF000F3B753 /* StickerPreview.swift */, + ); + path = Shared; + sourceTree = ""; + }; + A9F423C42F8722AA00C0BE3B /* Misc */ = { + isa = PBXGroup; + children = ( + A9BBC5172EB8FA4500FFE82F /* ViewModifiers.swift */, + A9BDEADD2F82BC93002798DF /* NoStickersView.swift */, + A921C2E12ED071C900E57B1A /* ListRow.swift */, + ); + path = Misc; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ diff --git a/StickerSlack/Emoji/Categorisation/EmojiPack.swift b/StickerSlack/Emoji/Categorisation/EmojiPack.swift index b5d4a72..39ca818 100644 --- a/StickerSlack/Emoji/Categorisation/EmojiPack.swift +++ b/StickerSlack/Emoji/Categorisation/EmojiPack.swift @@ -6,6 +6,7 @@ // import Foundation +import SwiftUI struct EmojiPack: Identifiable, Codable { var id: UUID @@ -18,6 +19,22 @@ struct EmojiPack: Identifiable, Codable { // var id: UUID // var name: String // } + + mutating func add(_ newItem: String) { + guard !items.contains(newItem) else { return } + withAnimation { + self.items.append(newItem) + } + } + + mutating func remove(_ itemToRemove: String) { + guard let index = self.items.firstIndex(where: { $0 == itemToRemove }) else { + return + } + let _ = withAnimation { + self.items.remove(at: index) + } + } } extension EmojiPack { diff --git a/StickerSlack/SwiftUI/Emoji/EmojiPackDetailView.swift b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift similarity index 96% rename from StickerSlack/SwiftUI/Emoji/EmojiPackDetailView.swift rename to StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift index 2cc0201..e233132 100644 --- a/StickerSlack/SwiftUI/Emoji/EmojiPackDetailView.swift +++ b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift @@ -98,9 +98,7 @@ struct EmojiPackDetailView: View { .overlay(alignment: .topLeading) { if edit { Button(role: .destructive) { - withAnimation(.spring) { - pack.items.removeAll { $0 == name } - } + pack.remove(name) } label: { Image(systemName: "minus.circle.fill") .resizable().scaledToFit() @@ -128,10 +126,7 @@ struct EmojiPackDetailView: View { .sheet(isPresented: $showAdder) { NavigationStack { SearchView(hoarder: hoarder, fromPackEditor: true) { selection in - print(selection) - withAnimation { - pack.items.append(selection.name) - } + pack.add(selection.name) } .navigationTitle("Search Emojis") .navigationBarTitleDisplayMode(.inline) diff --git a/StickerSlack/Emoji/Categorisation/EmojiPackManager.swift b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackManager.swift similarity index 100% rename from StickerSlack/Emoji/Categorisation/EmojiPackManager.swift rename to StickerSlack/SwiftUI/EmojiPacks/EmojiPackManager.swift diff --git a/StickerSlack/SwiftUI/ListRow.swift b/StickerSlack/SwiftUI/Misc/ListRow.swift similarity index 100% rename from StickerSlack/SwiftUI/ListRow.swift rename to StickerSlack/SwiftUI/Misc/ListRow.swift diff --git a/StickerSlack/SwiftUI/NoStickersView.swift b/StickerSlack/SwiftUI/Misc/NoStickersView.swift similarity index 100% rename from StickerSlack/SwiftUI/NoStickersView.swift rename to StickerSlack/SwiftUI/Misc/NoStickersView.swift diff --git a/StickerSlack/SwiftUI/ViewModifiers.swift b/StickerSlack/SwiftUI/Misc/ViewModifiers.swift similarity index 100% rename from StickerSlack/SwiftUI/ViewModifiers.swift rename to StickerSlack/SwiftUI/Misc/ViewModifiers.swift diff --git a/StickerSlack/SwiftUI/StickerPreview.swift b/StickerSlack/SwiftUI/Shared/StickerPreview.swift similarity index 100% rename from StickerSlack/SwiftUI/StickerPreview.swift rename to StickerSlack/SwiftUI/Shared/StickerPreview.swift diff --git a/StickerSlack/SwiftUI/StickerRow.swift b/StickerSlack/SwiftUI/Shared/StickerRow.swift similarity index 100% rename from StickerSlack/SwiftUI/StickerRow.swift rename to StickerSlack/SwiftUI/Shared/StickerRow.swift