mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 20:54:51 +00:00
Merge remote-tracking branch 'refs/remotes/origin/main'
This commit is contained in:
5 files changed
+54
-17
No files matched your search
@@ -15,8 +15,8 @@ struct BrowseView: View {
|
|||||||
var body: some View {
|
var body: some View {
|
||||||
List {
|
List {
|
||||||
Picker("", selection: $browseWhat) {
|
Picker("", selection: $browseWhat) {
|
||||||
ForEach(StickerType.allCases, id: \.self) { type in
|
ForEach(StickerType.allCases) { type in
|
||||||
Text(type.description)
|
Text(type.description).tag(type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.pickerStyle(.segmented)
|
.pickerStyle(.segmented)
|
||||||
|
|||||||
@@ -25,6 +25,18 @@ struct DownloadedView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var body: some 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
|
GeometryReader { geo in
|
||||||
ScrollView {
|
ScrollView {
|
||||||
let columns: Int = max(1, Int((geo.size.width - 2*spacing) / (minColWidth + spacing)))
|
let columns: Int = max(1, Int((geo.size.width - 2*spacing) / (minColWidth + spacing)))
|
||||||
|
|||||||
@@ -12,10 +12,21 @@ struct SearchView: View {
|
|||||||
|
|
||||||
@State private var currentSearch: Task<Void, Never>?
|
@State private var currentSearch: Task<Void, Never>?
|
||||||
@State var searchTerm: String = ""
|
@State var searchTerm: String = ""
|
||||||
|
@State var previousSearches: [String] = []
|
||||||
@State var searchResult: [String] = []
|
@State var searchResult: [String] = []
|
||||||
|
|
||||||
|
@State var stickerType: StickerType = .slackEmoji
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
|
Picker("", selection: $stickerType) {
|
||||||
|
ForEach(StickerType.allCases) { type in
|
||||||
|
Text(type.description).tag(type)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.pickerStyle(.segmented)
|
||||||
|
switch stickerType {
|
||||||
|
case .slackEmoji:
|
||||||
List {
|
List {
|
||||||
Text("\(searchResult.count) Result\(searchResult.count.plural)")
|
Text("\(searchResult.count) Result\(searchResult.count.plural)")
|
||||||
.contentTransition(.numericText())
|
.contentTransition(.numericText())
|
||||||
@@ -23,26 +34,35 @@ struct SearchView: View {
|
|||||||
StickerRow(hoarder: hoarder, emoji: hoarder.trie.dict[name]!)
|
StickerRow(hoarder: hoarder, emoji: hoarder.trie.dict[name]!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.fixedSize()
|
||||||
|
EmojiCollectionView(hoarder: hoarder, items: searchResult)
|
||||||
|
.id(searchResult)
|
||||||
|
case .giphyGifs:
|
||||||
|
Text("uhh")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.searchable(text: $searchTerm)
|
.searchable(text: $searchTerm)
|
||||||
.onChange(of: searchTerm) { _ in
|
.onChange(of: searchTerm) { new in
|
||||||
|
if currentSearch != nil { currentSearch?.cancel() }
|
||||||
guard !searchTerm.isEmpty else {
|
guard !searchTerm.isEmpty else {
|
||||||
currentSearch?.cancel()
|
currentSearch?.cancel()
|
||||||
withAnimation { searchResult = [] }
|
searchResult = []
|
||||||
|
previousSearches.append(searchTerm)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if currentSearch != nil {
|
currentSearch = Task.detached {
|
||||||
withAnimation { currentSearch?.cancel() }
|
let result = await hoarder.trie.search(
|
||||||
}
|
for: searchTerm,
|
||||||
// currentSearch = Task {
|
previousQuery: previousSearches.last,
|
||||||
let result = hoarder.trie.search(for: searchTerm)
|
previousResult: Set(searchResult)
|
||||||
guard !Task.isCancelled else { return }
|
)
|
||||||
// await MainActor.run {
|
await MainActor.run {
|
||||||
withAnimation(.snappy) {
|
withAnimation {
|
||||||
searchResult = result
|
searchResult = result
|
||||||
|
previousSearches.append(searchTerm)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,12 +42,17 @@ class Trie: ObservableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func search(for query: String) -> [String] {
|
func search(for query: String, previousQuery: String?, previousResult: Set<String>?) -> [String] {
|
||||||
var result: Set<String> = wordlist
|
var result: Set<String> = wordlist
|
||||||
|
if let previousQuery,
|
||||||
|
let previousResult,
|
||||||
|
query.hasPrefix(previousQuery) {
|
||||||
|
result = previousResult
|
||||||
|
}
|
||||||
for word in query.split(separator: " ") {
|
for word in query.split(separator: " ") {
|
||||||
result = result.filter { $0.localizedCaseInsensitiveContains(word) }
|
result = result.filter { $0.localizedCaseInsensitiveContains(word) }
|
||||||
}
|
}
|
||||||
return Array(result)
|
return Array(result).sorted()
|
||||||
}
|
}
|
||||||
|
|
||||||
func search(exactly query: String) -> Bool {
|
func search(exactly query: String) -> Bool {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ struct TrieTestingView: View {
|
|||||||
case .contains:
|
case .contains:
|
||||||
if searchTask != nil { searchTask?.cancel() }
|
if searchTask != nil { searchTask?.cancel() }
|
||||||
searchTask = Task.detached {
|
searchTask = Task.detached {
|
||||||
let result = await hoarder.trie.search(for: searchTerm)
|
let result = await hoarder.trie.search(for: searchTerm, previousQuery: nil, previousResult: nil)
|
||||||
await MainActor.run {
|
await MainActor.run {
|
||||||
withAnimation(.snappy) { searchResults = result }
|
withAnimation(.snappy) { searchResults = result }
|
||||||
print("testing: contains search complete")
|
print("testing: contains search complete")
|
||||||
|
|||||||