From e8ebc8be7294a8cb562aced1f9792dd8bc514bff Mon Sep 17 00:00:00 2001 From: NaiJi Date: Thu, 28 Sep 2023 22:09:57 -0300 Subject: [PATCH] refactor: Revert backups cubit back to normal --- lib/logic/cubit/backups/backups_cubit.dart | 54 +++++---------- lib/logic/cubit/backups/backups_state.dart | 80 +--------------------- 2 files changed, 19 insertions(+), 115 deletions(-) diff --git a/lib/logic/cubit/backups/backups_cubit.dart b/lib/logic/cubit/backups/backups_cubit.dart index 361cda06..cc6ca30c 100644 --- a/lib/logic/cubit/backups/backups_cubit.dart +++ b/lib/logic/cubit/backups/backups_cubit.dart @@ -25,33 +25,24 @@ class BackupsCubit extends ServerInstallationDependendCubit { @override Future load() async { - if (serverInstallationCubit.state is! ServerInstallationFinished) { - return; + if (serverInstallationCubit.state is ServerInstallationFinished) { + final BackblazeBucket? bucket = getIt().backblazeBucket; + final BackupConfiguration? backupConfig = + await api.getBackupsConfiguration(); + final List backups = await api.getBackups(); + backups.sort((final a, final b) => b.time.compareTo(a.time)); + emit( + state.copyWith( + backblazeBucket: bucket, + isInitialized: backupConfig?.isInitialized, + autobackupPeriod: backupConfig?.autobackupPeriod ?? Duration.zero, + autobackupQuotas: backupConfig?.autobackupQuotas, + backups: backups, + preventActions: false, + refreshing: false, + ), + ); } - - final BackblazeBucket? bucket = getIt().backblazeBucket; - final BackupConfiguration? backupConfig = - await api.getBackupsConfiguration(); - final BackupsCredential? backupsCredential = - getIt().backblazeCredential; - final List backups = await api.getBackups(); - backups.sort((final a, final b) => b.time.compareTo(a.time)); - final bool? initialized = backupConfig?.isInitialized; - final nextState = state.copyWith( - backblazeBucket: bucket, - isInitialized: initialized, - autobackupPeriod: backupConfig?.autobackupPeriod ?? Duration.zero, - autobackupQuotas: backupConfig?.autobackupQuotas, - backupsCredential: backupsCredential, - backups: backups, - preventActions: false, - refreshing: false, - ); - emit( - (initialized == null || initialized == false) - ? BackupsNotFinishedState.fromBackupsState(nextState) - : nextState, - ); } Future setBackupsKey( @@ -64,15 +55,6 @@ class BackupsCubit extends ServerInstallationDependendCubit { provider: BackupsProviderType.backblaze, ); await getIt().storeBackblazeCredential(backupsCredential); - if (state is BackupsNotFinishedState) { - emit( - (state as BackupsNotFinishedState).copyNotFinishedWith( - backupsCredential: backupsCredential, - step: BackupsInitializingStep.period, - ), - ); - return; - } emit( state.copyWith( backupsCredential: backupsCredential, @@ -309,6 +291,6 @@ class BackupsCubit extends ServerInstallationDependendCubit { @override void clear() async { - emit(BackupsNotFinishedState.fromBackupsState(const BackupsState())); + emit(const BackupsState()); } } diff --git a/lib/logic/cubit/backups/backups_state.dart b/lib/logic/cubit/backups/backups_state.dart index baf408b8..b94d87ed 100644 --- a/lib/logic/cubit/backups/backups_state.dart +++ b/lib/logic/cubit/backups/backups_state.dart @@ -53,9 +53,9 @@ class BackupsState extends ServerInstallationDependendState { preventActions: preventActions ?? this.preventActions, refreshTimer: refreshTimer ?? this.refreshTimer, refreshing: refreshing ?? this.refreshing, - backupsCredential: backupsCredential ?? this.backupsCredential, backblazeBucket: backblazeBucket ?? this.backblazeBucket, autobackupQuotas: autobackupQuotas ?? this.autobackupQuotas, + backupsCredential: backupsCredential ?? this.backupsCredential, // The autobackupPeriod might be null, so if the duration is set to 0, we // set it to null. autobackupPeriod: autobackupPeriod?.inSeconds == 0 @@ -63,81 +63,3 @@ class BackupsState extends ServerInstallationDependendState { : autobackupPeriod ?? this.autobackupPeriod, ); } - -class BackupsNotFinishedState extends BackupsState { - BackupsNotFinishedState.fromBackupsState(final BackupsState backupsState) - : this( - step: BackupsInitializingStep.hosting, - isInitialized: false, - autobackupPeriod: backupsState.autobackupPeriod, - autobackupQuotas: backupsState.autobackupQuotas, - backblazeBucket: backupsState.backblazeBucket, - backups: backupsState.backups, - backupsCredential: backupsState.backupsCredential, - preventActions: backupsState.preventActions, - refreshTimer: backupsState.refreshTimer, - refreshing: backupsState.refreshing, - ); - - const BackupsNotFinishedState({ - required this.step, - super.isInitialized = false, - super.backups = const [], - super.preventActions = true, - super.refreshTimer = const Duration(seconds: 60), - super.refreshing = true, - super.autobackupPeriod, - super.backblazeBucket, - super.autobackupQuotas, - super.backupsCredential, - }); - - final BackupsInitializingStep step; - - BackupsNotFinishedState copyNotFinishedWith({ - required final BackupsInitializingStep step, - final bool? isInitialized, - final List? backups, - final bool? preventActions, - final Duration? refreshTimer, - final bool? refreshing, - final Duration? autobackupPeriod, - final BackblazeBucket? backblazeBucket, - final AutobackupQuotas? autobackupQuotas, - final BackupsCredential? backupsCredential, - }) => - BackupsNotFinishedState( - isInitialized: isInitialized ?? this.isInitialized, - backups: backups ?? this.backups, - preventActions: preventActions ?? this.preventActions, - refreshTimer: refreshTimer ?? this.refreshTimer, - refreshing: refreshing ?? this.refreshing, - backupsCredential: backupsCredential ?? this.backupsCredential, - backblazeBucket: backblazeBucket ?? this.backblazeBucket, - autobackupQuotas: autobackupQuotas ?? this.autobackupQuotas, - step: step, - // The autobackupPeriod might be null, so if the duration is set to 0, we - // set it to null. - autobackupPeriod: autobackupPeriod?.inSeconds == 0 - ? null - : autobackupPeriod ?? this.autobackupPeriod, - ); - - BackupsState finish() => BackupsState( - isInitialized: true, - autobackupPeriod: autobackupPeriod, - autobackupQuotas: autobackupQuotas, - backblazeBucket: backblazeBucket, - backups: backups, - backupsCredential: backupsCredential, - preventActions: preventActions, - refreshTimer: refreshTimer, - refreshing: refreshing, - ); -} - -enum BackupsInitializingStep { - hosting, - period, - rotation, -}