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
fix: launch review issues 0.7.9 (#7073)
Richard Shiue87c1245a3ff6
diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/application/ai_prompt_input_bloc.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/application/ai_prompt_input_bloc.dartindex c52a464199..fdbcbb4cc0 100644--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/application/ai_prompt_input_bloc.dart+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/application/ai_prompt_input_bloc.dart@@ -37,8 +37,13 @@ class AIPromptInputBloc extends Bloc<AIPromptInputEvent, AIPromptInputState> {// Only user enable chat with file and the plugin is already runningfinal supportChatWithFile = chatState.fileEnabled &&chatState.pluginState.state == RunningStatePB.Running;++ final aiType = chatState.pluginState.state == RunningStatePB.Running+ ? AIType.localAI+ : AIType.appflowyAI;emit(state.copyWith(+ aiType: aiType,supportChatWithFile: supportChatWithFile,chatState: chatState,),diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_edit_document_service.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_edit_document_service.dartindex 1591b5ca96..e611b7de3e 100644--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_edit_document_service.dart+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_edit_document_service.dart@@ -84,8 +84,10 @@ class ChatEditDocumentService {final nodes = [if (rootIsEmpty || !isLastLineEmpty) paragraphNode(),...messageDocument.root.children,+ paragraphNode(),];- final insertPath = rootIsEmpty || listEquals(lastNodeOrNull.path, const [0])+ final insertPath = rootIsEmpty ||+ listEquals(lastNodeOrNull.path, const [0]) && isLastLineEmpty? const [0]: lastNodeOrNull.path.next;diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_select_sources_cubit.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_select_sources_cubit.dartindex 06ead7d8d8..4c4b473223 100644--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_select_sources_cubit.dart+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_select_sources_cubit.dart@@ -4,6 +4,7 @@ import 'package:appflowy/workspace/presentation/home/menu/view/view_item.dart';import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';import 'package:appflowy_result/appflowy_result.dart';import 'package:bloc/bloc.dart';+import 'package:collection/collection.dart';import 'package:flutter/foundation.dart';import 'package:freezed_annotation/freezed_annotation.dart';@@ -103,7 +104,7 @@ class ChatSettingsCubit extends Cubit<ChatSettingsState> {ChatSettingsCubit() : super(ChatSettingsState.initial());List<String> selectedSourceIds = [];- ChatSource? source;+ List<ChatSource> sources = [];List<ChatSource> selectedSources = [];String filter = '';@@ -111,25 +112,32 @@ class ChatSettingsCubit extends Cubit<ChatSettingsState> {selectedSourceIds = [...newSelectedSourceIds];}- void refreshSources(ViewPB view) async {+ void refreshSources(List<ViewPB> spaceViews) async {filter = "";- final newSource = await _recursiveBuild(view, null);- _restrictSelectionIfNecessary(newSource.children);-- final selected = _buildSelectedSources(newSource).toList();+ final newSources = await Future.wait(+ spaceViews.map((view) => _recursiveBuild(view, null)),+ );+ for (final source in newSources) {+ _restrictSelectionIfNecessary(source.children);+ }- newSource.toggleIsExpanded();+ final selected = newSources+ .map((source) => _buildSelectedSources(source))+ .flattened+ .toList();emit(state.copyWith(selectedSources: selected,- visibleSources: [newSource],+ visibleSources: newSources,),);- source?.dispose();- source = newSource.copy();+ sources+ ..forEach((e) => e.dispose())+ ..clear()+ ..addAll(newSources.map((e) => e.copy()));selectedSources..forEach((e) => e.dispose())@@ -204,12 +212,13 @@ class ChatSettingsCubit extends Cubit<ChatSettingsState> {for (final source in state.visibleSources) {source.dispose();}- if (source == null) {+ if (sources.isEmpty) {emit(ChatSettingsState.initial());} else {final selected =selectedSources.map(_buildSearchResults).nonNulls.toList();- final visible = [_buildSearchResults(source!)].nonNulls.toList();+ final visible =+ sources.map(_buildSearchResults).nonNulls.nonNulls.toList();emit(state.copyWith(selectedSources: selected,@@ -301,25 +310,21 @@ class ChatSettingsCubit extends Cubit<ChatSettingsState> {}void updateSelectedStatus() {- if (source == null) {+ if (sources.isEmpty) {return;}- _recursiveUpdateSelectedStatus(source!);- _restrictSelectionIfNecessary(source!.children);+ for (final source in sources) {+ _recursiveUpdateSelectedStatus(source);+ }+ _restrictSelectionIfNecessary(sources);for (final visibleSource in state.visibleSources) {visibleSource.dispose();}- final visible = [_buildSearchResults(source!)].nonNulls.toList();+ final visible = sources.map(_buildSearchResults).nonNulls.toList();- selectedSources- ..forEach((e) => e.dispose())- ..clear()- ..addAll(_buildSelectedSources(source!));emit(state.copyWith(visibleSources: visible,- selectedSources:- selectedSources.map(_buildSearchResults).nonNulls.toList(),),);}@@ -360,13 +365,24 @@ class ChatSettingsCubit extends Cubit<ChatSettingsState> {?.toggleIsExpanded();}} else {- source?.findChildBySourceId(chatSource.view.id)?.toggleIsExpanded();+ for (final source in sources) {+ final child = source.findChildBySourceId(chatSource.view.id);+ if (child != null) {+ child.toggleIsExpanded();+ break;+ }+ }}}@overrideFuture<void> close() {- source?.dispose();+ for (final child in sources) {+ child.dispose();+ }+ for (final child in selectedSources) {+ child.dispose();+ }for (final child in state.selectedSources) {child.dispose();}diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_input/desktop_ai_prompt_input.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_input/desktop_ai_prompt_input.dartindex a44f446433..0e3ca31980 100644--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_input/desktop_ai_prompt_input.dart+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_input/desktop_ai_prompt_input.dart@@ -506,6 +506,12 @@ class _PromptBottomActions extends StatelessWidget {margin: DesktopAIPromptSizes.actionBarPadding,child: BlocBuilder<AIPromptInputBloc, AIPromptInputState>(builder: (context, state) {+ if (state.chatState == null) {+ return Align(+ alignment: AlignmentDirectional.centerEnd,+ child: _sendButton(),+ );+ }return Row(children: [// predefinedFormatButton(),diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_input/mobile_ai_prompt_input.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_input/mobile_ai_prompt_input.dartindex 65d2f13874..7dbda11bfb 100644--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_input/mobile_ai_prompt_input.dart+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_input/mobile_ai_prompt_input.dart@@ -312,7 +312,7 @@ class _LeadingActions extends StatelessWidget {@overrideWidget build(BuildContext context) {return Material(- color: Theme.of(context).cardColor,+ color: Theme.of(context).colorScheme.surface,child: PromptInputMobileSelectSourcesButton(onUpdateSelectedSources: onUpdateSelectedSources,),diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_input/select_sources_bottom_sheet.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_input/select_sources_bottom_sheet.dartindex 2cd34bfdf0..6e464ef760 100644--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_input/select_sources_bottom_sheet.dart+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_input/select_sources_bottom_sheet.dart@@ -69,9 +69,9 @@ class _PromptInputMobileSelectSourcesButtonStatevalue: cubit,),],- child: BlocSelector<SpaceBloc, SpaceState, ViewPB?>(- selector: (state) => state.currentSpace,- builder: (context, spaceView) {+ child: BlocSelector<SpaceBloc, SpaceState, List<ViewPB>>(+ selector: (state) => state.spaces,+ builder: (context, spaces) {return BlocListener<ChatBloc, ChatState>(listener: (context, state) {cubit@@ -97,11 +97,7 @@ class _PromptInputMobileSelectSourcesButtonState],),onTap: () async {- if (spaceView != null) {- context- .read<ChatSettingsCubit>()- .refreshSources(spaceView);- }+ context.read<ChatSettingsCubit>().refreshSources(spaces);await showMobileBottomSheet<void>(context,backgroundColor: Theme.of(context).colorScheme.surface,diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_input/select_sources_menu.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_input/select_sources_menu.dartindex 47cfec9b4a..72eb18552e 100644--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_input/select_sources_menu.dart+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_input/select_sources_menu.dart@@ -74,9 +74,9 @@ class _PromptInputDesktopSelectSourcesButtonStatevalue: cubit,),],- child: BlocSelector<SpaceBloc, SpaceState, ViewPB?>(- selector: (state) => state.currentSpace,- builder: (context, spaceView) {+ child: BlocSelector<SpaceBloc, SpaceState, List<ViewPB>>(+ selector: (state) => state.spaces,+ builder: (context, spaces) {return BlocListener<ChatBloc, ChatState>(listener: (context, state) {cubit@@ -90,15 +90,11 @@ class _PromptInputDesktopSelectSourcesButtonStatemargin: EdgeInsets.zero,controller: popoverController,onOpen: () {- if (spaceView != null) {- context.read<ChatSettingsCubit>().refreshSources(spaceView);- }+ context.read<ChatSettingsCubit>().refreshSources(spaces);},onClose: () {widget.onUpdateSelectedSources(cubit.selectedSourceIds);- if (spaceView != null) {- context.read<ChatSettingsCubit>().refreshSources(spaceView);- }+ context.read<ChatSettingsCubit>().refreshSources(spaces);},popupBuilder: (_) {return BlocProvider.value(@@ -395,12 +391,19 @@ class ChatSourceTreeItemInner extends StatelessWidget {@overrideWidget build(BuildContext context) {return FlowyHover(+ cursor: isSelectedSection ? SystemMouseCursors.basic : null,style: HoverStyle(- hoverColor: AFThemeExtension.of(context).lightGreyHover,+ hoverColor: isSelectedSection+ ? Colors.transparent+ : AFThemeExtension.of(context).lightGreyHover,),child: GestureDetector(behavior: HitTestBehavior.translucent,- onTap: () => onSelected?.call(chatSource),+ onTap: () {+ if (!isSelectedSection) {+ onSelected?.call(chatSource);+ }+ },child: Row(children: [const HSpace(4.0),diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_message_action_bar.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_message_action_bar.dartindex fe3f1413d9..64183d0346 100644--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_message_action_bar.dart+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_message_action_bar.dart@@ -1,3 +1,4 @@+import 'dart:async';import 'dart:convert';import 'package:appflowy/generated/flowy_svgs.g.dart';@@ -19,6 +20,7 @@ import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/shared_wimport 'package:appflowy/workspace/presentation/home/menu/view/view_item.dart';import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';+import 'package:appflowy_editor/appflowy_editor.dart';import 'package:appflowy_result/appflowy_result.dart';import 'package:easy_localization/easy_localization.dart';import 'package:flowy_infra/theme_extension.dart';@@ -243,7 +245,7 @@ class _SaveToPageButtonState extends State<SaveToPageButton> {constraints: const BoxConstraints.tightFor(width: 300, height: 400),onClose: () {if (spaceView != null) {- context.read<ChatSettingsCubit>().refreshSources(spaceView);+ context.read<ChatSettingsCubit>().refreshSources([spaceView]);}widget.onOverrideVisibility?.call(false);},@@ -273,11 +275,11 @@ class _SaveToPageButtonState extends State<SaveToPageButton> {final documentId = getOpenedDocumentId();if (documentId != null) {await onAddToExistingPage(documentId);- DocumentBloc.findOpen(documentId)?.forceReloadDocumentState();+ await forceReloadAndUpdateSelection(documentId);} else {widget.onOverrideVisibility?.call(true);if (spaceView != null) {- context.read<ChatSettingsCubit>().refreshSources(spaceView);+ context.read<ChatSettingsCubit>().refreshSources([spaceView]);}popoverController.show();}@@ -331,6 +333,26 @@ class _SaveToPageButtonState extends State<SaveToPageButton> {}}+ Future<void> forceReloadAndUpdateSelection(String documentId) async {+ final bloc = DocumentBloc.findOpen(documentId);+ if (bloc == null) {+ return;+ }+ await bloc.forceReloadDocumentState();+ await Future.delayed(const Duration(milliseconds: 500));++ final editorState = bloc.state.editorState;+ final lastNodePath = editorState?.getLastSelectable()?.$1.path;+ if (editorState == null || lastNodePath == null) {+ return;+ }+ unawaited(+ editorState.updateSelectionWithReason(+ Selection.collapsed(Position(path: lastNodePath)),+ ),+ );+ }+String? getOpenedDocumentId() {final pageManager = getIt<TabsBloc>().state.currentPageManager;if (!pageManager.showSecondaryPluginNotifier.value) {diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_metadata.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_metadata.dartindex d55be401f9..1e06ff5f46 100644--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_metadata.dart+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_metadata.dart@@ -1,11 +1,17 @@import 'package:appflowy/generated/flowy_svgs.g.dart';import 'package:appflowy/generated/locale_keys.g.dart';import 'package:appflowy/plugins/ai_chat/application/chat_entity.dart';+import 'package:appflowy/workspace/application/view/view_bloc.dart';+import 'package:appflowy/workspace/application/view/view_ext.dart';+import 'package:appflowy/workspace/application/view/view_service.dart';+import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';import 'package:easy_localization/easy_localization.dart';import 'package:flowy_infra_ui/style_widget/button.dart';import 'package:flowy_infra_ui/style_widget/text.dart';import 'package:flowy_infra_ui/widget/spacing.dart';import 'package:flutter/material.dart';+import 'package:flutter_bloc/flutter_bloc.dart';+import 'package:string_validator/string_validator.dart';import 'package:time/time.dart';class AIMessageMetadata extends StatefulWidget {@@ -68,30 +74,43 @@ class _AIMessageMetadataState extends State<AIMessageMetadata> {runSpacing: 4.0,children: widget.sources.map((m) {- return ConstrainedBox(- constraints: const BoxConstraints(- maxHeight: 24,- maxWidth: 240,- ),- child: FlowyButton(- margin: const EdgeInsets.all(4.0),- useIntrinsicWidth: true,- radius: BorderRadius.circular(8.0),- text: FlowyText(- m.name,- fontSize: 12,- overflow: TextOverflow.ellipsis,- ),- leftIcon: FlowySvg(- FlowySvgs.icon_document_s,- size: const Size.square(16),- color: Theme.of(context).hintColor,- ),- onTap: () {- widget.onSelectedMetadata?.call(m);+ if (isURL(m.id)) {+ return _MetadataButton(+ name: m.id,+ onTap: () => widget.onSelectedMetadata?.call(m),+ );+ } else if (isUUID(m.id)) {+ return FutureBuilder<ViewPB?>(+ future: ViewBackendService.getView(m.id)+ .then((f) => f.toNullable()),+ builder: (context, snapshot) {+ final data = snapshot.data;+ if (!snapshot.hasData ||+ snapshot.connectionState != ConnectionState.done ||+ data == null) {+ return _MetadataButton(+ name: m.name,+ );+ }+ return BlocProvider(+ create: (_) => ViewBloc(view: data),+ child: BlocBuilder<ViewBloc, ViewState>(+ builder: (context, state) {+ return _MetadataButton(+ name: state.view.nameOrDefault,+ onTap: () => widget.onSelectedMetadata?.call(m),+ );+ },+ ),+ );},- ),- );+ );+ } else {+ return _MetadataButton(+ name: m.name,+ onTap: () => widget.onSelectedMetadata?.call(m),+ );+ }},).toList(),),@@ -101,3 +120,39 @@ class _AIMessageMetadataState extends State<AIMessageMetadata> {);}}++class _MetadataButton extends StatelessWidget {+ const _MetadataButton({+ this.name = "",+ this.onTap,+ });++ final String name;+ final void Function()? onTap;++ @override+ Widget build(BuildContext context) {+ return ConstrainedBox(+ constraints: const BoxConstraints(+ maxHeight: 24,+ maxWidth: 240,+ ),+ child: FlowyButton(+ margin: const EdgeInsets.all(4.0),+ useIntrinsicWidth: true,+ radius: BorderRadius.circular(8.0),+ text: FlowyText(+ name,+ fontSize: 12,+ overflow: TextOverflow.ellipsis,+ ),+ leftIcon: FlowySvg(+ FlowySvgs.icon_document_s,+ size: const Size.square(16),+ color: Theme.of(context).hintColor,+ ),+ onTap: onTap,+ ),+ );+ }+}diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_text_message.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_text_message.dartindex a4ef77bd06..632bf64ebc 100644--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_text_message.dart+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_text_message.dart@@ -100,7 +100,7 @@ class ChatAIMessageWidget extends StatelessWidget {onSelectedMetadata: onSelectedMetadata,),if (state.sources.isNotEmpty && !isLastMessage)- const VSpace(16.0),+ const VSpace(8.0),],),);diff --git a/frontend/appflowy_flutter/lib/plugins/document/application/document_bloc.dart b/frontend/appflowy_flutter/lib/plugins/document/application/document_bloc.dartindex 8a7d9ba47e..f34c9e0d6d 100644--- a/frontend/appflowy_flutter/lib/plugins/document/application/document_bloc.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/application/document_bloc.dart@@ -422,8 +422,8 @@ class DocumentBloc extends Bloc<DocumentEvent, DocumentState> {);}- void forceReloadDocumentState() {- _documentCollabAdapter.syncV3();+ Future<void> forceReloadDocumentState() {+ return _documentCollabAdapter.syncV3();}// this is only used for debug modediff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/home_stack.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/home_stack.dartindex 4261865e5e..d6fccee450 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/home_stack.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/home_stack.dart@@ -737,6 +737,7 @@ class HomeSecondaryTopBar extends StatelessWidget {children: [FlowyIconButton(width: 24,+ tooltipText: LocaleKeys.sideBar_closeSidebar.tr(),radius: const BorderRadius.all(Radius.circular(8.0)),icon: const FlowySvg(FlowySvgs.show_menu_s,@@ -749,6 +750,7 @@ class HomeSecondaryTopBar extends StatelessWidget {const HSpace(8.0),FlowyIconButton(width: 24,+ tooltipText: LocaleKeys.sideBar_expandSidebar.tr(),radius: const BorderRadius.all(Radius.circular(8.0)),icon: const FlowySvg(FlowySvgs.full_view_s,diff --git a/frontend/resources/translations/en.json b/frontend/resources/translations/en.jsonindex 6cc508ed4a..57f4897bbe 100644--- a/frontend/resources/translations/en.json+++ b/frontend/resources/translations/en.json@@ -304,6 +304,7 @@"sideBar": {"closeSidebar": "Close sidebar","openSidebar": "Open sidebar",+ "expandSidebar": "Expand as full page","personal": "Personal","private": "Private","workspace": "Workspace",