Init Chat Logical Flow

This commit is contained in:
砍砍
2024-12-06 17:50:51 +08:00
parent af3fa410a6
commit 2fee181633
2 changed files with 40 additions and 0 deletions

View File

@@ -21,6 +21,18 @@ extension InputEditView {
cancellables.forEach { $0.cancel() }
cancellables.removeAll()
}
func reset() {
text = ""
attachments = []
}
func duplicate() -> ViewModel {
let ans = ViewModel()
ans.text = text
ans.attachments = attachments
return ans
}
}
}

View File

@@ -119,5 +119,33 @@ public class IntelligentsChatController: UIViewController {
@objc func send() {
assert(Thread.isMainThread)
inputBox.isUserInteractionEnabled = false
progressView.startAnimating()
progressView.isHidden = false
progressView.alpha = 0
UIView.animate(withDuration: 0.3) {
self.inputBox.editor.alpha = 0
self.progressView.alpha = 1
} completion: { _ in
let viewModel = self.inputBox.editor.viewModel.duplicate()
self.inputBox.editor.viewModel.reset()
DispatchQueue.global().async {
self.sendSyncEx(viewModel: viewModel)
DispatchQueue.main.async {
UIView.animate(withDuration: 0.3) {
self.inputBox.editor.alpha = 1
self.progressView.alpha = 0
} completion: { _ in
self.inputBox.isUserInteractionEnabled = true
self.progressView.stopAnimating()
}
}
}
}
}
private func sendSyncEx(viewModel: InputEditView.ViewModel) {
let text = viewModel.text
let images = viewModel.attachments
}
}