mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 12:44:51 +00:00
fix searching again
This commit is contained in:
3 files changed
+43
-22
No files matched your search
@@ -15,8 +15,8 @@ struct BrowseView: View {
|
||||
var body: some View {
|
||||
List {
|
||||
Picker("", selection: $browseWhat) {
|
||||
ForEach(StickerType.allCases, id: \.self) { type in
|
||||
Text(type.description)
|
||||
ForEach(StickerType.allCases) { type in
|
||||
Text(type.description).tag(type)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
|
||||
@@ -25,6 +25,18 @@ struct DownloadedView: View {
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
if emojiHoarder.downloadedStickers.isEmpty && gifHoarder.downloadedStickers.isEmpty {
|
||||
VStack(alignment: .center) {
|
||||
Image(systemName: "questionmark.app.dashed")
|
||||
.resizable().scaledToFit()
|
||||
.frame(width: 75, height: 75)
|
||||
Text("No Downloaded Stickers")
|
||||
.font(.title)
|
||||
.bold()
|
||||
Text("Download some Slack Emojis or GIFs to use in iMessage!")
|
||||
.foregroundStyle(.gray)
|
||||
}
|
||||
}
|
||||
GeometryReader { geo in
|
||||
ScrollView {
|
||||
let columns: Int = max(1, Int((geo.size.width - 2*spacing) / (minColWidth + spacing)))
|
||||
@@ -62,18 +74,6 @@ struct DownloadedView: View {
|
||||
.padding(.horizontal, spacing)
|
||||
}
|
||||
}
|
||||
if emojiHoarder.downloadedStickers.isEmpty && gifHoarder.downloadedStickers.isEmpty {
|
||||
VStack(alignment: .center) {
|
||||
Image(systemName: "questionmark.app.dashed")
|
||||
.resizable().scaledToFit()
|
||||
.frame(width: 75, height: 75)
|
||||
Text("No Downloaded Stickers")
|
||||
.font(.title)
|
||||
.bold()
|
||||
Text("Download some Slack Emojis or GIFs to use in iMessage!")
|
||||
.foregroundStyle(.gray)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,30 +15,51 @@ struct SearchView: View {
|
||||
@State var previousSearches: [String] = []
|
||||
@State var searchResult: [String] = []
|
||||
|
||||
@State var stickerType: StickerType = .slackEmoji
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
List {
|
||||
Text("\(searchResult.count) Result\(searchResult.count.plural)")
|
||||
.contentTransition(.numericText())
|
||||
ForEach(searchResult, id: \.self) { name in
|
||||
StickerRow(hoarder: hoarder, emoji: hoarder.trie.dict[name]!)
|
||||
Picker("", selection: $stickerType) {
|
||||
ForEach(StickerType.allCases) { type in
|
||||
Text(type.description).tag(type)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
switch stickerType {
|
||||
case .slackEmoji:
|
||||
List {
|
||||
Text("\(searchResult.count) Result\(searchResult.count.plural)")
|
||||
.contentTransition(.numericText())
|
||||
ForEach(searchResult, id: \.self) { name in
|
||||
StickerRow(hoarder: hoarder, emoji: hoarder.trie.dict[name]!)
|
||||
}
|
||||
}
|
||||
.fixedSize()
|
||||
EmojiCollectionView(hoarder: hoarder, items: searchResult)
|
||||
.id(searchResult)
|
||||
case .giphyGifs:
|
||||
Text("uhh")
|
||||
}
|
||||
}
|
||||
.searchable(text: $searchTerm)
|
||||
.onChange(of: searchTerm) { new in
|
||||
if currentSearch != nil { currentSearch?.cancel() }
|
||||
defer { previousSearches.append("") }
|
||||
guard !searchTerm.isEmpty else {
|
||||
currentSearch?.cancel()
|
||||
searchResult = []
|
||||
previousSearches.append(searchTerm)
|
||||
return
|
||||
}
|
||||
currentSearch = Task {
|
||||
let result = hoarder.trie.search(for: searchTerm, previousQuery: previousSearches.last, previousResult: Set(searchResult))
|
||||
currentSearch = Task.detached {
|
||||
let result = await hoarder.trie.search(
|
||||
for: searchTerm,
|
||||
previousQuery: previousSearches.last,
|
||||
previousResult: Set(searchResult)
|
||||
)
|
||||
await MainActor.run {
|
||||
withAnimation {
|
||||
searchResult = result
|
||||
previousSearches.append(searchTerm)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||