mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 12:44:51 +00:00
save emojipacks on modify from stickerrow
extract addtoemojipackmenuview shit progress bar for downloads
This commit is contained in:
8 files changed
+95
-50
No files matched your search
@@ -14,7 +14,6 @@ struct EmojiPack: Identifiable, Codable, Equatable {
|
||||
var name: String
|
||||
var description: String
|
||||
var items: [String]
|
||||
var allDownloaded: Bool = false
|
||||
|
||||
init(id: UUID, name: String, description: String, items: [String]) {
|
||||
self.id = id
|
||||
@@ -134,15 +133,27 @@ struct EmojiPack: Identifiable, Codable, Equatable {
|
||||
url = components!.url!
|
||||
return url
|
||||
}
|
||||
|
||||
func allDownloaded(in hoarder: EmojiHoarder) -> Bool {
|
||||
guard !items.isEmpty else { return false }
|
||||
return Set(self.items).isSubset(of: hoarder.downloadedStickers)
|
||||
}
|
||||
|
||||
func downloadedFraction(in hoarder: EmojiHoarder) -> Double {
|
||||
guard !items.isEmpty else { return 0 }
|
||||
guard !allDownloaded(in: hoarder) else { return 1 }
|
||||
let common = hoarder.downloadedStickers.intersection(items)
|
||||
return Double(common.count)/Double(items.count)
|
||||
}
|
||||
}
|
||||
|
||||
extension EmojiPack {
|
||||
static func new() -> EmojiPack {
|
||||
static func new(withItems items: [String] = []) -> EmojiPack {
|
||||
EmojiPack(
|
||||
id: UUID(),
|
||||
name: "New Pack",
|
||||
description: "Created on \(Date().formatted())",
|
||||
items: []
|
||||
items: items
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -199,7 +199,6 @@ class EmojiHoarder: BaseHoarder {
|
||||
nonisolated func batchDownload(emojis emojisToDownload: [any StickerProtocol]) async {
|
||||
for emoji in emojisToDownload {
|
||||
await download(emoji: emoji, skipStoreIndex: true)
|
||||
|
||||
}
|
||||
|
||||
await buildDownloadedStickers()
|
||||
@@ -210,7 +209,6 @@ class EmojiHoarder: BaseHoarder {
|
||||
await super.download(emoji: emoji, skipStoreIndex: skipStoreIndex)
|
||||
|
||||
await MainActor.run {
|
||||
emojis.insert(.test, at: emojis.count-2)
|
||||
if !skipStoreIndex {
|
||||
let _ = withAnimation(.snappy) {
|
||||
self.downloadedStickers.insert(emoji.name)
|
||||
@@ -263,8 +261,8 @@ class EmojiHoarder: BaseHoarder {
|
||||
try? encoded.write(to: Self.packStore)
|
||||
}
|
||||
|
||||
func newEmojiPack() {
|
||||
addEmojiPack(.new())
|
||||
func newEmojiPack(withItems items: [String] = []) {
|
||||
addEmojiPack(.new(withItems: items))
|
||||
}
|
||||
|
||||
func addEmojiPack(_ packToAdd: EmojiPack) {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// AddToPackMenuView.swift
|
||||
// StickerSlack
|
||||
//
|
||||
// Created by neon443 on 01/05/2026.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct AddToPackMenuView: View {
|
||||
@ObservedObject var emojiHoarder: EmojiHoarder
|
||||
@State var sticker: Emoji
|
||||
|
||||
var body: some View {
|
||||
Menu {
|
||||
Button("Create new", systemImage: "plus") {
|
||||
emojiHoarder.newEmojiPack(withItems: [sticker.name])
|
||||
}
|
||||
Divider()
|
||||
if emojiHoarder.emojiPacks.isEmpty {
|
||||
Label("No Packs", systemImage: "questionmark.app.dashed")
|
||||
} else {
|
||||
Label("Add to Pack", systemImage: "square.stack.3d.up.fill")
|
||||
}
|
||||
ForEach($emojiHoarder.emojiPacks) { $pack in
|
||||
Button() {
|
||||
pack.addRemove(sticker.name)
|
||||
emojiHoarder.saveEmojiPacks()
|
||||
} label: {
|
||||
if pack.items.contains(sticker.name) {
|
||||
Image(systemName: "checkmark")
|
||||
}
|
||||
Text(pack.name)
|
||||
Text("\(pack.items.count) item"+pack.items.count.plural)
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
Image(systemName: "plus")
|
||||
.resizable().scaledToFit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
AddToPackMenuView(emojiHoarder: EmojiHoarder(localOnly: true, skipIndex: true), sticker: .test)
|
||||
}
|
||||
@@ -20,10 +20,10 @@ struct EmojiPackDetailView: View {
|
||||
@State var useSwiftUIGrid: Bool = false
|
||||
|
||||
var allDownloaded: Bool {
|
||||
let date = Date.now
|
||||
let result = Set(pack.items).isSubset(of: hoarder.downloadedStickers)
|
||||
// print("hit \(Date.now.timeIntervalSince(date)) \(UUID())")
|
||||
return result
|
||||
pack.allDownloaded(in: hoarder)
|
||||
}
|
||||
var downloadedFraction: Double {
|
||||
pack.downloadedFraction(in: hoarder)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
@@ -88,6 +88,19 @@ struct EmojiPackDetailView: View {
|
||||
hoarder.saveEmojiPacks()
|
||||
}
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .topBarLeading) {
|
||||
Circle()
|
||||
.trim(from: 0, to: pack.downloadedFraction(in: hoarder))
|
||||
.stroke(
|
||||
.foreground,
|
||||
style: StrokeStyle(
|
||||
lineWidth: 5,
|
||||
lineCap: .round
|
||||
)
|
||||
)
|
||||
.rotationEffect(.degrees(-90))
|
||||
.padding(5)
|
||||
}
|
||||
ToolbarItem(placement: .topBarLeading) {
|
||||
Button(
|
||||
"",
|
||||
|
||||
@@ -107,41 +107,6 @@ struct StickerRow<T: Hoarder>: View {
|
||||
}
|
||||
}
|
||||
|
||||
struct AddToPackMenuView: View {
|
||||
@ObservedObject var emojiHoarder: EmojiHoarder
|
||||
@State var sticker: Emoji
|
||||
|
||||
var body: some View {
|
||||
Menu {
|
||||
Button("Create new", systemImage: "plus") {
|
||||
var newPack = EmojiPack.new()
|
||||
newPack.add(sticker.name)
|
||||
emojiHoarder.emojiPacks.append(newPack)
|
||||
}
|
||||
Divider()
|
||||
if emojiHoarder.emojiPacks.isEmpty {
|
||||
Label("No Packs", systemImage: "questionmark.app.dashed")
|
||||
} else {
|
||||
Label("Add to Pack", systemImage: "square.stack.3d.up.fill")
|
||||
}
|
||||
ForEach($emojiHoarder.emojiPacks) { $pack in
|
||||
Button() {
|
||||
pack.addRemove(sticker.name)
|
||||
} label: {
|
||||
if pack.items.contains(sticker.name) {
|
||||
Image(systemName: "checkmark")
|
||||
}
|
||||
Text(pack.name)
|
||||
Text("\(pack.items.count) item"+pack.items.count.plural)
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
Image(systemName: "plus")
|
||||
.resizable().scaledToFit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 17, *)
|
||||
#Preview {
|
||||
@Previewable var hoarder = EmojiHoarder()
|
||||
|
||||
@@ -77,6 +77,8 @@ struct EmojiCollectionView: UIViewRepresentable {
|
||||
var edit: Bool? = false
|
||||
var onRemove: ((String) -> Void)?
|
||||
|
||||
var dataSource: UICollectionViewDiffableDataSource<Int, String>!
|
||||
|
||||
// [width: [label: height]]
|
||||
static var labelSizeDict: [CGFloat: [String: CGFloat]] = [:]
|
||||
|
||||
@@ -101,8 +103,13 @@ struct EmojiCollectionView: UIViewRepresentable {
|
||||
self.style = style
|
||||
|
||||
layout.minimumInteritemSpacing = 8
|
||||
|
||||
super.init(collectionViewLayout: layout)
|
||||
|
||||
self.dataSource = UICollectionViewDiffableDataSource<Int, String>(collectionView: collectionView) { (collectionView: UICollectionView, indexPath: IndexPath, itemIdentifier: String) -> UICollectionViewCell? in
|
||||
collectionView.cellForItem(at: indexPath)
|
||||
}
|
||||
collectionView.dataSource = dataSource
|
||||
|
||||
collectionView.contentInset = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
|
||||
}
|
||||
|
||||
|
||||
@@ -28,11 +28,10 @@ struct EmojiTableView: UIViewRepresentable {
|
||||
context.coordinator.items = items
|
||||
// guard itemsBefore != itemsAfter else { return }
|
||||
Task.detached {
|
||||
if !(-10_000...10_000).contains(itemsBefore.count-itemsAfter.count) {
|
||||
if !(-10_000...10_000).contains(itemsBefore.count-itemsAfter.count) ||
|
||||
itemsAfter == itemsBefore {
|
||||
//diff of more than 10k
|
||||
await context.coordinator.instantApplySnapshot()
|
||||
} else if itemsAfter == itemsBefore {
|
||||
await context.coordinator.instantApplySnapshot()
|
||||
} else {
|
||||
await context.coordinator.applySnapshot(animated: true)
|
||||
}
|
||||
|
||||