mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-12-24 16:10:38 +00:00
Suggestion: cancel previous task
This commit is contained in:
parent
761c8ed3be
commit
1466d9690a
1 changed files with 10 additions and 1 deletions
|
@ -126,7 +126,9 @@ public class StatusEditorViewModel: NSObject, ObservableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
private var mentionString: String?
|
private var mentionString: String?
|
||||||
|
|
||||||
private var uploadTask: Task<Void, Never>?
|
private var uploadTask: Task<Void, Never>?
|
||||||
|
private var suggestedTask: Task<Void, Never>?
|
||||||
|
|
||||||
init(mode: Mode) {
|
init(mode: Mode) {
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
|
@ -433,7 +435,8 @@ public class StatusEditorViewModel: NSObject, ObservableObject {
|
||||||
private func loadAutoCompleteResults(query: String) {
|
private func loadAutoCompleteResults(query: String) {
|
||||||
guard let client, query.utf8.count > 1 else { return }
|
guard let client, query.utf8.count > 1 else { return }
|
||||||
var query = query
|
var query = query
|
||||||
Task {
|
suggestedTask?.cancel()
|
||||||
|
suggestedTask = Task {
|
||||||
do {
|
do {
|
||||||
var results: SearchResults?
|
var results: SearchResults?
|
||||||
switch query.first {
|
switch query.first {
|
||||||
|
@ -444,6 +447,9 @@ public class StatusEditorViewModel: NSObject, ObservableObject {
|
||||||
offset: 0,
|
offset: 0,
|
||||||
following: nil),
|
following: nil),
|
||||||
forceVersion: .v2)
|
forceVersion: .v2)
|
||||||
|
guard !Task.isCancelled else {
|
||||||
|
return
|
||||||
|
}
|
||||||
withAnimation {
|
withAnimation {
|
||||||
tagsSuggestions = results?.hashtags.sorted(by: { $0.totalUses > $1.totalUses }) ?? []
|
tagsSuggestions = results?.hashtags.sorted(by: { $0.totalUses > $1.totalUses }) ?? []
|
||||||
}
|
}
|
||||||
|
@ -454,6 +460,9 @@ public class StatusEditorViewModel: NSObject, ObservableObject {
|
||||||
offset: 0,
|
offset: 0,
|
||||||
following: true),
|
following: true),
|
||||||
forceVersion: .v2)
|
forceVersion: .v2)
|
||||||
|
guard !Task.isCancelled else {
|
||||||
|
return
|
||||||
|
}
|
||||||
withAnimation {
|
withAnimation {
|
||||||
mentionsSuggestions = results?.accounts ?? []
|
mentionsSuggestions = results?.accounts ?? []
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue