Skip to content

Commit bcf8ea0

Browse files
committed
feat: add toast messages for ai chat interactions
1 parent dffb865 commit bcf8ea0

File tree

4 files changed

+55
-6
lines changed

4 files changed

+55
-6
lines changed

frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_message_action_bar.dart

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ class _SaveToPageButtonState extends State<SaveToPageButton> {
274274
onPressed: () async {
275275
final documentId = getOpenedDocumentId();
276276
if (documentId != null) {
277-
await onAddToExistingPage(documentId);
277+
await onAddToExistingPage(context, documentId);
278278
await forceReloadAndUpdateSelection(documentId);
279279
} else {
280280
widget.onOverrideVisibility?.call(true);
@@ -298,9 +298,8 @@ class _SaveToPageButtonState extends State<SaveToPageButton> {
298298
},
299299
onAddToExistingPage: (documentId) async {
300300
popoverController.close();
301-
await onAddToExistingPage(documentId);
302-
final view =
303-
await ViewBackendService.getView(documentId).toNullable();
301+
final view = await onAddToExistingPage(context, documentId);
302+
304303
if (context.mounted) {
305304
openPageFromMessage(context, view);
306305
}
@@ -309,12 +308,20 @@ class _SaveToPageButtonState extends State<SaveToPageButton> {
309308
);
310309
}
311310

312-
Future<void> onAddToExistingPage(String documentId) async {
311+
Future<ViewPB?> onAddToExistingPage(
312+
BuildContext context,
313+
String documentId,
314+
) async {
313315
await ChatEditDocumentService.addMessageToPage(
314316
documentId,
315317
widget.textMessage,
316318
);
317319
await Future.delayed(const Duration(milliseconds: 500));
320+
final view = await ViewBackendService.getView(documentId).toNullable();
321+
if (context.mounted) {
322+
showSaveMessageSuccessToast(context, view);
323+
}
324+
return view;
318325
}
319326

320327
void addMessageToNewPage(BuildContext context) async {
@@ -327,12 +334,43 @@ class _SaveToPageButtonState extends State<SaveToPageButton> {
327334
chatView.parentViewId,
328335
[widget.textMessage],
329336
);
337+
330338
if (context.mounted) {
339+
showSaveMessageSuccessToast(context, newView);
331340
openPageFromMessage(context, newView);
332341
}
333342
}
334343
}
335344

345+
void showSaveMessageSuccessToast(BuildContext context, ViewPB? view) {
346+
if (view == null) {
347+
return;
348+
}
349+
showToastNotification(
350+
context,
351+
richMessage: TextSpan(
352+
children: [
353+
TextSpan(
354+
text: LocaleKeys.chat_addToNewPageSuccessToast.tr(),
355+
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
356+
color: const Color(0xFFFFFFFF),
357+
),
358+
),
359+
const TextSpan(
360+
text: ' ',
361+
),
362+
TextSpan(
363+
text: view.nameOrDefault,
364+
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
365+
color: const Color(0xFFFFFFFF),
366+
fontWeight: FontWeight.w700,
367+
),
368+
),
369+
],
370+
),
371+
);
372+
}
373+
336374
Future<void> forceReloadAndUpdateSelection(String documentId) async {
337375
final bloc = DocumentBloc.findOpen(documentId);
338376
if (bloc == null) {

frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_metadata.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class _AIMessageMetadataState extends State<AIMessageMetadata> {
9090
data == null) {
9191
return _MetadataButton(
9292
name: m.name,
93+
onTap: () => widget.onSelectedMetadata?.call(m),
9394
);
9495
}
9596
return BlocProvider(

frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/message_util.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1+
import 'package:appflowy/generated/locale_keys.g.dart';
12
import 'package:appflowy/mobile/application/mobile_router.dart';
23
import 'package:appflowy/startup/startup.dart';
34
import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
45
import 'package:appflowy/workspace/application/view/view_ext.dart';
6+
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
57
import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
8+
import 'package:easy_localization/easy_localization.dart';
69
import 'package:flutter/widgets.dart';
710
import 'package:universal_platform/universal_platform.dart';
811

912
/// Opens a message in the right hand sidebar on desktop, and push the page
1013
/// on mobile
1114
void openPageFromMessage(BuildContext context, ViewPB? view) {
1215
if (view == null) {
16+
showToastNotification(
17+
context,
18+
message: LocaleKeys.chat_openPagePreviewFailedToast.tr(),
19+
type: ToastificationType.error,
20+
);
1321
return;
1422
}
1523
if (UniversalPlatform.isDesktop) {

frontend/resources/translations/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@
218218
"addToPageButton": "Add to page",
219219
"addToPageTitle": "Add message to...",
220220
"addToNewPage": "Add to a new page",
221-
"addToNewPageName": "Messages extracted from \"{}\""
221+
"addToNewPageName": "Messages extracted from \"{}\"",
222+
"addToNewPageSuccessToast": "Message added to",
223+
"openPagePreviewFailedToast": "Failed to open page"
222224
},
223225
"trash": {
224226
"text": "Trash",

0 commit comments

Comments
 (0)