mirror of
https://github.com/foss42/apidash.git
synced 2025-12-01 18:28:25 +08:00
feat: add clear chat functionality
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import 'package:apidash_design_system/apidash_design_system.dart';
|
||||||
|
|
||||||
import '../../models/chat_models.dart';
|
import '../../models/chat_models.dart';
|
||||||
import '../widgets/chat_bubble.dart';
|
import '../widgets/chat_bubble.dart';
|
||||||
import '../../viewmodel/chat_viewmodel.dart';
|
import '../../viewmodel/chat_viewmodel.dart';
|
||||||
@@ -82,6 +84,17 @@ class _ChatScreenState extends ConsumerState<ChatScreen> {
|
|||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
|
ADIconButton(
|
||||||
|
icon: Icons.clear_all_rounded,
|
||||||
|
tooltip: 'Clear chat',
|
||||||
|
onPressed: ref.watch(chatViewmodelProvider).isGenerating
|
||||||
|
? null
|
||||||
|
: () {
|
||||||
|
ref
|
||||||
|
.read(chatViewmodelProvider.notifier)
|
||||||
|
.clearCurrentChat();
|
||||||
|
},
|
||||||
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: TextField(
|
child: TextField(
|
||||||
controller: _textController,
|
controller: _textController,
|
||||||
|
|||||||
@@ -284,6 +284,18 @@ class ChatViewmodel extends StateNotifier<ChatState> {
|
|||||||
state = state.copyWith(isGenerating: false);
|
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<void> applyAutoFix(ChatAction action) async {
|
Future<void> applyAutoFix(ChatAction action) async {
|
||||||
final requestId = _currentRequest?.id;
|
final requestId = _currentRequest?.id;
|
||||||
if (requestId == null) return;
|
if (requestId == null) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user