mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 02:39:19 +08:00
refactor: update Dashbot window size constraints and enhance request navigation handling
This commit is contained in:
@@ -14,7 +14,7 @@ class DashbotWindowNotifier extends StateNotifier<DashbotWindowModel> {
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -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<NavigatorState> _dashbotNavigatorKey =
|
||||
GlobalKey<NavigatorState>();
|
||||
|
||||
@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,
|
||||
|
||||
@@ -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<ChatScreen> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
ref.listen(
|
||||
selectedRequestModelProvider,
|
||||
(current, next) {
|
||||
if (current?.id != next?.id) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
);
|
||||
return Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
@@ -77,8 +87,7 @@ class _ChatScreenState extends ConsumerState<ChatScreen> {
|
||||
child: TextField(
|
||||
controller: _textController,
|
||||
decoration: InputDecoration(
|
||||
hintText:
|
||||
ref.watch(chatViewmodelProvider).isGenerating
|
||||
hintText: ref.watch(chatViewmodelProvider).isGenerating
|
||||
? 'Generating...'
|
||||
: 'Ask anything',
|
||||
border: OutlineInputBorder(
|
||||
@@ -105,8 +114,7 @@ class _ChatScreenState extends ConsumerState<ChatScreen> {
|
||||
const SizedBox(width: 8),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.send_rounded),
|
||||
onPressed:
|
||||
ref.watch(chatViewmodelProvider).isGenerating
|
||||
onPressed: ref.watch(chatViewmodelProvider).isGenerating
|
||||
? null
|
||||
: () {
|
||||
final vm = ref.read(chatViewmodelProvider.notifier);
|
||||
|
||||
@@ -22,14 +22,14 @@ class _DashbotHomePageState extends ConsumerState<DashbotHomePage> {
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user