mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: update view names in page reference menu (#4802)
This commit is contained in:
parent
b087a9aeb3
commit
5daf9d23f5
@ -81,9 +81,9 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
|
|||||||
InlinePageReferenceService(
|
InlinePageReferenceService(
|
||||||
currentViewId: documentBloc.view.id,
|
currentViewId: documentBloc.view.id,
|
||||||
limitResults: 5,
|
limitResults: 5,
|
||||||
).inlinePageReferenceDelegate,
|
),
|
||||||
DateReferenceService(context).dateReferenceDelegate,
|
DateReferenceService(context),
|
||||||
ReminderReferenceService(context).reminderReferenceDelegate,
|
ReminderReferenceService(context),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -32,13 +32,13 @@ Future<void> showLinkToPageMenu(
|
|||||||
customTitle: titleFromPageType(pageType),
|
customTitle: titleFromPageType(pageType),
|
||||||
insertPage: pageType != ViewLayoutPB.Document,
|
insertPage: pageType != ViewLayoutPB.Document,
|
||||||
limitResults: 15,
|
limitResults: 15,
|
||||||
).inlinePageReferenceDelegate,
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
final List<InlineActionsResult> initialResults = [];
|
final List<InlineActionsResult> initialResults = [];
|
||||||
for (final handler in service.handlers) {
|
for (final handler in service.handlers) {
|
||||||
final group = await handler();
|
final group = await handler.search(null);
|
||||||
|
|
||||||
if (group.results.isNotEmpty) {
|
if (group.results.isNotEmpty) {
|
||||||
initialResults.add(group);
|
initialResults.add(group);
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:appflowy/plugins/inline_actions/handlers/inline_page_reference.dart';
|
import 'package:appflowy/plugins/inline_actions/handlers/inline_page_reference.dart';
|
||||||
import 'package:appflowy/plugins/inline_actions/inline_actions_menu.dart';
|
import 'package:appflowy/plugins/inline_actions/inline_actions_menu.dart';
|
||||||
import 'package:appflowy/plugins/inline_actions/inline_actions_result.dart';
|
import 'package:appflowy/plugins/inline_actions/inline_actions_result.dart';
|
||||||
import 'package:appflowy/plugins/inline_actions/inline_actions_service.dart';
|
import 'package:appflowy/plugins/inline_actions/inline_actions_service.dart';
|
||||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
const _bracketChar = '[';
|
const _bracketChar = '[';
|
||||||
const _plusChar = '+';
|
const _plusChar = '+';
|
||||||
@ -89,7 +90,7 @@ Future<bool> inlinePageReferenceCommandHandler(
|
|||||||
InlinePageReferenceService(
|
InlinePageReferenceService(
|
||||||
currentViewId: currentViewId,
|
currentViewId: currentViewId,
|
||||||
limitResults: 10,
|
limitResults: 10,
|
||||||
).inlinePageReferenceDelegate,
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -97,7 +98,7 @@ Future<bool> inlinePageReferenceCommandHandler(
|
|||||||
|
|
||||||
final List<InlineActionsResult> initialResults = [];
|
final List<InlineActionsResult> initialResults = [];
|
||||||
for (final handler in service.handlers) {
|
for (final handler in service.handlers) {
|
||||||
final group = await handler();
|
final group = await handler.search(null);
|
||||||
|
|
||||||
if (group.results.isNotEmpty) {
|
if (group.results.isNotEmpty) {
|
||||||
initialResults.add(group);
|
initialResults.add(group);
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:appflowy/date/date_service.dart';
|
import 'package:appflowy/date/date_service.dart';
|
||||||
import 'package:appflowy/generated/locale_keys.g.dart';
|
import 'package:appflowy/generated/locale_keys.g.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/base/string_extension.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/base/string_extension.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/mention_block.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/mention_block.dart';
|
||||||
import 'package:appflowy/plugins/inline_actions/inline_actions_result.dart';
|
import 'package:appflowy/plugins/inline_actions/inline_actions_result.dart';
|
||||||
|
import 'package:appflowy/plugins/inline_actions/service_handler.dart';
|
||||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
final _keywords = [
|
final _keywords = [
|
||||||
LocaleKeys.inlineActions_date.tr().toLowerCase(),
|
LocaleKeys.inlineActions_date.tr().toLowerCase(),
|
||||||
];
|
];
|
||||||
|
|
||||||
class DateReferenceService {
|
class DateReferenceService extends InlineActionsDelegate {
|
||||||
DateReferenceService(this.context) {
|
DateReferenceService(this.context) {
|
||||||
// Initialize locale
|
// Initialize locale
|
||||||
_locale = context.locale.toLanguageTag();
|
_locale = context.locale.toLanguageTag();
|
||||||
@ -27,7 +29,8 @@ class DateReferenceService {
|
|||||||
|
|
||||||
List<InlineActionsMenuItem> options = [];
|
List<InlineActionsMenuItem> options = [];
|
||||||
|
|
||||||
Future<InlineActionsResult> dateReferenceDelegate([
|
@override
|
||||||
|
Future<InlineActionsResult> search([
|
||||||
String? search,
|
String? search,
|
||||||
]) async {
|
]) async {
|
||||||
// Checks if Locale has changed since last
|
// Checks if Locale has changed since last
|
||||||
|
@ -9,16 +9,23 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/me
|
|||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/mention_page_block.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/mention_page_block.dart';
|
||||||
import 'package:appflowy/plugins/inline_actions/inline_actions_menu.dart';
|
import 'package:appflowy/plugins/inline_actions/inline_actions_menu.dart';
|
||||||
import 'package:appflowy/plugins/inline_actions/inline_actions_result.dart';
|
import 'package:appflowy/plugins/inline_actions/inline_actions_result.dart';
|
||||||
|
import 'package:appflowy/plugins/inline_actions/service_handler.dart';
|
||||||
|
import 'package:appflowy/startup/startup.dart';
|
||||||
|
import 'package:appflowy/user/application/auth/auth_service.dart';
|
||||||
import 'package:appflowy/workspace/application/view/view_ext.dart';
|
import 'package:appflowy/workspace/application/view/view_ext.dart';
|
||||||
import 'package:appflowy/workspace/application/view/view_service.dart';
|
import 'package:appflowy/workspace/application/view/view_service.dart';
|
||||||
|
import 'package:appflowy/workspace/application/workspace/workspace_listener.dart';
|
||||||
|
import 'package:appflowy_backend/dispatch/dispatch.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
||||||
|
import 'package:appflowy_backend/protobuf/flowy-folder/workspace.pb.dart';
|
||||||
|
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
|
||||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flowy_infra_ui/widget/dialog/styled_dialogs.dart';
|
import 'package:flowy_infra_ui/widget/dialog/styled_dialogs.dart';
|
||||||
import 'package:flowy_infra_ui/widget/error_page.dart';
|
import 'package:flowy_infra_ui/widget/error_page.dart';
|
||||||
|
|
||||||
class InlinePageReferenceService {
|
class InlinePageReferenceService extends InlineActionsDelegate {
|
||||||
InlinePageReferenceService({
|
InlinePageReferenceService({
|
||||||
required this.currentViewId,
|
required this.currentViewId,
|
||||||
this.viewLayout,
|
this.viewLayout,
|
||||||
@ -51,12 +58,67 @@ class InlinePageReferenceService {
|
|||||||
List<InlineActionsMenuItem> _items = [];
|
List<InlineActionsMenuItem> _items = [];
|
||||||
List<InlineActionsMenuItem> _filtered = [];
|
List<InlineActionsMenuItem> _filtered = [];
|
||||||
|
|
||||||
|
UserProfilePB? _user;
|
||||||
|
String? _workspaceId;
|
||||||
|
WorkspaceListener? _listener;
|
||||||
|
|
||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
_items = await _generatePageItems(currentViewId, viewLayout);
|
_items = await _generatePageItems(currentViewId, viewLayout);
|
||||||
_filtered = limitResults > 0 ? _items.take(limitResults).toList() : _items;
|
_filtered = limitResults > 0 ? _items.take(limitResults).toList() : _items;
|
||||||
|
|
||||||
|
await _initWorkspaceListener();
|
||||||
|
|
||||||
_initCompleter.complete();
|
_initCompleter.complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _initWorkspaceListener() async {
|
||||||
|
final snapshot = await Future.wait([
|
||||||
|
FolderEventGetCurrentWorkspaceSetting().send(),
|
||||||
|
getIt<AuthService>().getUser(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
final (workspaceSettings, userProfile) = (snapshot.first, snapshot.last);
|
||||||
|
_workspaceId = workspaceSettings.fold(
|
||||||
|
(s) => (s as WorkspaceSettingPB).workspaceId,
|
||||||
|
(e) => null,
|
||||||
|
);
|
||||||
|
|
||||||
|
_user = userProfile.fold((s) => s as UserProfilePB, (e) => null);
|
||||||
|
|
||||||
|
if (_user != null && _workspaceId != null) {
|
||||||
|
_listener = WorkspaceListener(
|
||||||
|
user: _user!,
|
||||||
|
workspaceId: _workspaceId!,
|
||||||
|
);
|
||||||
|
_listener!.start(
|
||||||
|
appsChanged: (_) async {
|
||||||
|
_items = await _generatePageItems(currentViewId, viewLayout);
|
||||||
|
_filtered =
|
||||||
|
limitResults > 0 ? _items.take(limitResults).toList() : _items;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<InlineActionsResult> search([
|
||||||
|
String? search,
|
||||||
|
]) async {
|
||||||
|
_filtered = await _filterItems(search);
|
||||||
|
|
||||||
|
return InlineActionsResult(
|
||||||
|
title: customTitle?.isNotEmpty == true
|
||||||
|
? customTitle!
|
||||||
|
: LocaleKeys.inlineActions_pageReference.tr(),
|
||||||
|
results: _filtered,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> dispose() async {
|
||||||
|
await _listener?.stop();
|
||||||
|
}
|
||||||
|
|
||||||
Future<List<InlineActionsMenuItem>> _filterItems(String? search) async {
|
Future<List<InlineActionsMenuItem>> _filterItems(String? search) async {
|
||||||
await _initCompleter.future;
|
await _initCompleter.future;
|
||||||
|
|
||||||
@ -76,19 +138,6 @@ class InlinePageReferenceService {
|
|||||||
: items.toList();
|
: items.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<InlineActionsResult> inlinePageReferenceDelegate([
|
|
||||||
String? search,
|
|
||||||
]) async {
|
|
||||||
_filtered = await _filterItems(search);
|
|
||||||
|
|
||||||
return InlineActionsResult(
|
|
||||||
title: customTitle?.isNotEmpty == true
|
|
||||||
? customTitle!
|
|
||||||
: LocaleKeys.inlineActions_pageReference.tr(),
|
|
||||||
results: _filtered,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<List<InlineActionsMenuItem>> _generatePageItems(
|
Future<List<InlineActionsMenuItem>> _generatePageItems(
|
||||||
String currentViewId,
|
String currentViewId,
|
||||||
ViewLayoutPB? viewLayout,
|
ViewLayoutPB? viewLayout,
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:appflowy/date/date_service.dart';
|
import 'package:appflowy/date/date_service.dart';
|
||||||
import 'package:appflowy/generated/locale_keys.g.dart';
|
import 'package:appflowy/generated/locale_keys.g.dart';
|
||||||
import 'package:appflowy/plugins/document/application/doc_bloc.dart';
|
import 'package:appflowy/plugins/document/application/doc_bloc.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/base/string_extension.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/base/string_extension.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/mention_block.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/mention_block.dart';
|
||||||
import 'package:appflowy/plugins/inline_actions/inline_actions_result.dart';
|
import 'package:appflowy/plugins/inline_actions/inline_actions_result.dart';
|
||||||
|
import 'package:appflowy/plugins/inline_actions/service_handler.dart';
|
||||||
import 'package:appflowy/user/application/reminder/reminder_bloc.dart';
|
import 'package:appflowy/user/application/reminder/reminder_bloc.dart';
|
||||||
import 'package:appflowy/user/application/reminder/reminder_extension.dart';
|
import 'package:appflowy/user/application/reminder/reminder_extension.dart';
|
||||||
import 'package:appflowy/workspace/presentation/widgets/date_picker/widgets/reminder_selector.dart';
|
import 'package:appflowy/workspace/presentation/widgets/date_picker/widgets/reminder_selector.dart';
|
||||||
@ -11,7 +14,6 @@ import 'package:appflowy_backend/protobuf/flowy-user/reminder.pb.dart';
|
|||||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:fixnum/fixnum.dart';
|
import 'package:fixnum/fixnum.dart';
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:nanoid/nanoid.dart';
|
import 'package:nanoid/nanoid.dart';
|
||||||
|
|
||||||
@ -20,7 +22,7 @@ final _keywords = [
|
|||||||
LocaleKeys.inlineActions_reminder_shortKeyword.tr().toLowerCase(),
|
LocaleKeys.inlineActions_reminder_shortKeyword.tr().toLowerCase(),
|
||||||
];
|
];
|
||||||
|
|
||||||
class ReminderReferenceService {
|
class ReminderReferenceService extends InlineActionsDelegate {
|
||||||
ReminderReferenceService(this.context) {
|
ReminderReferenceService(this.context) {
|
||||||
// Initialize locale
|
// Initialize locale
|
||||||
_locale = context.locale.toLanguageTag();
|
_locale = context.locale.toLanguageTag();
|
||||||
@ -36,7 +38,8 @@ class ReminderReferenceService {
|
|||||||
|
|
||||||
List<InlineActionsMenuItem> options = [];
|
List<InlineActionsMenuItem> options = [];
|
||||||
|
|
||||||
Future<InlineActionsResult> reminderReferenceDelegate([
|
@override
|
||||||
|
Future<InlineActionsResult> search([
|
||||||
String? search,
|
String? search,
|
||||||
]) async {
|
]) async {
|
||||||
// Checks if Locale has changed since last
|
// Checks if Locale has changed since last
|
||||||
|
@ -41,7 +41,7 @@ Future<bool> inlineActionsCommandHandler(
|
|||||||
|
|
||||||
final List<InlineActionsResult> initialResults = [];
|
final List<InlineActionsResult> initialResults = [];
|
||||||
for (final handler in service.handlers) {
|
for (final handler in service.handlers) {
|
||||||
final group = await handler();
|
final group = await handler.search(null);
|
||||||
|
|
||||||
if (group.results.isNotEmpty) {
|
if (group.results.isNotEmpty) {
|
||||||
initialResults.add(group);
|
initialResults.add(group);
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
import 'package:appflowy/plugins/inline_actions/inline_actions_result.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
typedef InlineActionsDelegate = Future<InlineActionsResult> Function([
|
import 'package:appflowy/plugins/inline_actions/service_handler.dart';
|
||||||
String? search,
|
|
||||||
]);
|
|
||||||
|
|
||||||
abstract class _InlineActionsProvider {
|
abstract class _InlineActionsProvider {
|
||||||
void dispose();
|
void dispose();
|
||||||
@ -26,7 +23,10 @@ class InlineActionsService extends _InlineActionsProvider {
|
|||||||
/// we set the [BuildContext] to null.
|
/// we set the [BuildContext] to null.
|
||||||
///
|
///
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
Future<void> dispose() async {
|
||||||
|
for (final handler in handlers) {
|
||||||
|
await handler.dispose();
|
||||||
|
}
|
||||||
context = null;
|
context = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
import 'package:appflowy/plugins/inline_actions/inline_actions_result.dart';
|
||||||
|
|
||||||
|
abstract class InlineActionsDelegate {
|
||||||
|
Future<InlineActionsResult> search(String? search);
|
||||||
|
|
||||||
|
Future<void> dispose() async {}
|
||||||
|
}
|
@ -92,7 +92,7 @@ class _InlineActionsHandlerState extends State<InlineActionsHandler> {
|
|||||||
Future<void> _doSearch() async {
|
Future<void> _doSearch() async {
|
||||||
final List<InlineActionsResult> newResults = [];
|
final List<InlineActionsResult> newResults = [];
|
||||||
for (final handler in widget.service.handlers) {
|
for (final handler in widget.service.handlers) {
|
||||||
final group = await handler.call(_search);
|
final group = await handler.search(_search);
|
||||||
|
|
||||||
if (group.results.isNotEmpty) {
|
if (group.results.isNotEmpty) {
|
||||||
newResults.add(group);
|
newResults.add(group);
|
||||||
|
@ -27,7 +27,8 @@ use crate::entities::{
|
|||||||
UpdateViewParams, ViewPB, WorkspacePB, WorkspaceSettingPB,
|
UpdateViewParams, ViewPB, WorkspacePB, WorkspaceSettingPB,
|
||||||
};
|
};
|
||||||
use crate::manager_observer::{
|
use crate::manager_observer::{
|
||||||
notify_child_views_changed, notify_parent_view_did_change, ChildViewChangeReason,
|
notify_child_views_changed, notify_did_update_workspace, notify_parent_view_did_change,
|
||||||
|
ChildViewChangeReason,
|
||||||
};
|
};
|
||||||
use crate::notification::{
|
use crate::notification::{
|
||||||
send_notification, send_workspace_setting_notification, FolderNotification,
|
send_notification, send_workspace_setting_notification, FolderNotification,
|
||||||
@ -991,7 +992,15 @@ impl FolderManager {
|
|||||||
send_notification(&view_pb.id, FolderNotification::DidUpdateView)
|
send_notification(&view_pb.id, FolderNotification::DidUpdateView)
|
||||||
.payload(view_pb)
|
.payload(view_pb)
|
||||||
.send();
|
.send();
|
||||||
|
|
||||||
|
if let Ok(workspace_id) = self.get_current_workspace_id().await {
|
||||||
|
let folder = &self.mutex_folder.lock();
|
||||||
|
if let Some(folder) = folder.as_ref() {
|
||||||
|
notify_did_update_workspace(&workspace_id, folder);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user