Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

[flutter]: delete page permenently from doc page

appflowy40c7b46d702a
diff --git a/app_flowy/lib/workspace/application/doc/doc_bloc.dart b/app_flowy/lib/workspace/application/doc/doc_bloc.dart
index 0cddc5a9d0..fb972ba6bf 100644
--- a/app_flowy/lib/workspace/application/doc/doc_bloc.dart
+++ b/app_flowy/lib/workspace/application/doc/doc_bloc.dart
@@ -2,6 +2,7 @@ import 'dart:convert';
import 'package:app_flowy/workspace/domain/i_trash.dart';
import 'package:app_flowy/workspace/domain/i_view.dart';
+import 'package:flowy_sdk/protobuf/flowy-workspace/trash_create.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';
import 'package:flutter_quill/flutter_quill.dart';
import 'package:flowy_log/flowy_log.dart';
@@ -39,9 +40,10 @@ class DocBloc extends Bloc<DocEvent, DocState> {
yield state.copyWith(isDeleted: false);
},
deletePermanently: (DeletePermanently value) async* {
- // final result = await trasnManager.deleteViews([e.trash]);
- // yield* _handleResult(result);
- yield state;
+ final result = await trasnManager.deleteViews([Tuple2(view.id, TrashType.View)]);
+ yield result.fold((l) => state.copyWith(forceClose: true), (r) {
+ return state;
+ });
},
restorePage: (RestorePage value) async* {
final result = await trasnManager.putback(view.id);
@@ -136,11 +138,13 @@ class DocState with _$DocState {
const factory DocState({
required DocLoadState loadState,
required bool isDeleted,
+ required bool forceClose,
}) = _DocState;
factory DocState.initial() => const DocState(
loadState: _Loading(),
isDeleted: false,
+ forceClose: false,
);
}
diff --git a/app_flowy/lib/workspace/application/doc/doc_bloc.freezed.dart b/app_flowy/lib/workspace/application/doc/doc_bloc.freezed.dart
index 1614ba8efd..a2f83ca8db 100644
--- a/app_flowy/lib/workspace/application/doc/doc_bloc.freezed.dart
+++ b/app_flowy/lib/workspace/application/doc/doc_bloc.freezed.dart
@@ -580,10 +580,14 @@ abstract class DeletePermanently implements DocEvent {
class _$DocStateTearOff {
const _$DocStateTearOff();
- _DocState call({required DocLoadState loadState, required bool isDeleted}) {
+ _DocState call(
+ {required DocLoadState loadState,
+ required bool isDeleted,
+ required bool forceClose}) {
return _DocState(
loadState: loadState,
isDeleted: isDeleted,
+ forceClose: forceClose,
);
}
}
@@ -595,6 +599,7 @@ const $DocState = _$DocStateTearOff();
mixin _$DocState {
DocLoadState get loadState => throw _privateConstructorUsedError;
bool get isDeleted => throw _privateConstructorUsedError;
+ bool get forceClose => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$DocStateCopyWith<DocState> get copyWith =>
@@ -605,7 +610,7 @@ mixin _$DocState {
abstract class $DocStateCopyWith<$Res> {
factory $DocStateCopyWith(DocState value, $Res Function(DocState) then) =
_$DocStateCopyWithImpl<$Res>;
- $Res call({DocLoadState loadState, bool isDeleted});
+ $Res call({DocLoadState loadState, bool isDeleted, bool forceClose});
$DocLoadStateCopyWith<$Res> get loadState;
}
@@ -622,6 +627,7 @@ class _$DocStateCopyWithImpl<$Res> implements $DocStateCopyWith<$Res> {
$Res call({
Object? loadState = freezed,
Object? isDeleted = freezed,
+ Object? forceClose = freezed,
}) {
return _then(_value.copyWith(
loadState: loadState == freezed
@@ -632,6 +638,10 @@ class _$DocStateCopyWithImpl<$Res> implements $DocStateCopyWith<$Res> {
? _value.isDeleted
: isDeleted // ignore: cast_nullable_to_non_nullable
as bool,
+ forceClose: forceClose == freezed
+ ? _value.forceClose
+ : forceClose // ignore: cast_nullable_to_non_nullable
+ as bool,
));
}
@@ -648,7 +658,7 @@ abstract class _$DocStateCopyWith<$Res> implements $DocStateCopyWith<$Res> {
factory _$DocStateCopyWith(_DocState value, $Res Function(_DocState) then) =
__$DocStateCopyWithImpl<$Res>;
@override
- $Res call({DocLoadState loadState, bool isDeleted});
+ $Res call({DocLoadState loadState, bool isDeleted, bool forceClose});
@override
$DocLoadStateCopyWith<$Res> get loadState;
@@ -667,6 +677,7 @@ class __$DocStateCopyWithImpl<$Res> extends _$DocStateCopyWithImpl<$Res>
$Res call({
Object? loadState = freezed,
Object? isDeleted = freezed,
+ Object? forceClose = freezed,
}) {
return _then(_DocState(
loadState: loadState == freezed
@@ -677,6 +688,10 @@ class __$DocStateCopyWithImpl<$Res> extends _$DocStateCopyWithImpl<$Res>
? _value.isDeleted
: isDeleted // ignore: cast_nullable_to_non_nullable
as bool,
+ forceClose: forceClose == freezed
+ ? _value.forceClose
+ : forceClose // ignore: cast_nullable_to_non_nullable
+ as bool,
));
}
}
@@ -684,16 +699,21 @@ class __$DocStateCopyWithImpl<$Res> extends _$DocStateCopyWithImpl<$Res>
/// @nodoc
class _$_DocState implements _DocState {
- const _$_DocState({required this.loadState, required this.isDeleted});
+ const _$_DocState(
+ {required this.loadState,
+ required this.isDeleted,
+ required this.forceClose});
@override
final DocLoadState loadState;
@override
final bool isDeleted;
+ @override
+ final bool forceClose;
@override
String toString() {
- return 'DocState(loadState: $loadState, isDeleted: $isDeleted)';
+ return 'DocState(loadState: $loadState, isDeleted: $isDeleted, forceClose: $forceClose)';
}
@override
@@ -705,14 +725,18 @@ class _$_DocState implements _DocState {
.equals(other.loadState, loadState)) &&
(identical(other.isDeleted, isDeleted) ||
const DeepCollectionEquality()
- .equals(other.isDeleted, isDeleted)));
+ .equals(other.isDeleted, isDeleted)) &&
+ (identical(other.forceClose, forceClose) ||
+ const DeepCollectionEquality()
+ .equals(other.forceClose, forceClose)));
}
@override
int get hashCode =>
runtimeType.hashCode ^
const DeepCollectionEquality().hash(loadState) ^
- const DeepCollectionEquality().hash(isDeleted);
+ const DeepCollectionEquality().hash(isDeleted) ^
+ const DeepCollectionEquality().hash(forceClose);
@JsonKey(ignore: true)
@override
@@ -722,13 +746,17 @@ class _$_DocState implements _DocState {
abstract class _DocState implements DocState {
const factory _DocState(
- {required DocLoadState loadState, required bool isDeleted}) = _$_DocState;
+ {required DocLoadState loadState,
+ required bool isDeleted,
+ required bool forceClose}) = _$_DocState;
@override
DocLoadState get loadState => throw _privateConstructorUsedError;
@override
bool get isDeleted => throw _privateConstructorUsedError;
@override
+ bool get forceClose => throw _privateConstructorUsedError;
+ @override
@JsonKey(ignore: true)
_$DocStateCopyWith<_DocState> get copyWith =>
throw _privateConstructorUsedError;
diff --git a/app_flowy/lib/workspace/application/trash/trash_bloc.dart b/app_flowy/lib/workspace/application/trash/trash_bloc.dart
index f0bc88ca9b..368ffef118 100644
--- a/app_flowy/lib/workspace/application/trash/trash_bloc.dart
+++ b/app_flowy/lib/workspace/application/trash/trash_bloc.dart
@@ -31,7 +31,7 @@ class TrashBloc extends Bloc<TrashEvent, TrashState> {
yield* _handleResult(result);
},
delete: (e) async* {
- final result = await trasnManager.deleteViews([e.trash]);
+ final result = await trasnManager.deleteViews([Tuple2(e.trash.id, e.trash.ty)]);
yield* _handleResult(result);
},
deleteAll: (e) async* {
diff --git a/app_flowy/lib/workspace/domain/i_trash.dart b/app_flowy/lib/workspace/domain/i_trash.dart
index a432a8032f..59c1c48030 100644
--- a/app_flowy/lib/workspace/domain/i_trash.dart
+++ b/app_flowy/lib/workspace/domain/i_trash.dart
@@ -8,7 +8,7 @@ abstract class ITrash {
Future<Either<Unit, WorkspaceError>> putback(String trashId);
- Future<Either<Unit, WorkspaceError>> deleteViews(List<Trash> trashList);
+ Future<Either<Unit, WorkspaceError>> deleteViews(List<Tuple2<String, TrashType>> trashList);
Future<Either<Unit, WorkspaceError>> restoreAll();
diff --git a/app_flowy/lib/workspace/infrastructure/i_trash_impl.dart b/app_flowy/lib/workspace/infrastructure/i_trash_impl.dart
index 25453910d8..3f2c18f1be 100644
--- a/app_flowy/lib/workspace/infrastructure/i_trash_impl.dart
+++ b/app_flowy/lib/workspace/infrastructure/i_trash_impl.dart
@@ -24,11 +24,6 @@ class ITrashImpl implements ITrash {
return repo.putback(trashId);
}
- @override
- Future<Either<Unit, WorkspaceError>> deleteViews(List<Trash> trashList) {
- return repo.deleteViews(trashList);
- }
-
@override
Future<Either<Unit, WorkspaceError>> deleteAll() {
return repo.deleteAll();
@@ -38,6 +33,11 @@ class ITrashImpl implements ITrash {
Future<Either<Unit, WorkspaceError>> restoreAll() {
return repo.restoreAll();
}
+
+ @override
+ Future<Either<Unit, WorkspaceError>> deleteViews(List<Tuple2<String, TrashType>> trashList) {
+ return repo.deleteViews(trashList);
+ }
}
class ITrashListenerImpl extends ITrashListener {
diff --git a/app_flowy/lib/workspace/infrastructure/repos/trash_repo.dart b/app_flowy/lib/workspace/infrastructure/repos/trash_repo.dart
index c6348669e4..aeec064365 100644
--- a/app_flowy/lib/workspace/infrastructure/repos/trash_repo.dart
+++ b/app_flowy/lib/workspace/infrastructure/repos/trash_repo.dart
@@ -21,11 +21,11 @@ class TrashRepo {
return WorkspaceEventPutbackTrash(id).send();
}
- Future<Either<Unit, WorkspaceError>> deleteViews(List<Trash> trashList) {
+ Future<Either<Unit, WorkspaceError>> deleteViews(List<Tuple2<String, TrashType>> trashList) {
final items = trashList.map((trash) {
return TrashIdentifier.create()
- ..id = trash.id
- ..ty = trash.ty;
+ ..id = trash.value1
+ ..ty = trash.value2;
});
final trashIdentifiers = TrashIdentifiers(items: items);
diff --git a/app_flowy/lib/workspace/presentation/stack_page/doc/doc_page.dart b/app_flowy/lib/workspace/presentation/stack_page/doc/doc_page.dart
index c9998413ad..5b6e68f6a5 100644
--- a/app_flowy/lib/workspace/presentation/stack_page/doc/doc_page.dart
+++ b/app_flowy/lib/workspace/presentation/stack_page/doc/doc_page.dart
@@ -43,7 +43,13 @@ class _DocPageState extends State<DocPage> {
return state.loadState.map(
loading: (_) => const FlowyProgressIndicator(),
finish: (result) => result.successOrFail.fold(
- (_) => _renderDoc(context, state),
+ (_) {
+ if (state.forceClose) {
+ return _renderAppPage();
+ } else {
+ return _renderDoc(context, state);
+ }
+ },
(err) => FlowyErrorPage(err.toString()),
),
);
@@ -120,4 +126,10 @@ class _DocPageState extends State<DocPage> {
controller: controller,
);
}
+
+ Widget _renderAppPage() {
+ return Container(
+ color: Colors.black,
+ );
+ }
}