From fc6abd044aa88a4724596e93dfbcacd7d80a5f06 Mon Sep 17 00:00:00 2001 From: Udhay-Adithya Date: Sun, 21 Sep 2025 01:08:02 +0530 Subject: [PATCH] feat: add clear chat functionality --- .../features/chat/view/pages/dashbot_chat_page.dart | 13 +++++++++++++ .../features/chat/viewmodel/chat_viewmodel.dart | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/dashbot/features/chat/view/pages/dashbot_chat_page.dart b/lib/dashbot/features/chat/view/pages/dashbot_chat_page.dart index dd7e38e8..c3fb9edc 100644 --- a/lib/dashbot/features/chat/view/pages/dashbot_chat_page.dart +++ b/lib/dashbot/features/chat/view/pages/dashbot_chat_page.dart @@ -1,3 +1,5 @@ +import 'package:apidash_design_system/apidash_design_system.dart'; + import '../../models/chat_models.dart'; import '../widgets/chat_bubble.dart'; import '../../viewmodel/chat_viewmodel.dart'; @@ -82,6 +84,17 @@ class _ChatScreenState extends ConsumerState { padding: const EdgeInsets.all(8.0), child: Row( children: [ + ADIconButton( + icon: Icons.clear_all_rounded, + tooltip: 'Clear chat', + onPressed: ref.watch(chatViewmodelProvider).isGenerating + ? null + : () { + ref + .read(chatViewmodelProvider.notifier) + .clearCurrentChat(); + }, + ), Expanded( child: TextField( controller: _textController, diff --git a/lib/dashbot/features/chat/viewmodel/chat_viewmodel.dart b/lib/dashbot/features/chat/viewmodel/chat_viewmodel.dart index 9f56ca92..37385acd 100644 --- a/lib/dashbot/features/chat/viewmodel/chat_viewmodel.dart +++ b/lib/dashbot/features/chat/viewmodel/chat_viewmodel.dart @@ -284,6 +284,18 @@ class ChatViewmodel extends StateNotifier { state = state.copyWith(isGenerating: false); } + void clearCurrentChat() { + final id = _currentRequest?.id ?? 'global'; + _sub?.cancel(); + final newSessions = {...state.chatSessions}; + newSessions[id] = []; + state = state.copyWith( + chatSessions: newSessions, + isGenerating: false, + currentStreamingResponse: '', + ); + } + Future applyAutoFix(ChatAction action) async { final requestId = _currentRequest?.id; if (requestId == null) return;