mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 12:44:51 +00:00
new seach algorithm in search, might remove trie :br:
remove searcterm from hoarder move emojipackmanager
This commit is contained in:
8 files changed
+52
-41
No files matched your search
@@ -251,6 +251,7 @@
|
|||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
A9D15B892EB1142C00404792 /* EmojiPack.swift */,
|
A9D15B892EB1142C00404792 /* EmojiPack.swift */,
|
||||||
|
A9CD6C372EDDE37500B7F421 /* EmojiPackManager.swift */,
|
||||||
A935437A2EB2A3C800BB80A4 /* FilterCategory.swift */,
|
A935437A2EB2A3C800BB80A4 /* FilterCategory.swift */,
|
||||||
);
|
);
|
||||||
path = Categorisation;
|
path = Categorisation;
|
||||||
@@ -293,7 +294,6 @@
|
|||||||
A949B1D62EA04C0B00215164 = {
|
A949B1D62EA04C0B00215164 = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
A9CD6C372EDDE37500B7F421 /* EmojiPackManager.swift */,
|
|
||||||
A9E2ECD72EB74CE00038B2D6 /* Config.xcconfig */,
|
A9E2ECD72EB74CE00038B2D6 /* Config.xcconfig */,
|
||||||
A949B1F22EA04E8200215164 /* StickerSlack */,
|
A949B1F22EA04E8200215164 /* StickerSlack */,
|
||||||
A9104C742EB3AE4700D160EA /* Resources */,
|
A9104C742EB3AE4700D160EA /* Resources */,
|
||||||
|
|||||||
File renamed without changes.
@@ -24,7 +24,6 @@ class EmojiHoarder: Hoarder, ObservableObject {
|
|||||||
@Published var trie: Trie = Trie()
|
@Published var trie: Trie = Trie()
|
||||||
@Published var downloadedEmojis: Set<String> = []
|
@Published var downloadedEmojis: Set<String> = []
|
||||||
@Published var downloadedEmojisArr: [String] = []
|
@Published var downloadedEmojisArr: [String] = []
|
||||||
@Published var searchTerm: String = ""
|
|
||||||
|
|
||||||
@Published var letterStats: [EmojiHoarder.LetterStat] = []
|
@Published var letterStats: [EmojiHoarder.LetterStat] = []
|
||||||
@Published var letterStatsSorting: EmojiHoarder.LetterStatSorting = .init(by: .letter, ascending: true)
|
@Published var letterStatsSorting: EmojiHoarder.LetterStatSorting = .init(by: .letter, ascending: true)
|
||||||
@@ -117,7 +116,6 @@ class EmojiHoarder: Hoarder, ObservableObject {
|
|||||||
downloadedEmojisArr = []
|
downloadedEmojisArr = []
|
||||||
UserDefaults.standard.removeObject(forKey: "downloadedEmojis")
|
UserDefaults.standard.removeObject(forKey: "downloadedEmojis")
|
||||||
UserDefaults.standard.removeObject(forKey: "downloadedEmojisArr")
|
UserDefaults.standard.removeObject(forKey: "downloadedEmojisArr")
|
||||||
searchTerm = ""
|
|
||||||
letterStats = []
|
letterStats = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ protocol Hoarder {
|
|||||||
var endpoint: URL { get }
|
var endpoint: URL { get }
|
||||||
var encoder: JSONEncoder { get }
|
var encoder: JSONEncoder { get }
|
||||||
var decoder: JSONDecoder { get }
|
var decoder: JSONDecoder { get }
|
||||||
var searchTerm: String { get set }
|
|
||||||
|
|
||||||
func download(emoji: Emoji, skipStoreIndex: Bool) async
|
func download(emoji: Emoji, skipStoreIndex: Bool) async
|
||||||
func delete(emoji: Emoji, skipStoreIndex: Bool)
|
func delete(emoji: Emoji, skipStoreIndex: Bool)
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ import Haptics
|
|||||||
struct EmojiRow: View {
|
struct EmojiRow: View {
|
||||||
@ObservedObject var hoarder: EmojiHoarder
|
@ObservedObject var hoarder: EmojiHoarder
|
||||||
@State var emoji: Emoji
|
@State var emoji: Emoji
|
||||||
|
|
||||||
|
var isLocal: Bool {
|
||||||
|
return hoarder.downloadedEmojis.contains(emoji.name)
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
HStack {
|
HStack {
|
||||||
@@ -24,12 +28,12 @@ struct EmojiRow: View {
|
|||||||
.foregroundStyle(.gray.opacity(0.1))
|
.foregroundStyle(.gray.opacity(0.1))
|
||||||
Text(emoji.name)
|
Text(emoji.name)
|
||||||
.font(.caption)
|
.font(.caption)
|
||||||
.bold(hoarder.downloadedEmojis.contains(emoji.name))
|
.bold(isLocal)
|
||||||
.foregroundColor(hoarder.downloadedEmojis.contains(emoji.name) ? .green : .primary)
|
.foregroundColor(isLocal ? .green : .primary)
|
||||||
.padding(3)
|
.padding(3)
|
||||||
}
|
}
|
||||||
.fixedSize()
|
.fixedSize()
|
||||||
if hoarder.downloadedEmojis.contains(emoji.name) {
|
if isLocal {
|
||||||
Image(systemName: "arrow.down.circle.fill")
|
Image(systemName: "arrow.down.circle.fill")
|
||||||
.resizable().scaledToFit()
|
.resizable().scaledToFit()
|
||||||
.frame(width: 20, height: 20)
|
.frame(width: 20, height: 20)
|
||||||
@@ -41,7 +45,7 @@ struct EmojiRow: View {
|
|||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
if hoarder.downloadedEmojis.contains(emoji.name) {
|
if isLocal {
|
||||||
Button("", systemImage: "trash") {
|
Button("", systemImage: "trash") {
|
||||||
hoarder.delete(emoji: emoji)
|
hoarder.delete(emoji: emoji)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,18 +10,26 @@ import SwiftUI
|
|||||||
struct SearchView: View {
|
struct SearchView: View {
|
||||||
@ObservedObject var hoarder: EmojiHoarder
|
@ObservedObject var hoarder: EmojiHoarder
|
||||||
|
|
||||||
@State var filterResult: [String] = []
|
@State var searchTerm: String = ""
|
||||||
|
@State var searchResult: [String] = []
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
List(filterResult, id: \.self) { name in
|
List(searchResult, id: \.self) { name in
|
||||||
EmojiRow(hoarder: hoarder, emoji: hoarder.trie.dict[name]!)
|
EmojiRow(hoarder: hoarder, emoji: hoarder.trie.dict[name]!)
|
||||||
}
|
}
|
||||||
.onChange(of: hoarder.searchTerm) { _ in
|
.onChange(of: searchTerm) { _ in
|
||||||
withAnimation(.snappy) { filterResult = hoarder.trie.search(prefix: hoarder.searchTerm) }
|
Task.detached(name: "emojiSearch", priority: .userInitiated) {
|
||||||
|
let result = await hoarder.trie.search(for: searchTerm)
|
||||||
|
await MainActor.run {
|
||||||
|
withAnimation(.snappy) {
|
||||||
|
searchResult = result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.searchable(text: $hoarder.searchTerm)
|
.searchable(text: $searchTerm)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,14 @@ class Trie: ObservableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func search(for query: String) -> [String] {
|
||||||
|
var result: [String] = wordlist
|
||||||
|
for word in query.split(separator: " ") {
|
||||||
|
result = result.filter { $0.localizedCaseInsensitiveContains(word) }
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
func search(exactly query: String) -> Bool {
|
func search(exactly query: String) -> Bool {
|
||||||
var currentNode = root
|
var currentNode = root
|
||||||
|
|
||||||
|
|||||||
@@ -10,10 +10,9 @@ import SwiftUI
|
|||||||
struct TrieTestingView: View {
|
struct TrieTestingView: View {
|
||||||
@ObservedObject var hoarder: EmojiHoarder
|
@ObservedObject var hoarder: EmojiHoarder
|
||||||
|
|
||||||
@State var searchStatus: Bool? = nil
|
@State var searchTerm: String = ""
|
||||||
|
@State var searchResults: [String] = []
|
||||||
@State var filterTerm: String = ""
|
@State var exactSearchResult: Bool? = nil
|
||||||
@State var filterResult: [String] = []
|
|
||||||
|
|
||||||
@State var uikit: Bool = false
|
@State var uikit: Bool = false
|
||||||
|
|
||||||
@@ -25,31 +24,26 @@ struct TrieTestingView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func runSearch() {
|
private func runSearch() {
|
||||||
filterResult = []
|
searchResults = []
|
||||||
searchStatus = nil
|
exactSearchResult = nil
|
||||||
guard !filterTerm.isEmpty else { return }
|
guard !searchTerm.isEmpty else { return }
|
||||||
switch searchType {
|
switch searchType {
|
||||||
case .trie:
|
case .trie:
|
||||||
withAnimation(.snappy) {
|
withAnimation(.snappy) {
|
||||||
filterResult = hoarder.trie.search(prefix: filterTerm)
|
searchResults = hoarder.trie.search(prefix: searchTerm)
|
||||||
}
|
}
|
||||||
print("testing: trie search complete")
|
print("testing: trie search complete")
|
||||||
case .contains:
|
case .contains:
|
||||||
Task.detached {
|
Task.detached {
|
||||||
var result: [String] = await hoarder.trie.wordlist
|
let result = await hoarder.trie.search(for: searchTerm)
|
||||||
for word in await filterTerm.split(separator: " ") {
|
|
||||||
result = result.filter { $0.localizedCaseInsensitiveContains(word) }
|
|
||||||
}
|
|
||||||
await MainActor.run {
|
await MainActor.run {
|
||||||
withAnimation(.snappy) {
|
withAnimation(.snappy) { searchResults = result }
|
||||||
filterResult = result
|
|
||||||
}
|
|
||||||
print("testing: contains search complete")
|
print("testing: contains search complete")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case .exact:
|
case .exact:
|
||||||
withAnimation(.snappy) {
|
withAnimation(.snappy) {
|
||||||
searchStatus = hoarder.trie.search(exactly: filterTerm)
|
exactSearchResult = hoarder.trie.search(exactly: searchTerm)
|
||||||
}
|
}
|
||||||
print("testing: exact search complete")
|
print("testing: exact search complete")
|
||||||
}
|
}
|
||||||
@@ -77,19 +71,19 @@ struct TrieTestingView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.pickerStyle(.segmented)
|
.pickerStyle(.segmented)
|
||||||
.onChange(of: searchType.rawValue+filterTerm) { _ in
|
.onChange(of: searchType.rawValue+searchTerm) { _ in
|
||||||
runSearch()
|
runSearch()
|
||||||
}
|
}
|
||||||
|
|
||||||
if searchType == .exact {
|
if searchType == .exact {
|
||||||
HStack {
|
HStack {
|
||||||
TextField("", text: $filterTerm)
|
TextField("", text: $searchTerm)
|
||||||
.textFieldStyle(.roundedBorder)
|
.textFieldStyle(.roundedBorder)
|
||||||
.border(.orange)
|
.border(.orange)
|
||||||
if let searchStatus {
|
if let exactSearchResult {
|
||||||
Circle()
|
Circle()
|
||||||
.frame(width: 20, height: 20)
|
.frame(width: 20, height: 20)
|
||||||
.foregroundStyle(searchStatus ? .green : .red)
|
.foregroundStyle(exactSearchResult ? .green : .red)
|
||||||
} else {
|
} else {
|
||||||
Text("?")
|
Text("?")
|
||||||
.frame(width: 20, height: 20)
|
.frame(width: 20, height: 20)
|
||||||
@@ -99,32 +93,32 @@ struct TrieTestingView: View {
|
|||||||
|
|
||||||
if searchType == .trie {
|
if searchType == .trie {
|
||||||
HStack {
|
HStack {
|
||||||
TextField("", text: $filterTerm)
|
TextField("", text: $searchTerm)
|
||||||
.textFieldStyle(.roundedBorder)
|
.textFieldStyle(.roundedBorder)
|
||||||
.border(.orange)
|
.border(.orange)
|
||||||
Text("\(filterResult.count)")
|
Text("\(searchResults.count)")
|
||||||
.modifier(numericTextCompat())
|
.modifier(numericTextCompat())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if searchType == .contains {
|
if searchType == .contains {
|
||||||
HStack {
|
HStack {
|
||||||
TextField("", text: $filterTerm)
|
TextField("", text: $searchTerm)
|
||||||
.textFieldStyle(.roundedBorder)
|
.textFieldStyle(.roundedBorder)
|
||||||
.border(.orange)
|
.border(.orange)
|
||||||
Text("\(filterResult.count)")
|
Text("\(searchResults.count)")
|
||||||
.modifier(numericTextCompat())
|
.modifier(numericTextCompat())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if uikit {
|
if uikit {
|
||||||
EmojiCollectionView(hoarder: hoarder, items: filterResult)
|
EmojiCollectionView(hoarder: hoarder, items: searchResults)
|
||||||
.animation(.snappy, value: filterResult)
|
.animation(.snappy, value: searchResults)
|
||||||
} else {
|
} else {
|
||||||
List(filterResult, id: \.self) { item in
|
List(searchResults, id: \.self) { item in
|
||||||
EmojiRow(hoarder: hoarder, emoji: hoarder.trie.dict[item]!)
|
EmojiRow(hoarder: hoarder, emoji: hoarder.trie.dict[item]!)
|
||||||
}
|
}
|
||||||
.animation(.snappy, value: filterResult)
|
.animation(.snappy, value: searchResults)
|
||||||
}
|
}
|
||||||
|
|
||||||
Text("\(hoarder.trie.root.children.count)")
|
Text("\(hoarder.trie.root.children.count)")
|
||||||
|
|||||||