Skip to content

Commit

Permalink
Merge pull request #41 from WilliamKarolDiCioccio/feature/keyboard-sh…
Browse files Browse the repository at this point in the history
…ortcut-new-session

Keyboard shortcut for "new session"
  • Loading branch information
WilliamKarolDiCioccio committed Jun 7, 2024
2 parents 575243e + 0d2efa5 commit 5574b88
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
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 @@ -465,6 +465,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 {
SnackBarHelpers.showSnackBar(
Expand Down

0 comments on commit 5574b88

Please sign in to comment.