fix: open latest after deleting current view

This commit is contained in:
appflowy
2022-09-26 16:59:58 +08:00
parent 81ecbd8ae2
commit e3a1384f7f
11 changed files with 82 additions and 37 deletions

View File

@ -68,9 +68,11 @@ class GridPluginDisplay extends PluginDisplay {
@override
Widget buildWidget(PluginContext context) {
notifier.isDeleted.addListener(() {
if (notifier.isDeleted.value) {
context.onDeleted(view);
}
notifier.isDeleted.value.fold(() => null, (deletedView) {
if (deletedView.hasIndex()) {
context.onDeleted(view, deletedView.index);
}
});
});
return BoardPage(key: ValueKey(view.id), view: view);

View File

@ -74,15 +74,26 @@ class DocumentPlugin extends Plugin<int> {
class DocumentPluginDisplay extends PluginDisplay with NavigationItem {
final ViewPluginNotifier notifier;
ViewPB get view => notifier.view;
int? deletedViewIndex;
DocumentPluginDisplay({required this.notifier, Key? key});
@override
Widget buildWidget(PluginContext context) => DocumentPage(
view: view,
onDeleted: () => context.onDeleted(view),
key: ValueKey(view.id),
);
Widget buildWidget(PluginContext context) {
notifier.isDeleted.addListener(() {
notifier.isDeleted.value.fold(() => null, (deletedView) {
if (deletedView.hasIndex()) {
deletedViewIndex = deletedView.index;
}
});
});
return DocumentPage(
view: view,
onDeleted: () => context.onDeleted(view, deletedViewIndex),
key: ValueKey(view.id),
);
}
@override
Widget get leftBarItem => ViewLeftBarItem(view: view);

View File

@ -70,9 +70,11 @@ class GridPluginDisplay extends PluginDisplay {
@override
Widget buildWidget(PluginContext context) {
notifier.isDeleted.addListener(() {
if (notifier.isDeleted.value) {
context.onDeleted(view);
}
notifier.isDeleted.value.fold(() => null, (deletedView) {
if (deletedView.hasIndex()) {
context.onDeleted(view, deletedView.index);
}
});
});
return GridPage(key: ValueKey(view.id), view: view);

View File

@ -1,15 +1,16 @@
import 'package:app_flowy/startup/plugin/plugin.dart';
import 'package:app_flowy/workspace/application/view/view_listener.dart';
import 'package:dartz/dartz.dart';
import 'package:flowy_sdk/log.dart';
import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart';
import 'package:flutter/material.dart';
class ViewPluginNotifier extends PluginNotifier {
class ViewPluginNotifier extends PluginNotifier<Option<DeletedViewPB>> {
final ViewListener? _viewListener;
ViewPB view;
@override
final ValueNotifier<bool> isDeleted = ValueNotifier(false);
final ValueNotifier<Option<DeletedViewPB>> isDeleted = ValueNotifier(none());
@override
final ValueNotifier<int> isDisplayChanged = ValueNotifier(0);
@ -27,9 +28,7 @@ class ViewPluginNotifier extends PluginNotifier {
);
}, onViewMoveToTrash: (result) {
result.fold(
(deletedView) {
isDeleted.value = true;
},
(deletedView) => isDeleted.value = some(deletedView),
(err) => Log.error(err),
);
});