Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
chore: disable add messages to page when chat is empty (#7518)
Richard Shiue392964ffd2b9
diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_select_message_bloc.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_select_message_bloc.dartindex 90a2db168f..9977d1df72 100644--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_select_message_bloc.dart+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_select_message_bloc.dart@@ -19,9 +19,17 @@ class ChatSelectMessageBlocon<ChatSelectMessageEvent>((event, emit) {event.when(+ enableStartSelectingMessages: () {+ emit(state.copyWith(enabled: true));+ },toggleSelectingMessages: () {if (state.isSelectingMessages) {- emit(ChatSelectMessageState.initial());+ emit(+ state.copyWith(+ isSelectingMessages: false,+ selectedMessages: [],+ ),+ );} else {emit(state.copyWith(isSelectingMessages: true));}@@ -50,8 +58,13 @@ class ChatSelectMessageBlocunselectAllMessages: () {emit(state.copyWith(selectedMessages: const []));},- saveAsPage: () {- emit(ChatSelectMessageState.initial());+ reset: () {+ emit(+ state.copyWith(+ isSelectingMessages: false,+ selectedMessages: [],+ ),+ );},);},@@ -70,6 +83,8 @@ class ChatSelectMessageBloc@freezedclass ChatSelectMessageEvent with _$ChatSelectMessageEvent {+ const factory ChatSelectMessageEvent.enableStartSelectingMessages() =+ _EnableStartSelectingMessages;const factory ChatSelectMessageEvent.toggleSelectingMessages() =_ToggleSelectingMessages;const factory ChatSelectMessageEvent.toggleSelectMessage(Message message) =@@ -79,7 +94,7 @@ class ChatSelectMessageEvent with _$ChatSelectMessageEvent {) = _SelectAllMessages;const factory ChatSelectMessageEvent.unselectAllMessages() =_UnselectAllMessages;- const factory ChatSelectMessageEvent.saveAsPage() = _SaveAsPage;+ const factory ChatSelectMessageEvent.reset() = _Reset;}@freezed@@ -87,9 +102,11 @@ class ChatSelectMessageState with _$ChatSelectMessageState {const factory ChatSelectMessageState({required bool isSelectingMessages,required List<Message> selectedMessages,+ required bool enabled,}) = _ChatSelectMessageState;factory ChatSelectMessageState.initial() => const ChatSelectMessageState(+ enabled: false,isSelectingMessages: false,selectedMessages: [],);diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/chat.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/chat.dartindex 1b3880e01d..b840472854 100644--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/chat.dart+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/chat.dart@@ -178,6 +178,7 @@ class AIChatPagePluginWidgetBuilder extends PluginWidgetBuildercustomActions: [CustomViewAction(view: notifier.view,+ disabled: !state.enabled,leftIcon: FlowySvgs.ai_add_to_page_s,label: LocaleKeys.moreAction_saveAsNewPage.tr(),onTap: () {diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/chat_page.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/chat_page.dartindex 74d1364436..2d0c05b2c4 100644--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/chat_page.dart+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/chat_page.dart@@ -319,6 +319,10 @@ class _ChatContentPage extends StatelessWidget {);}+ context+ .read<ChatSelectMessageBloc>()+ .add(ChatSelectMessageEvent.enableStartSelectingMessages());+return BlocSelector<ChatSelectMessageBloc, ChatSelectMessageState, bool>(selector: (state) => state.isSelectingMessages,builder: (context, isSelectingMessages) {diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_message_selector_banner.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_message_selector_banner.dartindex 4b25297d63..790a3fac3c 100644--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_message_selector_banner.dart+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_message_selector_banner.dart@@ -250,7 +250,7 @@ class _SaveToPageButtonState extends State<SaveToPageButton> {showSaveMessageSuccessToast(context, view);}- bloc.add(const ChatSelectMessageEvent.saveAsPage());+ bloc.add(const ChatSelectMessageEvent.reset());return view;}@@ -275,7 +275,7 @@ class _SaveToPageButtonState extends State<SaveToPageButton> {showSaveMessageSuccessToast(context, newView);openPageFromMessage(context, newView);}- bloc.add(const ChatSelectMessageEvent.saveAsPage());+ bloc.add(const ChatSelectMessageEvent.reset());}Future<void> forceReload(String documentId) async {diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/more_view_actions/widgets/common_view_action.dart b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/more_view_actions/widgets/common_view_action.dartindex 10bc3dde34..6fad559ba4 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/more_view_actions/widgets/common_view_action.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/more_view_actions/widgets/common_view_action.dart@@ -107,6 +107,7 @@ class CustomViewAction extends StatelessWidget {required this.view,required this.leftIcon,required this.label,+ this.disabled = false,this.onTap,this.mutex,});@@ -114,6 +115,7 @@ class CustomViewAction extends StatelessWidget {final ViewPB view;final FlowySvgData leftIcon;final String label;+ final bool disabled;final VoidCallback? onTap;final PopoverMutex? mutex;@@ -122,17 +124,20 @@ class CustomViewAction extends StatelessWidget {return Container(height: 34,padding: const EdgeInsets.symmetric(vertical: 2.0),- child: FlowyIconTextButton(+ child: FlowyButton(margin: const EdgeInsets.symmetric(horizontal: 6),+ disable: disabled,onTap: onTap,- leftIconBuilder: (onHover) => FlowySvg(+ leftIcon: FlowySvg(leftIcon,size: const Size.square(16.0),+ color: disabled ? Theme.of(context).disabledColor : null,),iconPadding: 10.0,- textBuilder: (onHover) => FlowyText(+ text: FlowyText(label,figmaLineHeight: 18.0,+ color: disabled ? Theme.of(context).disabledColor : null,),),);