From 6096173751b3235a23ad378e7b0729f81885b66b Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Wed, 8 Apr 2026 18:51:14 +0100 Subject: [PATCH] fixed some gifs not being loaded as downloaded -added UIName to separate the gif's slug and title fixed downloading gifs into emoji container --- StickerSlack/Emoji/Emoji.swift | 4 ++++ StickerSlack/Gifs/Gif.swift | 4 +++- StickerSlack/Models/Giphy/GifObject.swift | 5 +++-- StickerSlack/Stickers/Sticker.swift | 12 +++++++++-- StickerSlack/Stickers/StickerProtocol.swift | 1 + StickerSlack/SwiftUI/BrowseView.swift | 20 +++++++++++++++---- StickerSlack/SwiftUI/DownloadedView.swift | 4 ++-- .../SwiftUI/Emoji/EmojiPackDetailView.swift | 2 +- StickerSlack/SwiftUI/StickerPreview.swift | 2 +- StickerSlack/SwiftUI/StickerRow.swift | 2 +- 10 files changed, 42 insertions(+), 14 deletions(-) diff --git a/StickerSlack/Emoji/Emoji.swift b/StickerSlack/Emoji/Emoji.swift index 84b7a57..6914e71 100644 --- a/StickerSlack/Emoji/Emoji.swift +++ b/StickerSlack/Emoji/Emoji.swift @@ -14,6 +14,10 @@ import UniformTypeIdentifiers struct Emoji: StickerProtocol { var id: String var name: String + var UIName: String { + get { name } + set { return } + } var typeGlyph: String = "slack.logo" var remoteImageURL: URL diff --git a/StickerSlack/Gifs/Gif.swift b/StickerSlack/Gifs/Gif.swift index ee7de07..7a979c0 100644 --- a/StickerSlack/Gifs/Gif.swift +++ b/StickerSlack/Gifs/Gif.swift @@ -12,9 +12,9 @@ import UniformTypeIdentifiers struct Gif: StickerProtocol { var id: String var name: String + var UIName: String var typeGlyph: String = "giphy.logo" var remoteImageURL: URL - var giphyImages: GiphyImages? // enum CodingKeys: String, CodingKey { @@ -23,12 +23,14 @@ struct Gif: StickerProtocol { init( name: String, + UIName: String, url: URL, giphyImages: GiphyImages?, id: String = UUID().uuidString ) { self.id = id self.name = name + self.UIName = UIName self.giphyImages = giphyImages self.remoteImageURL = url } diff --git a/StickerSlack/Models/Giphy/GifObject.swift b/StickerSlack/Models/Giphy/GifObject.swift index 042548d..24b7b6e 100644 --- a/StickerSlack/Models/Giphy/GifObject.swift +++ b/StickerSlack/Models/Giphy/GifObject.swift @@ -32,8 +32,9 @@ struct GifObject: Codable, Identifiable { var toGif: Gif { return Gif( - name: self.title, - url: URL(string: self.images.fixed_width.url)!, + name: self.slug, + UIName: self.title, + url: URL(string: self.images.original.url)!, giphyImages: images, id: self.id ) diff --git a/StickerSlack/Stickers/Sticker.swift b/StickerSlack/Stickers/Sticker.swift index 0d4a9f5..14b2e62 100644 --- a/StickerSlack/Stickers/Sticker.swift +++ b/StickerSlack/Stickers/Sticker.swift @@ -10,10 +10,18 @@ import Messages extension StickerProtocol { var localImageURLString: String { + let containerPath: String + if type(of: self) == Emoji.self { + containerPath = EmojiHoarder.container.path() + } else if type(of: self) == Gif.self { + containerPath = GifHoarder.container.path() + } else { + fatalError("sticker type unrecogniesd") + } let urlString = remoteImageURL.absoluteString let split = urlString.split(separator: ".") - let fileExtension = ".\(split.last ?? "png")" - return EmojiHoarder.container.path()+name+"."+id+fileExtension + let fileExtension = ".\(split.last!)" + return containerPath+name+"."+id+fileExtension } var localImageURL: URL { diff --git a/StickerSlack/Stickers/StickerProtocol.swift b/StickerSlack/Stickers/StickerProtocol.swift index baeb478..ceccec6 100644 --- a/StickerSlack/Stickers/StickerProtocol.swift +++ b/StickerSlack/Stickers/StickerProtocol.swift @@ -11,6 +11,7 @@ import Messages protocol StickerProtocol: Codable, Identifiable, Hashable { var id: String { get set } var name: String { get set } + var UIName: String { get set } var typeGlyph: String { get } diff --git a/StickerSlack/SwiftUI/BrowseView.swift b/StickerSlack/SwiftUI/BrowseView.swift index 25dc28d..bc88148 100644 --- a/StickerSlack/SwiftUI/BrowseView.swift +++ b/StickerSlack/SwiftUI/BrowseView.swift @@ -31,12 +31,24 @@ struct BrowseView: View { .ignoresSafeArea(.container, edges: .bottom) .id(emojiHoarder.emojis) case .giphyGifs: - ScrollView { - ForEach(gifHoarder.trendingGifs) { gif in - StickerRow(hoarder: gifHoarder, sticker: gif) - .listRowSeparator(.hidden) + Button("download all") { + Task { + for gif in gifHoarder.trendingGifs { + await gifHoarder.download(emoji: gif) + } } } + Button("del all") { + for gif in gifHoarder.trendingGifs { + gifHoarder.delete(emoji: gif) + } + } + List { + ForEach(gifHoarder.trendingGifs) { gif in + StickerRow(hoarder: gifHoarder, sticker: gif) + } + } + .listRowSeparator(.hidden) } } } diff --git a/StickerSlack/SwiftUI/DownloadedView.swift b/StickerSlack/SwiftUI/DownloadedView.swift index a7183db..7684119 100644 --- a/StickerSlack/SwiftUI/DownloadedView.swift +++ b/StickerSlack/SwiftUI/DownloadedView.swift @@ -54,9 +54,9 @@ struct DownloadedView: View { .aspectRatio(1, contentMode: .fit) .clipShape(RoundedRectangle(cornerRadius: 15)) .contextMenu { - Text(emoji.name) + Text(emoji.UIName) Button("Copy Name", systemImage: "doc.on.clipboard") { - UIPasteboard.general.string = emoji.name + UIPasteboard.general.string = emoji.UIName } Button("Copy Image", systemImage: "photo.fill.on.rectangle.fill") { UIPasteboard.general.image = emoji.image diff --git a/StickerSlack/SwiftUI/Emoji/EmojiPackDetailView.swift b/StickerSlack/SwiftUI/Emoji/EmojiPackDetailView.swift index d85baec..a0f2c6d 100644 --- a/StickerSlack/SwiftUI/Emoji/EmojiPackDetailView.swift +++ b/StickerSlack/SwiftUI/Emoji/EmojiPackDetailView.swift @@ -61,7 +61,7 @@ struct EmojiPackDetailView: View { let emoji = hoarder.trie.dict[name] ?? .test VStack { StickerPreview(sticker: emoji) - Text(emoji.name) + Text(emoji.UIName) .multilineTextAlignment(.center) .font(.caption) Spacer() diff --git a/StickerSlack/SwiftUI/StickerPreview.swift b/StickerSlack/SwiftUI/StickerPreview.swift index b0e6011..a907a9d 100644 --- a/StickerSlack/SwiftUI/StickerPreview.swift +++ b/StickerSlack/SwiftUI/StickerPreview.swift @@ -19,7 +19,7 @@ struct StickerPreview: View { } else if type == Gif.self { return .giphyGifs } else { - fatalError() + fatalError("sticker type unrecognisedd") } } var body: some View { diff --git a/StickerSlack/SwiftUI/StickerRow.swift b/StickerSlack/SwiftUI/StickerRow.swift index 6c78651..8400af5 100644 --- a/StickerSlack/SwiftUI/StickerRow.swift +++ b/StickerSlack/SwiftUI/StickerRow.swift @@ -24,7 +24,7 @@ struct StickerRow: View { .transition(.scale) VStack(alignment: .leading, spacing: 5) { - Text(sticker.name) + Text(sticker.UIName) .font(.caption) .bold(isDownloaded) .foregroundColor(isDownloaded ? .green : .primary)