Skip to content

Commit 37f85ce

Browse files
committed
chore: open next page when current page get deleted
1 parent bdf4e60 commit 37f85ce

File tree

25 files changed

+312
-178
lines changed

25 files changed

+312
-178
lines changed

frontend/app_flowy/lib/plugins/blank/blank.dart

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'package:app_flowy/startup/plugin/plugin.dart';
99
class BlankPluginBuilder extends PluginBuilder {
1010
@override
1111
Plugin build(dynamic data) {
12-
return BlankPagePlugin(pluginType: pluginType);
12+
return BlankPagePlugin();
1313
}
1414

1515
@override
@@ -25,19 +25,14 @@ class BlankPluginConfig implements PluginConfig {
2525
}
2626

2727
class BlankPagePlugin extends Plugin {
28-
final PluginType _pluginType;
29-
BlankPagePlugin({
30-
required PluginType pluginType,
31-
}) : _pluginType = pluginType;
32-
3328
@override
3429
PluginDisplay get display => BlankPagePluginDisplay();
3530

3631
@override
3732
PluginId get id => "BlankStack";
3833

3934
@override
40-
PluginType get ty => _pluginType;
35+
PluginType get ty => PluginType.blank;
4136
}
4237

4338
class BlankPagePluginDisplay extends PluginDisplay with NavigationItem {
@@ -46,7 +41,7 @@ class BlankPagePluginDisplay extends PluginDisplay with NavigationItem {
4641
FlowyText.medium(LocaleKeys.blankPageTitle.tr(), fontSize: 12);
4742

4843
@override
49-
Widget buildWidget() => const BlankPage();
44+
Widget buildWidget(PluginContext context) => const BlankPage();
5045

5146
@override
5247
List<NavigationItem> get navigationItems => [this];

frontend/app_flowy/lib/plugins/board/board.dart

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:app_flowy/plugins/util.dart';
12
import 'package:app_flowy/workspace/presentation/home/home_stack.dart';
23
import 'package:app_flowy/workspace/presentation/widgets/left_bar_item.dart';
34
import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart';
@@ -35,34 +36,45 @@ class BoardPluginConfig implements PluginConfig {
3536
}
3637

3738
class BoardPlugin extends Plugin {
38-
final ViewPB _view;
39+
@override
40+
final ViewPluginNotifier notifier;
3941
final PluginType _pluginType;
4042

4143
BoardPlugin({
4244
required ViewPB view,
4345
required PluginType pluginType,
4446
}) : _pluginType = pluginType,
45-
_view = view;
47+
notifier = ViewPluginNotifier(view: view);
4648

4749
@override
48-
PluginDisplay get display => GridPluginDisplay(view: _view);
50+
PluginDisplay get display => GridPluginDisplay(notifier: notifier);
4951

5052
@override
51-
PluginId get id => _view.id;
53+
PluginId get id => notifier.view.id;
5254

5355
@override
5456
PluginType get ty => _pluginType;
5557
}
5658

5759
class GridPluginDisplay extends PluginDisplay {
58-
final ViewPB _view;
59-
GridPluginDisplay({required ViewPB view, Key? key}) : _view = view;
60+
final ViewPluginNotifier notifier;
61+
GridPluginDisplay({required this.notifier, Key? key});
62+
63+
ViewPB get view => notifier.view;
6064

6165
@override
62-
Widget get leftBarItem => ViewLeftBarItem(view: _view);
66+
Widget get leftBarItem => ViewLeftBarItem(view: view);
6367

6468
@override
65-
Widget buildWidget() => BoardPage(view: _view);
69+
Widget buildWidget(PluginContext context) {
70+
notifier.isDeleted.addListener(() {
71+
if (notifier.isDeleted.value) {
72+
context.onDeleted(view);
73+
}
74+
});
75+
76+
return BoardPage(key: ValueKey(view.id), view: view);
77+
}
6678

6779
@override
6880
List<NavigationItem> get navigationItems => [this];

frontend/app_flowy/lib/plugins/board/presentation/board_page.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ import 'toolbar/board_toolbar.dart';
3131

3232
class BoardPage extends StatelessWidget {
3333
final ViewPB view;
34-
BoardPage({required this.view, Key? key}) : super(key: ValueKey(view.id));
34+
BoardPage({
35+
required this.view,
36+
Key? key,
37+
}) : super(key: ValueKey(view.id));
3538

3639
@override
3740
Widget build(BuildContext context) {

frontend/app_flowy/lib/plugins/doc/document.dart

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
library document_plugin;
22

33
import 'package:app_flowy/generated/locale_keys.g.dart';
4+
import 'package:app_flowy/plugins/util.dart';
45
import 'package:app_flowy/startup/plugin/plugin.dart';
56
import 'package:app_flowy/startup/startup.dart';
67
import 'package:app_flowy/workspace/application/appearance.dart';
7-
import 'package:app_flowy/workspace/application/view/view_listener.dart';
88
import 'package:app_flowy/plugins/doc/application/share_bloc.dart';
99
import 'package:app_flowy/workspace/presentation/home/home_stack.dart';
1010
import 'package:app_flowy/workspace/presentation/home/toast.dart';
@@ -14,7 +14,6 @@ import 'package:app_flowy/workspace/presentation/widgets/pop_up_action.dart';
1414
import 'package:clipboard/clipboard.dart';
1515
import 'package:dartz/dartz.dart' as dartz;
1616
import 'package:easy_localization/easy_localization.dart';
17-
import 'package:flowy_infra/notifier.dart';
1817
import 'package:flowy_infra/size.dart';
1918
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
2019
import 'package:flowy_infra_ui/widget/rounded_button.dart';
@@ -48,63 +47,51 @@ class DocumentPluginBuilder extends PluginBuilder {
4847
ViewDataTypePB get dataType => ViewDataTypePB.Text;
4948
}
5049

51-
class DocumentPlugin implements Plugin {
52-
late ViewPB _view;
53-
ViewListener? _listener;
50+
class DocumentPlugin extends Plugin<int> {
5451
late PluginType _pluginType;
5552

56-
DocumentPlugin(
57-
{required PluginType pluginType, required ViewPB view, Key? key})
58-
: _view = view {
59-
_pluginType = pluginType;
60-
_listener = getIt<ViewListener>(param1: view);
61-
_listener?.start(onViewUpdated: (result) {
62-
result.fold(
63-
(newView) {
64-
_view = newView;
65-
display.notifier!.value = _view.hashCode;
66-
},
67-
(error) {},
68-
);
69-
});
70-
}
71-
7253
@override
73-
void dispose() {
74-
_listener?.stop();
75-
_listener = null;
54+
final ViewPluginNotifier notifier;
55+
56+
DocumentPlugin({
57+
required PluginType pluginType,
58+
required ViewPB view,
59+
Key? key,
60+
}) : notifier = ViewPluginNotifier(view: view) {
61+
_pluginType = pluginType;
7662
}
7763

7864
@override
79-
PluginDisplay<int> get display => DocumentPluginDisplay(view: _view);
65+
PluginDisplay get display => DocumentPluginDisplay(notifier: notifier);
8066

8167
@override
8268
PluginType get ty => _pluginType;
8369

8470
@override
85-
PluginId get id => _view.id;
71+
PluginId get id => notifier.view.id;
8672
}
8773

88-
class DocumentPluginDisplay extends PluginDisplay<int> with NavigationItem {
89-
final PublishNotifier<int> _displayNotifier = PublishNotifier<int>();
90-
final ViewPB _view;
74+
class DocumentPluginDisplay extends PluginDisplay with NavigationItem {
75+
final ViewPluginNotifier notifier;
76+
ViewPB get view => notifier.view;
9177

92-
DocumentPluginDisplay({required ViewPB view, Key? key}) : _view = view;
78+
DocumentPluginDisplay({required this.notifier, Key? key});
9379

9480
@override
95-
Widget buildWidget() => DocumentPage(view: _view, key: ValueKey(_view.id));
81+
Widget buildWidget(PluginContext context) => DocumentPage(
82+
view: view,
83+
onDeleted: () => context.onDeleted(view),
84+
key: ValueKey(view.id),
85+
);
9686

9787
@override
98-
Widget get leftBarItem => ViewLeftBarItem(view: _view);
88+
Widget get leftBarItem => ViewLeftBarItem(view: view);
9989

10090
@override
101-
Widget? get rightBarItem => DocumentShareButton(view: _view);
91+
Widget? get rightBarItem => DocumentShareButton(view: view);
10292

10393
@override
10494
List<NavigationItem> get navigationItems => [this];
105-
106-
@override
107-
PublishNotifier<int>? get notifier => _displayNotifier;
10895
}
10996

11097
class DocumentShareButton extends StatelessWidget {

frontend/app_flowy/lib/plugins/doc/document_page.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@ import 'application/doc_bloc.dart';
1414
import 'styles.dart';
1515

1616
class DocumentPage extends StatefulWidget {
17+
final VoidCallback onDeleted;
1718
final ViewPB view;
1819

19-
DocumentPage({Key? key, required this.view}) : super(key: ValueKey(view.id));
20+
DocumentPage({
21+
required this.view,
22+
required this.onDeleted,
23+
Key? key,
24+
}) : super(key: ValueKey(view.id));
2025

2126
@override
2227
State<DocumentPage> createState() => _DocumentPageState();
@@ -49,7 +54,8 @@ class _DocumentPageState extends State<DocumentPage> {
4954
finish: (result) => result.successOrFail.fold(
5055
(_) {
5156
if (state.forceClose) {
52-
return _renderAppPage();
57+
widget.onDeleted();
58+
return const SizedBox();
5359
} else {
5460
return _renderDocument(context, state);
5561
}
@@ -134,10 +140,4 @@ class _DocumentPageState extends State<DocumentPage> {
134140
),
135141
);
136142
}
137-
138-
Widget _renderAppPage() {
139-
return Container(
140-
color: Colors.black,
141-
);
142-
}
143143
}

frontend/app_flowy/lib/plugins/grid/grid.dart

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:app_flowy/generated/locale_keys.g.dart';
2+
import 'package:app_flowy/plugins/util.dart';
23
import 'package:app_flowy/startup/plugin/plugin.dart';
34
import 'package:app_flowy/workspace/presentation/home/home_stack.dart';
45
import 'package:app_flowy/workspace/presentation/widgets/left_bar_item.dart';
@@ -37,34 +38,45 @@ class GridPluginConfig implements PluginConfig {
3738
}
3839

3940
class GridPlugin extends Plugin {
40-
final ViewPB _view;
41+
@override
42+
final ViewPluginNotifier notifier;
4143
final PluginType _pluginType;
4244

4345
GridPlugin({
4446
required ViewPB view,
4547
required PluginType pluginType,
4648
}) : _pluginType = pluginType,
47-
_view = view;
49+
notifier = ViewPluginNotifier(view: view);
4850

4951
@override
50-
PluginDisplay get display => GridPluginDisplay(view: _view);
52+
PluginDisplay get display => GridPluginDisplay(notifier: notifier);
5153

5254
@override
53-
PluginId get id => _view.id;
55+
PluginId get id => notifier.view.id;
5456

5557
@override
5658
PluginType get ty => _pluginType;
5759
}
5860

5961
class GridPluginDisplay extends PluginDisplay {
60-
final ViewPB _view;
61-
GridPluginDisplay({required ViewPB view, Key? key}) : _view = view;
62+
final ViewPluginNotifier notifier;
63+
ViewPB get view => notifier.view;
64+
65+
GridPluginDisplay({required this.notifier, Key? key});
6266

6367
@override
64-
Widget get leftBarItem => ViewLeftBarItem(view: _view);
68+
Widget get leftBarItem => ViewLeftBarItem(view: view);
6569

6670
@override
67-
Widget buildWidget() => GridPage(view: _view);
71+
Widget buildWidget(PluginContext context) {
72+
notifier.isDeleted.addListener(() {
73+
if (notifier.isDeleted.value) {
74+
context.onDeleted(view);
75+
}
76+
});
77+
78+
return GridPage(key: ValueKey(view.id), view: view);
79+
}
6880

6981
@override
7082
List<NavigationItem> get navigationItems => [this];

frontend/app_flowy/lib/plugins/grid/presentation/grid_page.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@ import 'widgets/toolbar/grid_toolbar.dart';
2929

3030
class GridPage extends StatefulWidget {
3131
final ViewPB view;
32+
final VoidCallback? onDeleted;
3233

33-
GridPage({Key? key, required this.view}) : super(key: ValueKey(view.id));
34+
GridPage({
35+
required this.view,
36+
this.onDeleted,
37+
Key? key,
38+
}) : super(key: ValueKey(view.id));
3439

3540
@override
3641
State<GridPage> createState() => _GridPageState();

frontend/app_flowy/lib/plugins/trash/trash.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ class TrashPluginDisplay extends PluginDisplay {
6666
Widget? get rightBarItem => null;
6767

6868
@override
69-
Widget buildWidget() => const TrashPage(key: ValueKey('TrashPage'));
69+
Widget buildWidget(PluginContext context) => const TrashPage(
70+
key: ValueKey('TrashPage'),
71+
);
7072

7173
@override
7274
List<NavigationItem> get navigationItems => [this];
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import 'package:app_flowy/startup/plugin/plugin.dart';
2+
import 'package:app_flowy/workspace/application/view/view_listener.dart';
3+
import 'package:flowy_sdk/log.dart';
4+
import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart';
5+
import 'package:flutter/material.dart';
6+
7+
class ViewPluginNotifier extends PluginNotifier {
8+
final ViewListener? _viewListener;
9+
ViewPB view;
10+
11+
@override
12+
final ValueNotifier<bool> isDeleted = ValueNotifier(false);
13+
14+
@override
15+
final ValueNotifier<int> isDisplayChanged = ValueNotifier(0);
16+
17+
ViewPluginNotifier({
18+
required this.view,
19+
}) : _viewListener = ViewListener(view: view) {
20+
_viewListener?.start(onViewUpdated: (result) {
21+
result.fold(
22+
(updatedView) {
23+
view = updatedView;
24+
isDisplayChanged.value = updatedView.hashCode;
25+
},
26+
(err) => Log.error(err),
27+
);
28+
}, onViewMoveToTrash: (result) {
29+
result.fold(
30+
(deletedView) {
31+
isDeleted.value = true;
32+
},
33+
(err) => Log.error(err),
34+
);
35+
});
36+
}
37+
38+
@override
39+
void dispose() {
40+
isDeleted.dispose();
41+
isDisplayChanged.dispose();
42+
_viewListener?.stop();
43+
}
44+
}

frontend/app_flowy/lib/startup/deps_resolver.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void _resolveFolderDeps(GetIt getIt) {
120120
getIt.registerFactoryParam<AppBloc, AppPB, void>(
121121
(app, _) => AppBloc(
122122
app: app,
123-
appService: AppService(appId: app.id),
123+
appService: AppService(),
124124
appListener: AppListener(appId: app.id),
125125
),
126126
);

0 commit comments

Comments
 (0)