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 uploadTask: Task<Void, Never>?
|
||||
private var suggestedTask: Task<Void, Never>?
|
||||
|
||||
init(mode: Mode) {
|
||||
self.mode = mode
|
||||
|
@ -433,7 +435,8 @@ public class StatusEditorViewModel: NSObject, ObservableObject {
|
|||
private func loadAutoCompleteResults(query: String) {
|
||||
guard let client, query.utf8.count > 1 else { return }
|
||||
var query = query
|
||||
Task {
|
||||
suggestedTask?.cancel()
|
||||
suggestedTask = Task {
|
||||
do {
|
||||
var results: SearchResults?
|
||||
switch query.first {
|
||||
|
@ -444,6 +447,9 @@ public class StatusEditorViewModel: NSObject, ObservableObject {
|
|||
offset: 0,
|
||||
following: nil),
|
||||
forceVersion: .v2)
|
||||
guard !Task.isCancelled else {
|
||||
return
|
||||
}
|
||||
withAnimation {
|
||||
tagsSuggestions = results?.hashtags.sorted(by: { $0.totalUses > $1.totalUses }) ?? []
|
||||
}
|
||||
|
@ -454,6 +460,9 @@ public class StatusEditorViewModel: NSObject, ObservableObject {
|
|||
offset: 0,
|
||||
following: true),
|
||||
forceVersion: .v2)
|
||||
guard !Task.isCancelled else {
|
||||
return
|
||||
}
|
||||
withAnimation {
|
||||
mentionsSuggestions = results?.accounts ?? []
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue