Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: no banner to restore or delete permanently appears #3646

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions frontend/appflowy_flutter/lib/plugins/banner.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/size.dart';
import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flowy_infra_ui/widget/buttons/base_styled_button.dart';
import 'package:flowy_infra_ui/widget/spacing.dart';
import 'package:flutter/material.dart';
import 'package:appflowy/generated/locale_keys.g.dart';

class OnDeleteBanner extends StatelessWidget {
final void Function() onRestore;
final void Function() onDelete;
const OnDeleteBanner({

Check warning on line 12 in frontend/appflowy_flutter/lib/plugins/banner.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/banner.dart#L12

Added line #L12 was not covered by tests
required this.onRestore,
required this.onDelete,
Key? key,
}) : super(key: key);

Check warning on line 16 in frontend/appflowy_flutter/lib/plugins/banner.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/banner.dart#L16

Added line #L16 was not covered by tests

@override

Check warning on line 18 in frontend/appflowy_flutter/lib/plugins/banner.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/banner.dart#L18

Added line #L18 was not covered by tests
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
return ConstrainedBox(

Check warning on line 21 in frontend/appflowy_flutter/lib/plugins/banner.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/banner.dart#L20-L21

Added lines #L20 - L21 were not covered by tests
constraints: const BoxConstraints(minHeight: 60),
child: Container(

Check warning on line 23 in frontend/appflowy_flutter/lib/plugins/banner.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/banner.dart#L23

Added line #L23 was not covered by tests
width: double.infinity,
color: colorScheme.error,
child: FittedBox(

Check warning on line 26 in frontend/appflowy_flutter/lib/plugins/banner.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/banner.dart#L25-L26

Added lines #L25 - L26 were not covered by tests
alignment: Alignment.center,
fit: BoxFit.scaleDown,
child: Row(
children: [
FlowyText.medium(
LocaleKeys.deletePagePrompt_text.tr(),
color: colorScheme.onError,

Check warning on line 33 in frontend/appflowy_flutter/lib/plugins/banner.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/banner.dart#L29-L33

Added lines #L29 - L33 were not covered by tests
fontSize: 14,
),
const HSpace(20),
BaseStyledButton(

Check warning on line 37 in frontend/appflowy_flutter/lib/plugins/banner.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/banner.dart#L37

Added line #L37 was not covered by tests
minWidth: 160,
minHeight: 40,
contentPadding: EdgeInsets.zero,
bgColor: Colors.transparent,
highlightColor: Theme.of(context).colorScheme.primaryContainer,
outlineColor: colorScheme.onError,

Check warning on line 43 in frontend/appflowy_flutter/lib/plugins/banner.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/banner.dart#L42-L43

Added lines #L42 - L43 were not covered by tests
borderRadius: Corners.s8Border,
onPressed: onRestore,
child: FlowyText.medium(
LocaleKeys.deletePagePrompt_restore.tr(),
color: colorScheme.onError,

Check warning on line 48 in frontend/appflowy_flutter/lib/plugins/banner.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/banner.dart#L45-L48

Added lines #L45 - L48 were not covered by tests
fontSize: 13,
),
),
const HSpace(20),
BaseStyledButton(

Check warning on line 53 in frontend/appflowy_flutter/lib/plugins/banner.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/banner.dart#L53

Added line #L53 was not covered by tests
minWidth: 220,
minHeight: 40,
contentPadding: EdgeInsets.zero,
bgColor: Colors.transparent,
highlightColor: Theme.of(context).colorScheme.primary,
outlineColor: colorScheme.onError,

Check warning on line 59 in frontend/appflowy_flutter/lib/plugins/banner.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/banner.dart#L58-L59

Added lines #L58 - L59 were not covered by tests
borderRadius: Corners.s8Border,
onPressed: onDelete,
child: FlowyText.medium(
LocaleKeys.deletePagePrompt_deletePermanent.tr(),
color: colorScheme.onError,

Check warning on line 64 in frontend/appflowy_flutter/lib/plugins/banner.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/banner.dart#L61-L64

Added lines #L61 - L64 were not covered by tests
fontSize: 13,
),
),
],
),
),
),
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:appflowy/plugins/database_view/tar_bar/tab_bar_view.dart';
import 'package:appflowy/plugins/database_view/tar_bar/tar_bar_add_button.dart';
import 'package:appflowy/plugins/trash/application/trash_service.dart';
import 'package:appflowy/workspace/application/view/prelude.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy_backend/log.dart';
Expand All @@ -14,17 +15,38 @@
part 'tar_bar_bloc.freezed.dart';

class GridTabBarBloc extends Bloc<GridTabBarEvent, GridTabBarState> {
final TrashService _trashService;
final ViewListener _viewListener;

GridTabBarBloc({
bool isInlineView = false,
required ViewPB view,
}) : super(GridTabBarState.initial(view)) {
}) : _trashService = TrashService(),
_viewListener = ViewListener(viewId: view.id),
super(GridTabBarState.initial(view)) {

Check warning on line 26 in frontend/appflowy_flutter/lib/plugins/database_view/application/tar_bar_bloc.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/database_view/application/tar_bar_bloc.dart#L24-L26

Added lines #L24 - L26 were not covered by tests
on<GridTabBarEvent>(
(event, emit) async {
event.when(
await event.when(

Check warning on line 29 in frontend/appflowy_flutter/lib/plugins/database_view/application/tar_bar_bloc.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/database_view/application/tar_bar_bloc.dart#L29

Added line #L29 was not covered by tests
initial: () {
_listenInlineViewChanged();
_loadChildView();
},
moveToTrash: () async {
emit(state.copyWith(isDeleted: true));

Check warning on line 35 in frontend/appflowy_flutter/lib/plugins/database_view/application/tar_bar_bloc.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/database_view/application/tar_bar_bloc.dart#L34-L35

Added lines #L34 - L35 were not covered by tests
},
restore: () async {
emit(state.copyWith(isDeleted: false));

Check warning on line 38 in frontend/appflowy_flutter/lib/plugins/database_view/application/tar_bar_bloc.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/database_view/application/tar_bar_bloc.dart#L37-L38

Added lines #L37 - L38 were not covered by tests
},
deletePermanently: () async {
final result = await _trashService.deleteViews([view.id]);
final forceClose = result.fold((l) => true, (r) => false);
emit(state.copyWith(forceClose: forceClose));

Check warning on line 43 in frontend/appflowy_flutter/lib/plugins/database_view/application/tar_bar_bloc.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/database_view/application/tar_bar_bloc.dart#L40-L43

Added lines #L40 - L43 were not covered by tests
},
restorePage: () async {
final result = await _trashService.putback(view.id);
final isDeleted = result.fold((l) => false, (r) => true);
emit(state.copyWith(isDeleted: isDeleted));

Check warning on line 48 in frontend/appflowy_flutter/lib/plugins/database_view/application/tar_bar_bloc.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/database_view/application/tar_bar_bloc.dart#L45-L48

Added lines #L45 - L48 were not covered by tests
},
didLoadChildViews: (List<ViewPB> childViews) {
emit(
state.copyWith(
Expand Down Expand Up @@ -130,6 +152,7 @@
for (final tabBar in state.tabBars) {
await state.tabBarControllerByViewId[tabBar.viewId]?.dispose();
}
await _viewListener.stop();

Check warning on line 155 in frontend/appflowy_flutter/lib/plugins/database_view/application/tar_bar_bloc.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/database_view/application/tar_bar_bloc.dart#L155

Added line #L155 was not covered by tests
return super.close();
}

Expand All @@ -143,6 +166,17 @@
controller?.onViewChildViewChanged = (update) {
add(GridTabBarEvent.didUpdateChildViews(update));
};

_viewListener.start(
onViewMoveToTrash: (r) {
r.swap().map((r) => add(const GridTabBarEvent.moveToTrash()));

Check warning on line 172 in frontend/appflowy_flutter/lib/plugins/database_view/application/tar_bar_bloc.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/database_view/application/tar_bar_bloc.dart#L170-L172

Added lines #L170 - L172 were not covered by tests
},
onViewDeleted: (r) {
r.swap().map((r) => add(const GridTabBarEvent.moveToTrash()));

Check warning on line 175 in frontend/appflowy_flutter/lib/plugins/database_view/application/tar_bar_bloc.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/database_view/application/tar_bar_bloc.dart#L174-L175

Added lines #L174 - L175 were not covered by tests
},
onViewRestored: (r) =>
r.swap().map((r) => add(const GridTabBarEvent.restore())),

Check warning on line 178 in frontend/appflowy_flutter/lib/plugins/database_view/application/tar_bar_bloc.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/database_view/application/tar_bar_bloc.dart#L177-L178

Added lines #L177 - L178 were not covered by tests
);
}

/// Create tab bar controllers for the new views and return the updated map.
Expand Down Expand Up @@ -201,6 +235,10 @@
@freezed
class GridTabBarEvent with _$GridTabBarEvent {
const factory GridTabBarEvent.initial() = _Initial;
const factory GridTabBarEvent.moveToTrash() = MoveToTrash;
const factory GridTabBarEvent.restore() = Restore;
const factory GridTabBarEvent.restorePage() = RestorePage;
const factory GridTabBarEvent.deletePermanently() = DeletePermanently;
const factory GridTabBarEvent.didLoadChildViews(
List<ViewPB> childViews,
) = _DidLoadChildViews;
Expand All @@ -223,6 +261,8 @@
required int selectedIndex,
required List<TarBar> tabBars,
required Map<String, DatabaseTarBarController> tabBarControllerByViewId,
required bool isDeleted,
required bool forceClose,
}) = _GridTabBarState;

factory GridTabBarState.initial(ViewPB view) {
Expand All @@ -236,6 +276,8 @@
view: view,
)
},
isDeleted: false,
forceClose: false,
);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:appflowy/plugins/database_view/application/tar_bar_bloc.dart';
import 'package:appflowy/plugins/banner.dart';
import 'package:appflowy/plugins/database_view/widgets/share_button.dart';
import 'package:appflowy/plugins/util.dart';
import 'package:appflowy/startup/plugin/plugin.dart';
Expand Down Expand Up @@ -41,9 +42,11 @@
class DatabaseTabBarView extends StatefulWidget {
final ViewPB view;
final bool shrinkWrap;
final VoidCallback onDeleted;
const DatabaseTabBarView({
required this.view,
required this.shrinkWrap,
required this.onDeleted,
super.key,
});

Expand Down Expand Up @@ -82,55 +85,61 @@
},
),
],
child: Column(
children: [
BlocBuilder<GridTabBarBloc, GridTabBarState>(
builder: (context, state) {
return ValueListenableBuilder<bool>(
valueListenable: state
.tabBarControllerByViewId[state.parentView.id]!
.controller
.isLoading,
builder: (_, value, ___) {
if (value) {
return const SizedBox.shrink();
}
return SizedBox(
height: 30,
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: GridSize.leadingHeaderPadding,
child: BlocBuilder<GridTabBarBloc, GridTabBarState>(
builder: (context, state) {
if (state.forceClose) {
widget.onDeleted();

Check warning on line 91 in frontend/appflowy_flutter/lib/plugins/database_view/tar_bar/tab_bar_view.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/database_view/tar_bar/tab_bar_view.dart#L88-L91

Added lines #L88 - L91 were not covered by tests
return const SizedBox.shrink();
} else {
return Column(
children: [
if (state.isDeleted) _buildBanner(context),
ValueListenableBuilder<bool>(

Check warning on line 97 in frontend/appflowy_flutter/lib/plugins/database_view/tar_bar/tab_bar_view.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/database_view/tar_bar/tab_bar_view.dart#L94-L97

Added lines #L94 - L97 were not covered by tests
valueListenable: state
.tabBarControllerByViewId[state.parentView.id]!
.controller
.isLoading,
builder: (_, value, ___) {

Check warning on line 102 in frontend/appflowy_flutter/lib/plugins/database_view/tar_bar/tab_bar_view.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/database_view/tar_bar/tab_bar_view.dart#L99-L102

Added lines #L99 - L102 were not covered by tests
if (value) {
return const SizedBox.shrink();
}
return SizedBox(

Check warning on line 106 in frontend/appflowy_flutter/lib/plugins/database_view/tar_bar/tab_bar_view.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/database_view/tar_bar/tab_bar_view.dart#L106

Added line #L106 was not covered by tests
height: 30,
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: GridSize.leadingHeaderPadding,

Check warning on line 110 in frontend/appflowy_flutter/lib/plugins/database_view/tar_bar/tab_bar_view.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/database_view/tar_bar/tab_bar_view.dart#L108-L110

Added lines #L108 - L110 were not covered by tests
),
child: const TabBarHeader(),
),
child: const TabBarHeader(),
),
);
},
);
},
),
BlocBuilder<GridTabBarBloc, GridTabBarState>(
builder: (context, state) {
return pageSettingBarExtensionFromState(state);
},
),
Expanded(
child: BlocBuilder<GridTabBarBloc, GridTabBarState>(
builder: (context, state) {
return PageView(
pageSnapping: false,
physics: const NeverScrollableScrollPhysics(),
controller: _pageController,
children: pageContentFromState(state),
);
},
),
),
],
);
},
),
pageSettingBarExtensionFromState(state),
Expanded(
child: PageView(

Check warning on line 119 in frontend/appflowy_flutter/lib/plugins/database_view/tar_bar/tab_bar_view.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/database_view/tar_bar/tab_bar_view.dart#L117-L119

Added lines #L117 - L119 were not covered by tests
pageSnapping: false,
physics: const NeverScrollableScrollPhysics(),
controller: _pageController,
children: pageContentFromState(state),

Check warning on line 123 in frontend/appflowy_flutter/lib/plugins/database_view/tar_bar/tab_bar_view.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/database_view/tar_bar/tab_bar_view.dart#L122-L123

Added lines #L122 - L123 were not covered by tests
),
),
],
);
}
},
),
),
);
}

