diff options
author | hunteraraujo <hunter_araujo@msn.com> | 2023-10-31 16:59:36 -0700 |
---|---|---|
committer | hunteraraujo <hunter_araujo@msn.com> | 2023-10-31 16:59:36 -0700 |
commit | 688ba62db73fe227b448b3a116f875bc7b805e51 (patch) | |
tree | ef5ae76b837aaa69c1dc620dec855821ff8cb6f6 /frontend | |
parent | refactor: Refactor agent message tile rendering logic (diff) | |
download | Auto-GPT-688ba62db73fe227b448b3a116f875bc7b805e51.tar.gz Auto-GPT-688ba62db73fe227b448b3a116f875bc7b805e51.tar.bz2 Auto-GPT-688ba62db73fe227b448b3a116f875bc7b805e51.zip |
feat: Add isWaitingForAgentResponse property to TaskViewModel
- Added a boolean property `isWaitingForAgentResponse` to the `TaskViewModel` class to track whether a task is being created and waiting for a response from the agent.
- When a task is being created, we set `isWaitingForAgentResponse` to `true` and notify the listeners.
- When the task creation process is completed (successfully or not), `isWaitingForAgentResponse` is set to `false` and listeners are notified.
- Updated the `ChatView` class to listen to changes in `TaskViewModel.isWaitingForAgentResponse` to show the loading indicator conditionally.
Diffstat (limited to 'frontend')
-rw-r--r-- | frontend/lib/viewmodels/task_viewmodel.dart | 9 | ||||
-rw-r--r-- | frontend/lib/views/chat/chat_view.dart | 5 |
2 files changed, 12 insertions, 2 deletions
diff --git a/frontend/lib/viewmodels/task_viewmodel.dart b/frontend/lib/viewmodels/task_viewmodel.dart index eca6554e7..61187a760 100644 --- a/frontend/lib/viewmodels/task_viewmodel.dart +++ b/frontend/lib/viewmodels/task_viewmodel.dart @@ -20,6 +20,10 @@ class TaskViewModel with ChangeNotifier { Task? _selectedTask; TestSuite? _selectedTestSuite; + bool _isWaitingForAgentResponse = false; + + bool get isWaitingForAgentResponse => _isWaitingForAgentResponse; + TaskViewModel(this._taskService, this._prefsService); /// Returns the currently selected task. @@ -28,6 +32,8 @@ class TaskViewModel with ChangeNotifier { /// Adds a task and returns its ID. Future<String> createTask(String title) async { + _isWaitingForAgentResponse = true; + notifyListeners(); try { final newTask = TaskRequestBody(input: title); // Add to data source @@ -45,6 +51,9 @@ class TaskViewModel with ChangeNotifier { } catch (e) { // TODO: We are bubbling up the full response. Revisit this. rethrow; + } finally { + _isWaitingForAgentResponse = false; + notifyListeners(); } } diff --git a/frontend/lib/views/chat/chat_view.dart b/frontend/lib/views/chat/chat_view.dart index 5d34bf52d..9e28f6843 100644 --- a/frontend/lib/views/chat/chat_view.dart +++ b/frontend/lib/views/chat/chat_view.dart @@ -64,7 +64,7 @@ class _ChatViewState extends State<ChatView> { @override Widget build(BuildContext context) { // TODO: Do we want to have a reference to task view model in this class? - final taskViewModel = Provider.of<TaskViewModel>(context, listen: false); + final taskViewModel = Provider.of<TaskViewModel>(context, listen: true); return Scaffold( body: Column( children: [ @@ -105,7 +105,8 @@ class _ChatViewState extends State<ChatView> { LoadingIndicator( isLoading: Provider.of<TaskQueueViewModel>(context, listen: true) .isBenchmarkRunning || - widget.viewModel.isWaitingForAgentResponse), + widget.viewModel.isWaitingForAgentResponse || + taskViewModel.isWaitingForAgentResponse), const SizedBox(height: 10), // Input area Padding( |