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(mobile): edit mention page (#7698)
Richard Shiue7d0f6c9debd8
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/base/insert_page_command.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/base/insert_page_command.dartindex af605972de..11aed036d2 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/base/insert_page_command.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/base/insert_page_command.dart@@ -70,13 +70,12 @@ extension InsertDatabase on EditorState {node,selection.end.offset,0,- r'$',- attributes: {- MentionBlockKeys.mention: {- MentionBlockKeys.type: MentionType.page.name,- MentionBlockKeys.pageId: view.id,- },- },+ MentionBlockKeys.mentionChar,+ attributes: MentionBlockKeys.buildMentionPageAttributes(+ mentionType: MentionType.page,+ pageId: view.id,+ blockId: null,+ ),);}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/paste_from_block_link.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/paste_from_block_link.dartindex fbd9914c1d..c47c0c967d 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/paste_from_block_link.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/paste_from_block_link.dart@@ -43,13 +43,11 @@ extension PasteFromBlockLink on EditorState {node,selection.startIndex,MentionBlockKeys.mentionChar,- attributes: {- MentionBlockKeys.mention: {- MentionBlockKeys.type: MentionType.page.name,- MentionBlockKeys.blockId: blockId,- MentionBlockKeys.pageId: pageId,- },- },+ attributes: MentionBlockKeys.buildMentionPageAttributes(+ mentionType: MentionType.page,+ pageId: pageId,+ blockId: blockId,+ ),);await apply(transaction);diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/child_page_transaction_handler.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/child_page_transaction_handler.dartindex ef32ad1098..117e09e67f 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/child_page_transaction_handler.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/child_page_transaction_handler.dart@@ -179,13 +179,6 @@ class ChildPageTransactionHandler extends MentionTransactionHandler {await duplicatedViewOrFailure.fold((newView) async {- final newMentionAttributes = {- MentionBlockKeys.mention: {- MentionBlockKeys.type: MentionType.childPage.name,- MentionBlockKeys.pageId: newView.id,- },- };-// The index is the index of the delta, to get the index of the mention character// in all the text, we need to calculate it based on the deltas before the current delta.int mentionIndex = 0;@@ -202,7 +195,11 @@ class ChildPageTransactionHandler extends MentionTransactionHandler {node,mentionIndex,MentionBlockKeys.mentionChar.length,- newMentionAttributes,+ MentionBlockKeys.buildMentionPageAttributes(+ mentionType: MentionType.childPage,+ pageId: newView.id,+ blockId: null,+ ),);await editorState.apply(transaction,diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/date_transaction_handler.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/date_transaction_handler.dartindex 972ed229dd..cb3196e9b7 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/date_transaction_handler.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/date_transaction_handler.dart@@ -192,15 +192,12 @@ class DateTransactionHandler extends MentionTransactionHandler {),);- final newMentionAttributes = {- MentionBlockKeys.mention: {- MentionBlockKeys.type: MentionType.date.name,- MentionBlockKeys.date: dateTime.toIso8601String(),- MentionBlockKeys.reminderId: reminderId,- MentionBlockKeys.includeTime: data.includeTime,- MentionBlockKeys.reminderOption: data.reminderOption.name,- },- };+ final newMentionAttributes = MentionBlockKeys.buildMentionDateAttributes(+ date: dateTime.toIso8601String(),+ reminderId: reminderId,+ reminderOption: data.reminderOption.name,+ includeTime: data.includeTime,+ );// The index is the index of the delta, to get the index of the mention character// in all the text, we need to calculate it based on the deltas before the current delta.diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_block.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_block.dartindex d65609f1a8..79c9b31d20 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_block.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_block.dart@@ -27,12 +27,12 @@ Node dateMentionNode() {operations: [TextInsert(MentionBlockKeys.mentionChar,- attributes: {- MentionBlockKeys.mention: {- MentionBlockKeys.type: MentionType.date.name,- MentionBlockKeys.date: DateTime.now().toIso8601String(),- },- },+ attributes: MentionBlockKeys.buildMentionDateAttributes(+ date: DateTime.now().toIso8601String(),+ reminderId: null,+ reminderOption: null,+ includeTime: false,+ ),),],),@@ -42,18 +42,51 @@ Node dateMentionNode() {class MentionBlockKeys {const MentionBlockKeys._();- static const reminderId = 'reminder_id'; // ReminderIDstatic const mention = 'mention';static const type = 'type'; // MentionType, String+static const pageId = 'page_id';static const blockId = 'block_id';// Related to Reminder and Date blocksstatic const date = 'date'; // Start Datestatic const includeTime = 'include_time';+ static const reminderId = 'reminder_id'; // ReminderIDstatic const reminderOption = 'reminder_option';static const mentionChar = '\$';++ static Map<String, dynamic> buildMentionPageAttributes({+ required MentionType mentionType,+ required String pageId,+ required String? blockId,+ }) {+ return {+ MentionBlockKeys.mention: {+ MentionBlockKeys.type: mentionType.name,+ MentionBlockKeys.pageId: pageId,+ if (blockId != null) MentionBlockKeys.blockId: blockId,+ },+ };+ }++ static Map<String, dynamic> buildMentionDateAttributes({+ required String date,+ required String? reminderId,+ required String? reminderOption,+ required bool includeTime,+ }) {+ return {+ MentionBlockKeys.mention: {+ MentionBlockKeys.type: MentionType.date.name,+ MentionBlockKeys.date: date,+ MentionBlockKeys.includeTime: includeTime,+ if (reminderId != null) MentionBlockKeys.reminderId: reminderId,+ if (reminderOption != null)+ MentionBlockKeys.reminderOption: reminderOption,+ },+ };+ }}class MentionBlock extends StatelessWidget {diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_date_block.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_date_block.dartindex 6c5ee7f527..20f60be23d 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_date_block.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_date_block.dart@@ -201,16 +201,17 @@ class _MentionDateBlockState extends State<MentionDateBlock> {(reminderOption == ReminderOption.none ? null : widget.reminderId);final transaction = widget.editorState.transaction- ..formatText(widget.node, widget.index, 1, {- MentionBlockKeys.mention: {- MentionBlockKeys.type: MentionType.date.name,- MentionBlockKeys.date: date.toIso8601String(),- MentionBlockKeys.reminderId: rId,- MentionBlockKeys.includeTime: includeTime,- MentionBlockKeys.reminderOption:- reminderOption?.name ?? widget.reminderOption.name,- },- });+ ..formatText(+ widget.node,+ widget.index,+ 1,+ MentionBlockKeys.buildMentionDateAttributes(+ date: date.toIso8601String(),+ reminderId: rId,+ includeTime: includeTime,+ reminderOption: reminderOption?.name ?? widget.reminderOption.name,+ ),+ );widget.editorState.apply(transaction, withUpdateSelection: false);diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_page_block.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_page_block.dartindex 23c05b89eb..ede690eb30 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_page_block.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_page_block.dart@@ -50,12 +50,11 @@ Node pageMentionNode(String viewId) {operations: [TextInsert(MentionBlockKeys.mentionChar,- attributes: {- MentionBlockKeys.mention: {- MentionBlockKeys.type: MentionType.page.name,- MentionBlockKeys.pageId: viewId,- },- },+ attributes: MentionBlockKeys.buildMentionPageAttributes(+ mentionType: MentionType.page,+ pageId: viewId,+ blockId: null,+ ),),],),@@ -284,12 +283,11 @@ class _MentionSubPageBlockState extends State<MentionSubPageBlock> {widget.node,widget.index,MentionBlockKeys.mentionChar.length,- {- MentionBlockKeys.mention: {- MentionBlockKeys.type: MentionType.page.name,- MentionBlockKeys.pageId: widget.pageId,- },- },+ MentionBlockKeys.buildMentionPageAttributes(+ mentionType: MentionType.page,+ pageId: widget.pageId,+ blockId: null,+ ),);widget.editorState.apply(@@ -383,25 +381,24 @@ Future<void> _handleDoubleTap(}final currentViewId = context.read<DocumentBloc>().documentId;- final newViewId = await showPageSelectorSheet(+ final newView = await showPageSelectorSheet(context,currentViewId: currentViewId,selectedViewId: viewId,);- if (newViewId != null) {+ if (newView != null) {// Update this nodes pageIdfinal transaction = editorState.transaction..formatText(node,index,1,- {- MentionBlockKeys.mention: {- MentionBlockKeys.type: MentionType.page.name,- MentionBlockKeys.pageId: newViewId,- },- },+ MentionBlockKeys.buildMentionPageAttributes(+ mentionType: MentionType.page,+ pageId: newView.id,+ blockId: null,+ ),);await editorState.apply(transaction, withUpdateSelection: false);diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/date_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/date_item.dartindex 0bb09d0a7e..04a8ee1b7e 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/date_item.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/date_item.dart@@ -46,12 +46,12 @@ extension on EditorState {selection.start.offset,0,MentionBlockKeys.mentionChar,- attributes: {- MentionBlockKeys.mention: {- MentionBlockKeys.type: MentionType.date.name,- MentionBlockKeys.date: DateTime.now().toIso8601String(),- },- },+ attributes: MentionBlockKeys.buildMentionDateAttributes(+ date: DateTime.now().toIso8601String(),+ reminderId: null,+ reminderOption: null,+ includeTime: false,+ ),);await apply(transaction);diff --git a/frontend/appflowy_flutter/lib/plugins/inline_actions/handlers/child_page.dart b/frontend/appflowy_flutter/lib/plugins/inline_actions/handlers/child_page.dartindex d29a1f86bf..665c284aea 100644--- a/frontend/appflowy_flutter/lib/plugins/inline_actions/handlers/child_page.dart+++ b/frontend/appflowy_flutter/lib/plugins/inline_actions/handlers/child_page.dart@@ -71,12 +71,11 @@ class InlineChildPageService extends InlineActionsDelegate {replacement.$1,replacement.$2,MentionBlockKeys.mentionChar,- attributes: {- MentionBlockKeys.mention: {- MentionBlockKeys.type: MentionType.childPage.name,- MentionBlockKeys.pageId: view.id,- },- },+ attributes: MentionBlockKeys.buildMentionPageAttributes(+ mentionType: MentionType.childPage,+ pageId: view.id,+ blockId: null,+ ),);await editorState.apply(transaction);diff --git a/frontend/appflowy_flutter/lib/plugins/inline_actions/handlers/date_reference.dart b/frontend/appflowy_flutter/lib/plugins/inline_actions/handlers/date_reference.dartindex c7076bd255..747c8667f8 100644--- a/frontend/appflowy_flutter/lib/plugins/inline_actions/handlers/date_reference.dart+++ b/frontend/appflowy_flutter/lib/plugins/inline_actions/handlers/date_reference.dart@@ -122,12 +122,12 @@ class DateReferenceService extends InlineActionsDelegate {start,end,MentionBlockKeys.mentionChar,- attributes: {- MentionBlockKeys.mention: {- MentionBlockKeys.type: MentionType.date.name,- MentionBlockKeys.date: date.toIso8601String(),- },- },+ attributes: MentionBlockKeys.buildMentionDateAttributes(+ date: date.toIso8601String(),+ includeTime: false,+ reminderId: null,+ reminderOption: null,+ ),);await editorState.apply(transaction);diff --git a/frontend/appflowy_flutter/lib/plugins/inline_actions/handlers/inline_page_reference.dart b/frontend/appflowy_flutter/lib/plugins/inline_actions/handlers/inline_page_reference.dartindex 27a632e8ef..ebc684327b 100644--- a/frontend/appflowy_flutter/lib/plugins/inline_actions/handlers/inline_page_reference.dart+++ b/frontend/appflowy_flutter/lib/plugins/inline_actions/handlers/inline_page_reference.dart@@ -221,12 +221,11 @@ class InlinePageReferenceService extends InlineActionsDelegate {replace.$1,replace.$2,MentionBlockKeys.mentionChar,- attributes: {- MentionBlockKeys.mention: {- MentionBlockKeys.type: MentionType.page.name,- MentionBlockKeys.pageId: view.id,- },- },+ attributes: MentionBlockKeys.buildMentionPageAttributes(+ mentionType: MentionType.page,+ pageId: view.id,+ blockId: null,+ ),);await editorState.apply(transaction);diff --git a/frontend/appflowy_flutter/lib/plugins/inline_actions/handlers/reminder_reference.dart b/frontend/appflowy_flutter/lib/plugins/inline_actions/handlers/reminder_reference.dartindex 1f479fa7c5..471f1c9211 100644--- a/frontend/appflowy_flutter/lib/plugins/inline_actions/handlers/reminder_reference.dart+++ b/frontend/appflowy_flutter/lib/plugins/inline_actions/handlers/reminder_reference.dart@@ -148,14 +148,12 @@ class ReminderReferenceService extends InlineActionsDelegate {start,end,MentionBlockKeys.mentionChar,- attributes: {- MentionBlockKeys.mention: {- MentionBlockKeys.type: MentionType.date.name,- MentionBlockKeys.date: date.toIso8601String(),- MentionBlockKeys.reminderId: reminder.id,- MentionBlockKeys.reminderOption: ReminderOption.atTimeOfEvent.name,- },- },+ attributes: MentionBlockKeys.buildMentionDateAttributes(+ date: date.toIso8601String(),+ reminderId: reminder.id,+ reminderOption: ReminderOption.atTimeOfEvent.name,+ includeTime: false,+ ),);await editorState.apply(transaction);