[flutter]: delete page permenently from doc page

This commit is contained in:
appflowy 2021-10-31 20:27:37 +08:00
parent ddfe985065
commit 40c7b46d70
7 changed files with 66 additions and 22 deletions

View File

@ -2,6 +2,7 @@ import 'dart:convert';
import 'package:app_flowy/workspace/domain/i_trash.dart'; import 'package:app_flowy/workspace/domain/i_trash.dart';
import 'package:app_flowy/workspace/domain/i_view.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:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';
import 'package:flutter_quill/flutter_quill.dart'; import 'package:flutter_quill/flutter_quill.dart';
import 'package:flowy_log/flowy_log.dart'; import 'package:flowy_log/flowy_log.dart';
@ -39,9 +40,10 @@ class DocBloc extends Bloc<DocEvent, DocState> {
yield state.copyWith(isDeleted: false); yield state.copyWith(isDeleted: false);
}, },
deletePermanently: (DeletePermanently value) async* { deletePermanently: (DeletePermanently value) async* {
// final result = await trasnManager.deleteViews([e.trash]); final result = await trasnManager.deleteViews([Tuple2(view.id, TrashType.View)]);
// yield* _handleResult(result); yield result.fold((l) => state.copyWith(forceClose: true), (r) {
yield state; return state;
});
}, },
restorePage: (RestorePage value) async* { restorePage: (RestorePage value) async* {
final result = await trasnManager.putback(view.id); final result = await trasnManager.putback(view.id);
@ -136,11 +138,13 @@ class DocState with _$DocState {
const factory DocState({ const factory DocState({
required DocLoadState loadState, required DocLoadState loadState,
required bool isDeleted, required bool isDeleted,
required bool forceClose,
}) = _DocState; }) = _DocState;
factory DocState.initial() => const DocState( factory DocState.initial() => const DocState(
loadState: _Loading(), loadState: _Loading(),
isDeleted: false, isDeleted: false,
forceClose: false,
); );
} }

View File

@ -580,10 +580,14 @@ abstract class DeletePermanently implements DocEvent {
class _$DocStateTearOff { class _$DocStateTearOff {
const _$DocStateTearOff(); const _$DocStateTearOff();
_DocState call({required DocLoadState loadState, required bool isDeleted}) { _DocState call(
{required DocLoadState loadState,
required bool isDeleted,
required bool forceClose}) {
return _DocState( return _DocState(
loadState: loadState, loadState: loadState,
isDeleted: isDeleted, isDeleted: isDeleted,
forceClose: forceClose,
); );
} }
} }
@ -595,6 +599,7 @@ const $DocState = _$DocStateTearOff();
mixin _$DocState { mixin _$DocState {
DocLoadState get loadState => throw _privateConstructorUsedError; DocLoadState get loadState => throw _privateConstructorUsedError;
bool get isDeleted => throw _privateConstructorUsedError; bool get isDeleted => throw _privateConstructorUsedError;
bool get forceClose => throw _privateConstructorUsedError;
@JsonKey(ignore: true) @JsonKey(ignore: true)
$DocStateCopyWith<DocState> get copyWith => $DocStateCopyWith<DocState> get copyWith =>
@ -605,7 +610,7 @@ mixin _$DocState {
abstract class $DocStateCopyWith<$Res> { abstract class $DocStateCopyWith<$Res> {
factory $DocStateCopyWith(DocState value, $Res Function(DocState) then) = factory $DocStateCopyWith(DocState value, $Res Function(DocState) then) =
_$DocStateCopyWithImpl<$Res>; _$DocStateCopyWithImpl<$Res>;
$Res call({DocLoadState loadState, bool isDeleted}); $Res call({DocLoadState loadState, bool isDeleted, bool forceClose});
$DocLoadStateCopyWith<$Res> get loadState; $DocLoadStateCopyWith<$Res> get loadState;
} }
@ -622,6 +627,7 @@ class _$DocStateCopyWithImpl<$Res> implements $DocStateCopyWith<$Res> {
$Res call({ $Res call({
Object? loadState = freezed, Object? loadState = freezed,
Object? isDeleted = freezed, Object? isDeleted = freezed,
Object? forceClose = freezed,
}) { }) {
return _then(_value.copyWith( return _then(_value.copyWith(
loadState: loadState == freezed loadState: loadState == freezed
@ -632,6 +638,10 @@ class _$DocStateCopyWithImpl<$Res> implements $DocStateCopyWith<$Res> {
? _value.isDeleted ? _value.isDeleted
: isDeleted // ignore: cast_nullable_to_non_nullable : isDeleted // ignore: cast_nullable_to_non_nullable
as bool, 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) = factory _$DocStateCopyWith(_DocState value, $Res Function(_DocState) then) =
__$DocStateCopyWithImpl<$Res>; __$DocStateCopyWithImpl<$Res>;
@override @override
$Res call({DocLoadState loadState, bool isDeleted}); $Res call({DocLoadState loadState, bool isDeleted, bool forceClose});
@override @override
$DocLoadStateCopyWith<$Res> get loadState; $DocLoadStateCopyWith<$Res> get loadState;
@ -667,6 +677,7 @@ class __$DocStateCopyWithImpl<$Res> extends _$DocStateCopyWithImpl<$Res>
$Res call({ $Res call({
Object? loadState = freezed, Object? loadState = freezed,
Object? isDeleted = freezed, Object? isDeleted = freezed,
Object? forceClose = freezed,
}) { }) {
return _then(_DocState( return _then(_DocState(
loadState: loadState == freezed loadState: loadState == freezed
@ -677,6 +688,10 @@ class __$DocStateCopyWithImpl<$Res> extends _$DocStateCopyWithImpl<$Res>
? _value.isDeleted ? _value.isDeleted
: isDeleted // ignore: cast_nullable_to_non_nullable : isDeleted // ignore: cast_nullable_to_non_nullable
as bool, 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 /// @nodoc
class _$_DocState implements _DocState { class _$_DocState implements _DocState {
const _$_DocState({required this.loadState, required this.isDeleted}); const _$_DocState(
{required this.loadState,
required this.isDeleted,
required this.forceClose});
@override @override
final DocLoadState loadState; final DocLoadState loadState;
@override @override
final bool isDeleted; final bool isDeleted;
@override
final bool forceClose;
@override @override
String toString() { String toString() {
return 'DocState(loadState: $loadState, isDeleted: $isDeleted)'; return 'DocState(loadState: $loadState, isDeleted: $isDeleted, forceClose: $forceClose)';
} }
@override @override
@ -705,14 +725,18 @@ class _$_DocState implements _DocState {
.equals(other.loadState, loadState)) && .equals(other.loadState, loadState)) &&
(identical(other.isDeleted, isDeleted) || (identical(other.isDeleted, isDeleted) ||
const DeepCollectionEquality() const DeepCollectionEquality()
.equals(other.isDeleted, isDeleted))); .equals(other.isDeleted, isDeleted)) &&
(identical(other.forceClose, forceClose) ||
const DeepCollectionEquality()
.equals(other.forceClose, forceClose)));
} }
@override @override
int get hashCode => int get hashCode =>
runtimeType.hashCode ^ runtimeType.hashCode ^
const DeepCollectionEquality().hash(loadState) ^ const DeepCollectionEquality().hash(loadState) ^
const DeepCollectionEquality().hash(isDeleted); const DeepCollectionEquality().hash(isDeleted) ^
const DeepCollectionEquality().hash(forceClose);
@JsonKey(ignore: true) @JsonKey(ignore: true)
@override @override
@ -722,13 +746,17 @@ class _$_DocState implements _DocState {
abstract class _DocState implements DocState { abstract class _DocState implements DocState {
const factory _DocState( const factory _DocState(
{required DocLoadState loadState, required bool isDeleted}) = _$_DocState; {required DocLoadState loadState,
required bool isDeleted,
required bool forceClose}) = _$_DocState;
@override @override
DocLoadState get loadState => throw _privateConstructorUsedError; DocLoadState get loadState => throw _privateConstructorUsedError;
@override @override
bool get isDeleted => throw _privateConstructorUsedError; bool get isDeleted => throw _privateConstructorUsedError;
@override @override
bool get forceClose => throw _privateConstructorUsedError;
@override
@JsonKey(ignore: true) @JsonKey(ignore: true)
_$DocStateCopyWith<_DocState> get copyWith => _$DocStateCopyWith<_DocState> get copyWith =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;

View File

@ -31,7 +31,7 @@ class TrashBloc extends Bloc<TrashEvent, TrashState> {
yield* _handleResult(result); yield* _handleResult(result);
}, },
delete: (e) async* { 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); yield* _handleResult(result);
}, },
deleteAll: (e) async* { deleteAll: (e) async* {

View File

@ -8,7 +8,7 @@ abstract class ITrash {
Future<Either<Unit, WorkspaceError>> putback(String trashId); 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(); Future<Either<Unit, WorkspaceError>> restoreAll();

View File

@ -24,11 +24,6 @@ class ITrashImpl implements ITrash {
return repo.putback(trashId); return repo.putback(trashId);
} }
@override
Future<Either<Unit, WorkspaceError>> deleteViews(List<Trash> trashList) {
return repo.deleteViews(trashList);
}
@override @override
Future<Either<Unit, WorkspaceError>> deleteAll() { Future<Either<Unit, WorkspaceError>> deleteAll() {
return repo.deleteAll(); return repo.deleteAll();
@ -38,6 +33,11 @@ class ITrashImpl implements ITrash {
Future<Either<Unit, WorkspaceError>> restoreAll() { Future<Either<Unit, WorkspaceError>> restoreAll() {
return repo.restoreAll(); return repo.restoreAll();
} }
@override
Future<Either<Unit, WorkspaceError>> deleteViews(List<Tuple2<String, TrashType>> trashList) {
return repo.deleteViews(trashList);
}
} }
class ITrashListenerImpl extends ITrashListener { class ITrashListenerImpl extends ITrashListener {

View File

@ -21,11 +21,11 @@ class TrashRepo {
return WorkspaceEventPutbackTrash(id).send(); 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) { final items = trashList.map((trash) {
return TrashIdentifier.create() return TrashIdentifier.create()
..id = trash.id ..id = trash.value1
..ty = trash.ty; ..ty = trash.value2;
}); });
final trashIdentifiers = TrashIdentifiers(items: items); final trashIdentifiers = TrashIdentifiers(items: items);

View File

@ -43,7 +43,13 @@ class _DocPageState extends State<DocPage> {
return state.loadState.map( return state.loadState.map(
loading: (_) => const FlowyProgressIndicator(), loading: (_) => const FlowyProgressIndicator(),
finish: (result) => result.successOrFail.fold( finish: (result) => result.successOrFail.fold(
(_) => _renderDoc(context, state), (_) {
if (state.forceClose) {
return _renderAppPage();
} else {
return _renderDoc(context, state);
}
},
(err) => FlowyErrorPage(err.toString()), (err) => FlowyErrorPage(err.toString()),
), ),
); );
@ -120,4 +126,10 @@ class _DocPageState extends State<DocPage> {
controller: controller, controller: controller,
); );
} }
Widget _renderAppPage() {
return Container(
color: Colors.black,
);
}
} }