Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyboard shortcut for "new session" #41

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions app/lib/pages/chat.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:open_local_ui/layout/page_base.dart';
import 'package:open_local_ui/providers/chat.dart';
import 'package:open_local_ui/widgets/chat_example_questions.dart';
Expand All @@ -21,22 +22,28 @@ class ChatPage extends StatelessWidget {

@override
Widget build(BuildContext context) {
return PageBaseLayout(
body: Column(
children: [
const ChatToolbarWidget(),
const SizedBox(height: 16.0),
Expanded(
child: FractionallySizedBox(
return CallbackShortcuts(
bindings: {
const SingleActivator(LogicalKeyboardKey.keyN, control: true):
context.read<ChatProvider>().newSession,
},
child: PageBaseLayout(
body: Column(
children: [
const ChatToolbarWidget(),
const SizedBox(height: 16.0),
Expanded(
child: FractionallySizedBox(
widthFactor: 0.6,
child: _buildInnerWidget(context),
),
),
const FractionallySizedBox(
widthFactor: 0.6,
child: _buildInnerWidget(context),
child: ChatInputFieldWidget(),
),
),
const FractionallySizedBox(
widthFactor: 0.6,
child: ChatInputFieldWidget(),
),
],
],
),
),
);
}
Expand Down
6 changes: 6 additions & 0 deletions app/lib/providers/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,12 @@ class ChatProvider extends ChangeNotifier {
notifyListeners();
}

void newSession() {
final session = addSession('');
setSession(session.uuid);
notifyListeners();
}

bool get isWebSearchEnabled => _enableWebSearch;

bool get isDocsSearchEnabled => _enableDocsSearch;
Expand Down
3 changes: 1 addition & 2 deletions app/lib/widgets/chat_toolbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ class _ChatToolbarWidgetState extends State<ChatToolbarWidget> {
SnackBarType.error,
);
} else {
final session = context.read<ChatProvider>().addSession('');
context.read<ChatProvider>().setSession(session.uuid);
context.read<ChatProvider>().newSession();
}
} else {
SnackBarHelper.showSnackBar(
Expand Down