mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: insert reference page in nested page
This commit is contained in:
@ -234,13 +234,19 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
|
||||
),
|
||||
),
|
||||
DatabaseBlockKeys.gridType: DatabaseViewBlockComponentBuilder(
|
||||
configuration: configuration,
|
||||
configuration: configuration.copyWith(
|
||||
padding: (_) => const EdgeInsets.symmetric(vertical: 10),
|
||||
),
|
||||
),
|
||||
DatabaseBlockKeys.boardType: DatabaseViewBlockComponentBuilder(
|
||||
configuration: configuration,
|
||||
configuration: configuration.copyWith(
|
||||
padding: (_) => const EdgeInsets.symmetric(vertical: 10),
|
||||
),
|
||||
),
|
||||
DatabaseBlockKeys.calendarType: DatabaseViewBlockComponentBuilder(
|
||||
configuration: configuration,
|
||||
configuration: configuration.copyWith(
|
||||
padding: (_) => const EdgeInsets.symmetric(vertical: 10),
|
||||
),
|
||||
),
|
||||
CalloutBlockKeys.type: CalloutBlockComponentBuilder(
|
||||
configuration: configuration,
|
||||
|
@ -82,23 +82,16 @@ class _LinkToPageMenuState extends State<LinkToPageMenu> {
|
||||
final _focusNode = FocusNode(debugLabel: 'reference_list_widget');
|
||||
EditorStyle get style => widget.editorState.editorStyle;
|
||||
int _selectedIndex = 0;
|
||||
int _totalItems = 0;
|
||||
Future<List<(ViewPB, List<ViewPB>)>>? _availableLayout;
|
||||
final Map<int, (ViewPB, ViewPB)> _items = {};
|
||||
final int _totalItems = 0;
|
||||
Future<List<ViewPB>>? _availableLayout;
|
||||
final List<ViewPB> _items = [];
|
||||
|
||||
Future<List<(ViewPB, List<ViewPB>)>> fetchItems() async {
|
||||
Future<List<ViewPB>> fetchItems() async {
|
||||
final items =
|
||||
await ViewBackendService().fetchViewsWithLayoutType(widget.layoutType);
|
||||
|
||||
int index = 0;
|
||||
for (final (app, children) in items) {
|
||||
for (final view in children) {
|
||||
_items.putIfAbsent(index, () => (app, view));
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
|
||||
_totalItems = _items.length;
|
||||
_items
|
||||
..clear()
|
||||
..addAll(items);
|
||||
return items;
|
||||
}
|
||||
|
||||
@ -176,8 +169,8 @@ class _LinkToPageMenuState extends State<LinkToPageMenu> {
|
||||
newSelectedIndex %= _totalItems;
|
||||
} else if (event.logicalKey == LogicalKeyboardKey.enter) {
|
||||
widget.onSelected(
|
||||
_items[_selectedIndex]!.$1,
|
||||
_items[_selectedIndex]!.$2,
|
||||
_items[_selectedIndex],
|
||||
_items[_selectedIndex],
|
||||
);
|
||||
}
|
||||
|
||||
@ -191,10 +184,10 @@ class _LinkToPageMenuState extends State<LinkToPageMenu> {
|
||||
Widget _buildListWidget(
|
||||
BuildContext context,
|
||||
int selectedIndex,
|
||||
Future<List<(ViewPB, List<ViewPB>)>>? items,
|
||||
Future<List<ViewPB>>? items,
|
||||
) {
|
||||
int index = 0;
|
||||
return FutureBuilder<List<(ViewPB, List<ViewPB>)>>(
|
||||
return FutureBuilder<List<ViewPB>>(
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData &&
|
||||
snapshot.connectionState == ConnectionState.done) {
|
||||
@ -211,35 +204,23 @@ class _LinkToPageMenuState extends State<LinkToPageMenu> {
|
||||
];
|
||||
|
||||
if (views != null && views.isNotEmpty) {
|
||||
for (final (view, viewChildren) in views) {
|
||||
if (viewChildren.isNotEmpty) {
|
||||
children.add(
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||
child: FlowyText.regular(
|
||||
view.name,
|
||||
),
|
||||
for (final view in views) {
|
||||
children.add(
|
||||
FlowyButton(
|
||||
isSelected: index == _selectedIndex,
|
||||
leftIcon: svgWidget(
|
||||
view.iconName,
|
||||
color: Theme.of(context).iconTheme.color,
|
||||
),
|
||||
);
|
||||
text: FlowyText.regular(view.name),
|
||||
onTap: () => widget.onSelected(view, view),
|
||||
),
|
||||
);
|
||||
|
||||
for (final value in viewChildren) {
|
||||
children.add(
|
||||
FlowyButton(
|
||||
isSelected: index == _selectedIndex,
|
||||
leftIcon: svgWidget(
|
||||
value.iconName,
|
||||
color: Theme.of(context).iconTheme.color,
|
||||
),
|
||||
text: FlowyText.regular(value.name),
|
||||
onTap: () => widget.onSelected(view, value),
|
||||
),
|
||||
);
|
||||
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: children,
|
||||
|
@ -82,6 +82,11 @@ class _DatabaseBlockComponentWidgetState
|
||||
},
|
||||
);
|
||||
|
||||
child = Padding(
|
||||
padding: padding,
|
||||
child: child,
|
||||
);
|
||||
|
||||
if (widget.actionBuilder != null) {
|
||||
child = BlockComponentActionWrapper(
|
||||
node: widget.node,
|
||||
|
@ -17,11 +17,8 @@ SelectionMenuItem inlineGridMenuItem(DocumentBloc documentBloc) =>
|
||||
),
|
||||
keywords: ['grid', 'database'],
|
||||
handler: (editorState, menuService, context) async {
|
||||
if (!documentBloc.view.hasParentViewId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final parentViewId = documentBloc.view.parentViewId;
|
||||
// create the view inside current page
|
||||
final parentViewId = documentBloc.view.id;
|
||||
ViewBackendService.createView(
|
||||
parentViewId: parentViewId,
|
||||
openAfterCreate: false,
|
||||
@ -45,11 +42,8 @@ SelectionMenuItem inlineBoardMenuItem(DocumentBloc documentBloc) =>
|
||||
),
|
||||
keywords: ['board', 'kanban', 'database'],
|
||||
handler: (editorState, menuService, context) async {
|
||||
if (!documentBloc.view.hasParentViewId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final parentViewId = documentBloc.view.parentViewId;
|
||||
// create the view inside current page
|
||||
final parentViewId = documentBloc.view.id;
|
||||
ViewBackendService.createView(
|
||||
parentViewId: parentViewId,
|
||||
name: LocaleKeys.menuAppHeader_defaultNewPageName.tr(),
|
||||
@ -72,11 +66,8 @@ SelectionMenuItem inlineCalendarMenuItem(DocumentBloc documentBloc) =>
|
||||
),
|
||||
keywords: ['calendar', 'database'],
|
||||
handler: (editorState, menuService, context) async {
|
||||
if (!documentBloc.view.hasParentViewId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final parentViewId = documentBloc.view.parentViewId;
|
||||
// create the view inside current page
|
||||
final parentViewId = documentBloc.view.id;
|
||||
ViewBackendService.createView(
|
||||
parentViewId: parentViewId,
|
||||
name: LocaleKeys.menuAppHeader_defaultNewPageName.tr(),
|
||||
|
@ -2,7 +2,6 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selec
|
||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/mention_page_block.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-folder2/view.pb.dart';
|
||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
|
||||
enum MentionType {
|
||||
@ -98,17 +97,11 @@ class InlinePageReferenceService {
|
||||
|
||||
Future<List<SelectionMenuItem>> generatePageItems(String character) async {
|
||||
final service = ViewBackendService();
|
||||
final List<(ViewPB, List<ViewPB>)> pbViews = await service.fetchViews(
|
||||
(_, __) => true,
|
||||
);
|
||||
if (pbViews.isEmpty) {
|
||||
final views = await service.fetchViews();
|
||||
if (views.isEmpty) {
|
||||
return [];
|
||||
}
|
||||
final List<SelectionMenuItem> pages = [];
|
||||
final List<ViewPB> views = [];
|
||||
for (final element in pbViews) {
|
||||
views.addAll(element.$2);
|
||||
}
|
||||
views.sort(((a, b) => b.createTime.compareTo(a.createTime)));
|
||||
|
||||
for (final view in views) {
|
||||
|
Reference in New Issue
Block a user