mirror of
https://github.com/foss42/apidash.git
synced 2025-12-01 18:28:25 +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) {
|
void updateSize(double dx, double dy, Size screenSize) {
|
||||||
final newWidth =
|
final newWidth =
|
||||||
(state.width - dx).clamp(300, screenSize.width - state.right);
|
(state.width - dx).clamp(375, screenSize.width - state.right);
|
||||||
final newHeight =
|
final newHeight =
|
||||||
(state.height - dy).clamp(460, screenSize.height - state.bottom);
|
(state.height - dy).clamp(460, screenSize.height - state.bottom);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'package:apidash/providers/providers.dart';
|
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_core/apidash_core.dart';
|
||||||
import 'package:apidash_design_system/apidash_design_system.dart';
|
import 'package:apidash_design_system/apidash_design_system.dart';
|
||||||
import 'core/utils/dashbot_icons.dart';
|
import 'core/utils/dashbot_icons.dart';
|
||||||
@@ -14,16 +15,27 @@ class DashbotWindow extends ConsumerWidget {
|
|||||||
|
|
||||||
const DashbotWindow({super.key, required this.onClose});
|
const DashbotWindow({super.key, required this.onClose});
|
||||||
|
|
||||||
|
static final GlobalKey<NavigatorState> _dashbotNavigatorKey =
|
||||||
|
GlobalKey<NavigatorState>();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final windowState = ref.watch(dashbotWindowNotifierProvider);
|
final windowState = ref.watch(dashbotWindowNotifierProvider);
|
||||||
final windowNotifier = ref.read(dashbotWindowNotifierProvider.notifier);
|
final windowNotifier = ref.read(dashbotWindowNotifierProvider.notifier);
|
||||||
final defaultModelJson = ref.watch(settingsProvider).defaultAIModel;
|
final settings = ref.watch(settingsProvider);
|
||||||
final dashbotCtx = defaultModelJson == null
|
|
||||||
? const AIRequestModel()
|
|
||||||
: AIRequestModel.fromJson(defaultModelJson);
|
|
||||||
final currentRequest = ref.watch(selectedRequestModelProvider);
|
final currentRequest = ref.watch(selectedRequestModelProvider);
|
||||||
|
|
||||||
|
ref.listen(
|
||||||
|
selectedRequestModelProvider,
|
||||||
|
(current, next) {
|
||||||
|
if (next?.responseStatus != null) {
|
||||||
|
_dashbotNavigatorKey.currentState?.pushNamed(
|
||||||
|
DashbotRoutes.dashbotHome,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
return Stack(
|
return Stack(
|
||||||
children: [
|
children: [
|
||||||
Positioned(
|
Positioned(
|
||||||
@@ -71,9 +83,7 @@ class DashbotWindow extends ConsumerWidget {
|
|||||||
// TODO: remove the show active request name/model in prod
|
// TODO: remove the show active request name/model in prod
|
||||||
kHSpacer12,
|
kHSpacer12,
|
||||||
Text(
|
Text(
|
||||||
dashbotCtx.modelApiProvider?.name == null
|
'DashBot',
|
||||||
? 'DashBot'
|
|
||||||
: 'DashBot · ${dashbotCtx.modelApiProvider?.name}',
|
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
@@ -81,6 +91,21 @@ class DashbotWindow extends ConsumerWidget {
|
|||||||
Theme.of(context).colorScheme.surface,
|
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(
|
IconButton(
|
||||||
@@ -97,6 +122,7 @@ class DashbotWindow extends ConsumerWidget {
|
|||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Navigator(
|
child: Navigator(
|
||||||
|
key: _dashbotNavigatorKey,
|
||||||
initialRoute: currentRequest?.responseStatus == null
|
initialRoute: currentRequest?.responseStatus == null
|
||||||
? DashbotRoutes.dashbotDefault
|
? DashbotRoutes.dashbotDefault
|
||||||
: DashbotRoutes.dashbotHome,
|
: DashbotRoutes.dashbotHome,
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import 'package:apidash/providers/collection_providers.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';
|
||||||
@@ -32,6 +34,14 @@ class _ChatScreenState extends ConsumerState<ChatScreen> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
ref.listen(
|
||||||
|
selectedRequestModelProvider,
|
||||||
|
(current, next) {
|
||||||
|
if (current?.id != next?.id) {
|
||||||
|
Navigator.pop(context);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: Column(
|
body: Column(
|
||||||
children: [
|
children: [
|
||||||
@@ -77,10 +87,9 @@ class _ChatScreenState extends ConsumerState<ChatScreen> {
|
|||||||
child: TextField(
|
child: TextField(
|
||||||
controller: _textController,
|
controller: _textController,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText:
|
hintText: ref.watch(chatViewmodelProvider).isGenerating
|
||||||
ref.watch(chatViewmodelProvider).isGenerating
|
? 'Generating...'
|
||||||
? 'Generating...'
|
: 'Ask anything',
|
||||||
: 'Ask anything',
|
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
borderSide: BorderSide.none,
|
borderSide: BorderSide.none,
|
||||||
@@ -105,18 +114,17 @@ class _ChatScreenState extends ConsumerState<ChatScreen> {
|
|||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.send_rounded),
|
icon: const Icon(Icons.send_rounded),
|
||||||
onPressed:
|
onPressed: ref.watch(chatViewmodelProvider).isGenerating
|
||||||
ref.watch(chatViewmodelProvider).isGenerating
|
? null
|
||||||
? null
|
: () {
|
||||||
: () {
|
final vm = ref.read(chatViewmodelProvider.notifier);
|
||||||
final vm = ref.read(chatViewmodelProvider.notifier);
|
final text = _textController.text;
|
||||||
final text = _textController.text;
|
_textController.clear();
|
||||||
_textController.clear();
|
vm.sendMessage(
|
||||||
vm.sendMessage(
|
text: text,
|
||||||
text: text,
|
type: ChatMessageType.general,
|
||||||
type: ChatMessageType.general,
|
);
|
||||||
);
|
},
|
||||||
},
|
|
||||||
tooltip: 'Send message',
|
tooltip: 'Send message',
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -22,14 +22,14 @@ class _DashbotHomePageState extends ConsumerState<DashbotHomePage> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final currentRequest = ref.watch(selectedRequestModelProvider);
|
final currentRequest = ref.watch(selectedRequestModelProvider);
|
||||||
|
|
||||||
// ref.listen(
|
ref.listen(
|
||||||
// selectedRequestModelProvider,
|
selectedRequestModelProvider,
|
||||||
// (current, next) {
|
(current, next) {
|
||||||
// if (current?.id != next?.id) {
|
if (current?.id != next?.id) {
|
||||||
// Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
// }
|
}
|
||||||
// },
|
},
|
||||||
// );
|
);
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
child: Column(
|
child: Column(
|
||||||
|
|||||||
Reference in New Issue
Block a user