diff --git a/lib/dashbot/core/providers/dashbot_window_notifier.dart b/lib/dashbot/core/providers/dashbot_window_notifier.dart index d1c5baa1..628f8689 100644 --- a/lib/dashbot/core/providers/dashbot_window_notifier.dart +++ b/lib/dashbot/core/providers/dashbot_window_notifier.dart @@ -14,7 +14,7 @@ class DashbotWindowNotifier extends StateNotifier { void updateSize(double dx, double dy, Size screenSize) { final newWidth = - (state.width - dx).clamp(300, screenSize.width - state.right); + (state.width - dx).clamp(375, screenSize.width - state.right); final newHeight = (state.height - dy).clamp(460, screenSize.height - state.bottom); diff --git a/lib/dashbot/dashbot_dashboard.dart b/lib/dashbot/dashbot_dashboard.dart index dbaa1993..04dab940 100644 --- a/lib/dashbot/dashbot_dashboard.dart +++ b/lib/dashbot/dashbot_dashboard.dart @@ -1,4 +1,5 @@ import 'package:apidash/providers/providers.dart'; +import 'package:apidash/screens/common_widgets/ai/ai.dart'; import 'package:apidash_core/apidash_core.dart'; import 'package:apidash_design_system/apidash_design_system.dart'; import 'core/utils/dashbot_icons.dart'; @@ -14,16 +15,27 @@ class DashbotWindow extends ConsumerWidget { const DashbotWindow({super.key, required this.onClose}); + static final GlobalKey _dashbotNavigatorKey = + GlobalKey(); + @override Widget build(BuildContext context, WidgetRef ref) { final windowState = ref.watch(dashbotWindowNotifierProvider); final windowNotifier = ref.read(dashbotWindowNotifierProvider.notifier); - final defaultModelJson = ref.watch(settingsProvider).defaultAIModel; - final dashbotCtx = defaultModelJson == null - ? const AIRequestModel() - : AIRequestModel.fromJson(defaultModelJson); + final settings = ref.watch(settingsProvider); final currentRequest = ref.watch(selectedRequestModelProvider); + ref.listen( + selectedRequestModelProvider, + (current, next) { + if (next?.responseStatus != null) { + _dashbotNavigatorKey.currentState?.pushNamed( + DashbotRoutes.dashbotHome, + ); + } + }, + ); + return Stack( children: [ Positioned( @@ -71,9 +83,7 @@ class DashbotWindow extends ConsumerWidget { // TODO: remove the show active request name/model in prod kHSpacer12, Text( - dashbotCtx.modelApiProvider?.name == null - ? 'DashBot' - : 'DashBot ยท ${dashbotCtx.modelApiProvider?.name}', + 'DashBot', style: TextStyle( fontSize: 16, fontWeight: FontWeight.bold, @@ -81,6 +91,21 @@ class DashbotWindow extends ConsumerWidget { Theme.of(context).colorScheme.surface, ), ), + kHSpacer4, + AIModelSelectorButton( + aiRequestModel: AIRequestModel.fromJson( + settings.defaultAIModel ?? {}), + onModelUpdated: (d) { + ref + .read(settingsProvider.notifier) + .update( + defaultAIModel: d.copyWith( + modelConfigs: [], + stream: null, + systemPrompt: '', + userPrompt: '').toJson()); + }, + ), ], ), IconButton( @@ -97,6 +122,7 @@ class DashbotWindow extends ConsumerWidget { ), Expanded( child: Navigator( + key: _dashbotNavigatorKey, initialRoute: currentRequest?.responseStatus == null ? DashbotRoutes.dashbotDefault : DashbotRoutes.dashbotHome, 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 d09d385c..b3836f63 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/providers/collection_providers.dart'; + import '../../models/chat_models.dart'; import '../widgets/chat_bubble.dart'; import '../../viewmodel/chat_viewmodel.dart'; @@ -32,6 +34,14 @@ class _ChatScreenState extends ConsumerState { @override Widget build(BuildContext context) { + ref.listen( + selectedRequestModelProvider, + (current, next) { + if (current?.id != next?.id) { + Navigator.pop(context); + } + }, + ); return Scaffold( body: Column( children: [ @@ -77,10 +87,9 @@ class _ChatScreenState extends ConsumerState { child: TextField( controller: _textController, decoration: InputDecoration( - hintText: - ref.watch(chatViewmodelProvider).isGenerating - ? 'Generating...' - : 'Ask anything', + hintText: ref.watch(chatViewmodelProvider).isGenerating + ? 'Generating...' + : 'Ask anything', border: OutlineInputBorder( borderRadius: BorderRadius.circular(8), borderSide: BorderSide.none, @@ -105,18 +114,17 @@ class _ChatScreenState extends ConsumerState { const SizedBox(width: 8), IconButton( icon: const Icon(Icons.send_rounded), - onPressed: - ref.watch(chatViewmodelProvider).isGenerating - ? null - : () { - final vm = ref.read(chatViewmodelProvider.notifier); - final text = _textController.text; - _textController.clear(); - vm.sendMessage( - text: text, - type: ChatMessageType.general, - ); - }, + onPressed: ref.watch(chatViewmodelProvider).isGenerating + ? null + : () { + final vm = ref.read(chatViewmodelProvider.notifier); + final text = _textController.text; + _textController.clear(); + vm.sendMessage( + text: text, + type: ChatMessageType.general, + ); + }, tooltip: 'Send message', ), ], diff --git a/lib/dashbot/features/home/view/pages/home_page.dart b/lib/dashbot/features/home/view/pages/home_page.dart index 79def0fc..bdd5c9d8 100644 --- a/lib/dashbot/features/home/view/pages/home_page.dart +++ b/lib/dashbot/features/home/view/pages/home_page.dart @@ -22,14 +22,14 @@ class _DashbotHomePageState extends ConsumerState { Widget build(BuildContext context) { final currentRequest = ref.watch(selectedRequestModelProvider); - // ref.listen( - // selectedRequestModelProvider, - // (current, next) { - // if (current?.id != next?.id) { - // Navigator.pop(context); - // } - // }, - // ); + ref.listen( + selectedRequestModelProvider, + (current, next) { + if (current?.id != next?.id) { + Navigator.pop(context); + } + }, + ); return Container( padding: const EdgeInsets.all(16), child: Column(