mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 20:54:51 +00:00
new contains searching algo
also fix animations on list
This commit is contained in:
1 file changed
+16
-5
@@ -35,10 +35,22 @@ struct TrieTestingView: View {
|
|||||||
}
|
}
|
||||||
print("testing: trie search")
|
print("testing: trie search")
|
||||||
case .contains:
|
case .contains:
|
||||||
|
Task.detached {
|
||||||
|
var results: [[Emoji]] = []
|
||||||
|
var result: [Emoji] = []
|
||||||
|
for word in filterTerm.split(separator: " ") {
|
||||||
|
results.append(hoarder.emojis.filter({ $0.name.localizedCaseInsensitiveContains(word) }))
|
||||||
|
}
|
||||||
|
result = results.reduce(results[0]) { partialResult, array in
|
||||||
|
partialResult.filter { array.contains($0) }
|
||||||
|
}
|
||||||
|
await MainActor.run {
|
||||||
withAnimation(.snappy) {
|
withAnimation(.snappy) {
|
||||||
filterResult = hoarder.emojis.filter({ $0.name.localizedCaseInsensitiveContains(filterTerm) }).map({ $0.name })
|
filterResult = result.map { $0.name }
|
||||||
}
|
}
|
||||||
print("testing: contains search")
|
print("testing: contains search")
|
||||||
|
}
|
||||||
|
}
|
||||||
case .exact:
|
case .exact:
|
||||||
withAnimation(.snappy) {
|
withAnimation(.snappy) {
|
||||||
searchStatus = hoarder.trie.search(for: filterTerm)
|
searchStatus = hoarder.trie.search(for: filterTerm)
|
||||||
@@ -69,10 +81,7 @@ struct TrieTestingView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.pickerStyle(.segmented)
|
.pickerStyle(.segmented)
|
||||||
.onChange(of: searchType) { _ in
|
.onChange(of: searchType.rawValue+filterTerm) { _ in
|
||||||
runSearch()
|
|
||||||
}
|
|
||||||
.onChange(of: filterTerm) { _ in
|
|
||||||
runSearch()
|
runSearch()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,10 +123,12 @@ struct TrieTestingView: View {
|
|||||||
|
|
||||||
if uikit {
|
if uikit {
|
||||||
EmojiCollectionView(hoarder: hoarder, items: filterResult)
|
EmojiCollectionView(hoarder: hoarder, items: filterResult)
|
||||||
|
.animation(.snappy, value: filterResult)
|
||||||
} else {
|
} else {
|
||||||
List(filterResult, id: \.self) { item in
|
List(filterResult, id: \.self) { item in
|
||||||
EmojiRow(hoarder: hoarder, emoji: hoarder.trie.dict[item]!)
|
EmojiRow(hoarder: hoarder, emoji: hoarder.trie.dict[item]!)
|
||||||
}
|
}
|
||||||
|
.animation(.snappy, value: filterResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
Text("\(hoarder.trie.root.children.count)")
|
Text("\(hoarder.trie.root.children.count)")
|
||||||
|
|||||||