Widget _buildBanner(BuildContext context) {
final bloc = context.read<GridTabBarBloc>();
return OnDeleteBanner(
onRestore: () => bloc.add(const GridTabBarEvent.restorePage()),
onDelete: () => bloc.add(const GridTabBarEvent.deletePermanently()),

Check warning on line 139 in frontend/appflowy_flutter/lib/plugins/database_view/tar_bar/tab_bar_view.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/database_view/tar_bar/tab_bar_view.dart#L135-L139

Added lines #L135 - L139 were not covered by tests
);
}

List<Widget> pageContentFromState(GridTabBarState state) {
return state.tabBars.map((tabBar) {
final controller =
Expand Down Expand Up @@ -183,6 +192,7 @@

class DatabasePluginWidgetBuilder extends PluginWidgetBuilder {
final ViewPluginNotifier notifier;
int? deletedViewIndex;

DatabasePluginWidgetBuilder({
required this.notifier,
Expand All @@ -200,14 +210,15 @@
notifier.isDeleted.addListener(() {
notifier.isDeleted.value.fold(() => null, (deletedView) {
if (deletedView.hasIndex()) {
context?.onDeleted(notifier.view, deletedView.index);
deletedViewIndex = deletedView.index;

Check warning on line 213 in frontend/appflowy_flutter/lib/plugins/database_view/tar_bar/tab_bar_view.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/database_view/tar_bar/tab_bar_view.dart#L213

Added line #L213 was not covered by tests
}
});
});
return DatabaseTabBarView(
key: ValueKey(notifier.view.id),
view: notifier.view,
shrinkWrap: shrinkWrap,
onDeleted: () => context?.onDeleted(notifier.view, deletedViewIndex),

Check warning on line 221 in frontend/appflowy_flutter/lib/plugins/database_view/tar_bar/tab_bar_view.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/database_view/tar_bar/tab_bar_view.dart#L221

Added line #L221 was not covered by tests
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import 'dart:io';

import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/banner.dart';
import 'package:appflowy/plugins/document/application/doc_bloc.dart';
import 'package:appflowy/plugins/document/presentation/banner.dart';
import 'package:appflowy/plugins/document/presentation/editor_page.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy/plugins/document/presentation/editor_style.dart';
Expand Down Expand Up @@ -118,7 +118,7 @@
}

Widget _buildBanner(BuildContext context) {
return DocumentBanner(
return OnDeleteBanner(

Check warning on line 121 in frontend/appflowy_flutter/lib/plugins/document/document_page.dart

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_flutter/lib/plugins/document/document_page.dart#L121

Added line #L121 was not covered by tests
onRestore: () => documentBloc.add(const DocumentEvent.restorePage()),
onDelete: () => documentBloc.add(const DocumentEvent.deletePermanently()),
);
Expand Down
Loading