mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: show indicator when importing appflowy data (#4357)
* feat: show indicator when importing appflowy data * Update frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/setting_file_import_appflowy_data_view.dart Co-authored-by: Mathias Mogensen <42929161+Xazin@users.noreply.github.com> * chore: fix analyzer * chore: fix test --------- Co-authored-by: Mathias Mogensen <42929161+Xazin@users.noreply.github.com>
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
import 'package:appflowy/plugins/database/application/defines.dart';
|
||||
import 'package:appflowy_backend/dispatch/dispatch.dart';
|
||||
import 'package:appflowy_backend/log.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||
@ -9,39 +10,51 @@ import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'setting_file_importer_bloc.freezed.dart';
|
||||
|
||||
class SettingFileImporterBloc
|
||||
class SettingFileImportBloc
|
||||
extends Bloc<SettingFileImportEvent, SettingFileImportState> {
|
||||
SettingFileImporterBloc() : super(SettingFileImportState.initial()) {
|
||||
on<SettingFileImportEvent>((event, emit) async {
|
||||
await event.when(
|
||||
importAppFlowyDataFolder: (String path) async {
|
||||
final formattedDate =
|
||||
DateFormat('yyyy-MM-dd HH:mm:ss').format(DateTime.now());
|
||||
final payload = ImportAppFlowyDataPB.create()
|
||||
..path = path
|
||||
..importContainerName = "appflowy_import_$formattedDate";
|
||||
final result =
|
||||
await FolderEventImportAppFlowyDataFolder(payload).send();
|
||||
result.fold(
|
||||
(l) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
successOrFail: some(left(unit)),
|
||||
),
|
||||
);
|
||||
},
|
||||
(err) {
|
||||
Log.error(err);
|
||||
emit(
|
||||
state.copyWith(
|
||||
successOrFail: some(right(err)),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
SettingFileImportBloc() : super(SettingFileImportState.initial()) {
|
||||
on<SettingFileImportEvent>(
|
||||
(event, emit) async {
|
||||
await event.when(
|
||||
importAppFlowyDataFolder: (String path) async {
|
||||
final formattedDate =
|
||||
DateFormat('yyyy-MM-dd HH:mm:ss').format(DateTime.now());
|
||||
final payload = ImportAppFlowyDataPB.create()
|
||||
..path = path
|
||||
..importContainerName = "appflowy_import_$formattedDate";
|
||||
emit(
|
||||
state.copyWith(loadingState: const LoadingState.loading()),
|
||||
);
|
||||
FolderEventImportAppFlowyDataFolder(payload).send().then((result) {
|
||||
if (!isClosed) {
|
||||
add(SettingFileImportEvent.finishImport(result));
|
||||
}
|
||||
});
|
||||
},
|
||||
finishImport: (result) {
|
||||
result.fold(
|
||||
(l) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
successOrFail: some(left(unit)),
|
||||
loadingState: LoadingState.finish(left(unit)),
|
||||
),
|
||||
);
|
||||
},
|
||||
(err) {
|
||||
Log.error(err);
|
||||
emit(
|
||||
state.copyWith(
|
||||
successOrFail: some(right(err)),
|
||||
loadingState: LoadingState.finish(right(err)),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,15 +62,20 @@ class SettingFileImporterBloc
|
||||
class SettingFileImportEvent with _$SettingFileImportEvent {
|
||||
const factory SettingFileImportEvent.importAppFlowyDataFolder(String path) =
|
||||
_ImportAppFlowyDataFolder;
|
||||
const factory SettingFileImportEvent.finishImport(
|
||||
Either<Unit, FlowyError> result,
|
||||
) = _ImportResult;
|
||||
}
|
||||
|
||||
@freezed
|
||||
class SettingFileImportState with _$SettingFileImportState {
|
||||
const factory SettingFileImportState({
|
||||
required LoadingState loadingState,
|
||||
required Option<Either<Unit, FlowyError>> successOrFail,
|
||||
}) = _SettingFileImportState;
|
||||
|
||||
factory SettingFileImportState.initial() => SettingFileImportState(
|
||||
loadingState: const LoadingState.idle(),
|
||||
successOrFail: none(),
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user