implement testdata!

got a list of emojis and urls
reanmed slackemojiresponse to emoji
This commit is contained in:
neon443 committed 2025-10-16 19:22:37 +01:00
1 parent 8e36082490
commit c5afd89222
3 files changed
+31 -4

No files matched your search

+3 -3
View File
@@ -11,14 +11,14 @@ struct SlackResponse: Codable {
var ok: Bool
var emoji: [String:String]
func toEmojiResponse() -> [SlackEmojiResponse] {
func toEmojis() -> [Emoji] {
return emoji.map {
SlackEmojiResponse(name: $0.key, url: $0.value)
Emoji(name: $0.key, url: $0.value)
}
}
}
struct SlackEmojiResponse: Codable {
struct Emoji: Codable, Hashable {
var name: String
var url: String
+18
View File
@@ -12,4 +12,22 @@ import Combine
class EmojiHoarder: ObservableObject {
private let endpoint: URL = URL(string: "https://slack.com/api/emoji.list")!
@Published var kys = ""
@Published var testBundle: SlackResponse
init() {
self.kys = ""
guard let testURL = Bundle.main.url(forResource: "testData", withExtension: "json") else {
fatalError("")
}
guard let data = try? Data(contentsOf: testURL) else {
self.testBundle = SlackResponse(ok: false, emoji: [:])
return
}
guard let decoded = try? JSONDecoder().decode(SlackResponse.self, from: data) else {
fatalError("couldnt decode :sob:")
}
self.testBundle = decoded
}
}
+10 -1
View File
@@ -8,14 +8,23 @@
import SwiftUI
struct ContentView: View {
@StateObject var hoarder: EmojiHoarder = EmojiHoarder()
var body: some View {
NavigationStack {
TabView {
Text("hi")
List {
ForEach(hoarder.testBundle.toEmojis(), id: \.self) { emoji in
Text(emoji.name)
Text(emoji.url)
}
}
.tabItem {
Label("home", systemImage: "house")
}
}
}
}
}
#Preview {
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.