File tree Expand file tree Collapse file tree 4 files changed +20
-6
lines changed Expand file tree Collapse file tree 4 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ internal struct HomeView: View {
2121 Group {
2222 switch selectedMenu {
2323 case . models: ModelsView ( )
24+ case . completions: CompletionsView ( )
2425 case . chatCompletions: ChatCompletionsView ( )
2526 default : Feedback ( state: . construction)
2627 }
Original file line number Diff line number Diff line change @@ -28,11 +28,12 @@ struct CompletionsView: View {
2828 . opacity ( viewModel. isLoading ? 0.4 : 1 )
2929 ButtonContained (
3030 " Submit " ,
31- isEnabled: !viewModel. input. isEmpty
31+ isEnabled: !viewModel. input. isEmpty && !viewModel. isLoading,
32+ onAction: { viewModel. requestCompletions ( ) }
3233 )
3334 . padding ( . top, 16 )
3435 . padding ( . bottom, 24 )
35- OutputBox ( states: [ ] )
36+ OutputBox ( states: viewModel . outputBoxStates )
3637 }
3738 . padding ( 16 )
3839 . fullScreen ( )
Original file line number Diff line number Diff line change @@ -24,19 +24,30 @@ internal class CompletionsViewModel: ObservableObject {
2424 }
2525
2626 @MainActor
27- func fetchListModels ( ) {
27+ func requestCompletions ( ) {
2828 let completions = yChat. completion ( )
2929 . setInput ( input: input)
3030 outputBoxStates = [ ]
3131 outputBoxStates. append ( OutputState . text ( text: input) )
32+ setLoading ( isLoading: true )
3233 Task . init {
33-
3434 do {
3535 let result = try await completions. execute ( )
36-
36+ setLoading ( isLoading: false )
37+ outputBoxStates. append ( OutputState . text ( text: result, isMarked: true ) )
3738 } catch {
38-
39+ setLoading ( isLoading: false )
40+ outputBoxStates. append ( OutputState . error)
3941 }
4042 }
4143 }
44+
45+ private func setLoading( isLoading: Bool ) {
46+ self . isLoading = isLoading
47+ if isLoading {
48+ outputBoxStates. append ( OutputState . loading)
49+ } else {
50+ outputBoxStates. removeAll { $0 == . loading }
51+ }
52+ }
4253}
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ struct ButtonContained: View {
3939 }
4040 . background ( backgroundColor)
4141 . cornerRadius ( 8 )
42+ . disabled ( !isEnabled)
4243 }
4344}
4445
You can’t perform that action at this time.
0 commit comments