mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 12:44:51 +00:00
extracted logic for packs, reorg
This commit is contained in:
9 files changed
+46
-26
No files matched your search
@@ -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 {
|
||||
|
||||
+2
-7
@@ -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)
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.