From a6e6833efb6749577b1a53ad66eae625be393b4a Mon Sep 17 00:00:00 2001 From: NaiJi Date: Tue, 12 Sep 2023 21:37:12 -0300 Subject: [PATCH] refactor: Remove backblaze page from installation wizard --- .../server_installation_cubit.dart | 13 +--- .../server_installation_repository.dart | 9 --- .../server_installation_state.dart | 21 ------ lib/ui/pages/backups/backup_details.dart | 5 +- .../pages/backups/backup_provider_picker.dart | 65 +++++++++++++++++++ .../setup/initializing/initializing.dart | 64 ------------------ .../setup/recovering/recovery_routing.dart | 4 -- 7 files changed, 69 insertions(+), 112 deletions(-) create mode 100644 lib/ui/pages/backups/backup_provider_picker.dart diff --git a/lib/logic/cubit/server_installation/server_installation_cubit.dart b/lib/logic/cubit/server_installation/server_installation_cubit.dart index 8884b472..612ec715 100644 --- a/lib/logic/cubit/server_installation/server_installation_cubit.dart +++ b/lib/logic/cubit/server_installation/server_installation_cubit.dart @@ -237,13 +237,8 @@ class ServerInstallationCubit extends Cubit { print(e); } } - finishRecoveryProcess(backblazeCredential); return; } - emit( - (state as ServerInstallationNotFinished) - .copyWith(backblazeCredential: backblazeCredential), - ); } void setDomain(final ServerDomain serverDomain) async { @@ -756,14 +751,12 @@ class ServerInstallationCubit extends Cubit { provider: dnsProviderType, ), dnsApiToken: token, - currentStep: RecoveryStep.backblazeToken, ), ); + finishRecoveryProcess(); } - void finishRecoveryProcess( - final BackupsCredential backblazeCredential, - ) async { + void finishRecoveryProcess() async { await repository.saveIsServerStarted(true); await repository.saveIsServerResetedFirstTime(true); await repository.saveIsServerResetedSecondTime(true); @@ -778,7 +771,6 @@ class ServerInstallationCubit extends Cubit { await repository.saveRootUser(mainUser); final ServerInstallationRecovery updatedState = (state as ServerInstallationRecovery).copyWith( - backblazeCredential: backblazeCredential, rootUser: mainUser, serverTypeIdentificator: serverType.data!.identifier, ); @@ -845,7 +837,6 @@ class ServerInstallationCubit extends Cubit { providerApiToken: state.providerApiToken, serverDomain: state.serverDomain, dnsApiToken: state.dnsApiToken, - backblazeCredential: state.backblazeCredential, rootUser: state.rootUser, serverDetails: null, isServerStarted: false, diff --git a/lib/logic/cubit/server_installation/server_installation_repository.dart b/lib/logic/cubit/server_installation/server_installation_repository.dart index 30bccfd5..50156a39 100644 --- a/lib/logic/cubit/server_installation/server_installation_repository.dart +++ b/lib/logic/cubit/server_installation/server_installation_repository.dart @@ -45,8 +45,6 @@ class ServerInstallationRepository { final DnsProviderType? dnsProvider = getIt().dnsProvider; final ServerProviderType? serverProvider = getIt().serverProvider; - final BackupsCredential? backblazeCredential = - getIt().backblazeCredential; final ServerHostingDetails? serverDetails = getIt().serverDetails; @@ -87,7 +85,6 @@ class ServerInstallationRepository { serverTypeIdentificator: finalServerType.data!.identifier, dnsApiToken: dnsApiToken!, serverDomain: serverDomain!, - backblazeCredential: backblazeCredential!, serverDetails: serverDetails, rootUser: box.get(BNames.rootUser), isServerStarted: box.get(BNames.isServerStarted, defaultValue: false), @@ -103,7 +100,6 @@ class ServerInstallationRepository { serverTypeIdentificator: serverTypeIdentificator!, dnsApiToken: dnsApiToken!, serverDomain: serverDomain!, - backblazeCredential: backblazeCredential!, serverDetails: serverDetails!, rootUser: box.get(BNames.rootUser), isServerStarted: box.get(BNames.isServerStarted, defaultValue: false), @@ -122,7 +118,6 @@ class ServerInstallationRepository { dnsApiToken: dnsApiToken, serverDomain: serverDomain, serverTypeIdentificator: serverTypeIdentificator, - backblazeCredential: backblazeCredential, serverDetails: serverDetails, rootUser: box.get(BNames.rootUser), currentStep: _getCurrentRecoveryStep( @@ -140,7 +135,6 @@ class ServerInstallationRepository { dnsApiToken: dnsApiToken, serverDomain: serverDomain, serverTypeIdentificator: serverTypeIdentificator, - backblazeCredential: backblazeCredential, serverDetails: serverDetails, rootUser: box.get(BNames.rootUser), isServerStarted: box.get(BNames.isServerStarted, defaultValue: false), @@ -162,9 +156,6 @@ class ServerInstallationRepository { if (serverDetails != null) { if (serverProviderToken != null) { if (serverDetails.provider != ServerProviderType.unknown) { - if (serverDomain.provider != DnsProviderType.unknown) { - return RecoveryStep.backblazeToken; - } return RecoveryStep.dnsProviderToken; } return RecoveryStep.serverSelection; diff --git a/lib/logic/cubit/server_installation/server_installation_state.dart b/lib/logic/cubit/server_installation/server_installation_state.dart index 9f701a0a..4673e021 100644 --- a/lib/logic/cubit/server_installation/server_installation_state.dart +++ b/lib/logic/cubit/server_installation/server_installation_state.dart @@ -5,7 +5,6 @@ abstract class ServerInstallationState extends Equatable { required this.providerApiToken, required this.serverTypeIdentificator, required this.dnsApiToken, - required this.backblazeCredential, required this.serverDomain, required this.rootUser, required this.serverDetails, @@ -20,7 +19,6 @@ abstract class ServerInstallationState extends Equatable { providerApiToken, serverTypeIdentificator, dnsApiToken, - backblazeCredential, serverDomain, rootUser, serverDetails, @@ -32,7 +30,6 @@ abstract class ServerInstallationState extends Equatable { final String? providerApiToken; final String? dnsApiToken; final String? serverTypeIdentificator; - final BackupsCredential? backblazeCredential; final ServerDomain? serverDomain; final User? rootUser; final ServerHostingDetails? serverDetails; @@ -44,7 +41,6 @@ abstract class ServerInstallationState extends Equatable { bool get isServerProviderApiKeyFilled => providerApiToken != null; bool get isServerTypeFilled => serverTypeIdentificator != null; bool get isDnsProviderFilled => dnsApiToken != null; - bool get isBackupsProviderFilled => backblazeCredential != null; bool get isDomainSelected => serverDomain != null; bool get isPrimaryUserFilled => rootUser != null; bool get isServerCreated => serverDetails != null; @@ -68,7 +64,6 @@ abstract class ServerInstallationState extends Equatable { isServerProviderApiKeyFilled, isServerTypeFilled, isDnsProviderFilled, - isBackupsProviderFilled, isDomainSelected, isPrimaryUserFilled, isServerCreated, @@ -91,7 +86,6 @@ class TimerState extends ServerInstallationNotFinished { providerApiToken: dataState.providerApiToken, serverTypeIdentificator: dataState.serverTypeIdentificator, dnsApiToken: dataState.dnsApiToken, - backblazeCredential: dataState.backblazeCredential, serverDomain: dataState.serverDomain, rootUser: dataState.rootUser, serverDetails: dataState.serverDetails, @@ -119,7 +113,6 @@ enum ServerSetupProgress { serverProviderFilled, servertTypeFilled, dnsProviderFilled, - backblazeFilled, domainFilled, userFilled, serverCreated, @@ -138,7 +131,6 @@ class ServerInstallationNotFinished extends ServerInstallationState { super.providerApiToken, super.serverTypeIdentificator, super.dnsApiToken, - super.backblazeCredential, super.serverDomain, super.rootUser, super.serverDetails, @@ -152,7 +144,6 @@ class ServerInstallationNotFinished extends ServerInstallationState { providerApiToken, serverTypeIdentificator, dnsApiToken, - backblazeCredential, serverDomain, rootUser, serverDetails, @@ -167,7 +158,6 @@ class ServerInstallationNotFinished extends ServerInstallationState { final String? providerApiToken, final String? serverTypeIdentificator, final String? dnsApiToken, - final BackupsCredential? backblazeCredential, final ServerDomain? serverDomain, final User? rootUser, final ServerHostingDetails? serverDetails, @@ -183,7 +173,6 @@ class ServerInstallationNotFinished extends ServerInstallationState { serverTypeIdentificator: serverTypeIdentificator ?? this.serverTypeIdentificator, dnsApiToken: dnsApiToken ?? this.dnsApiToken, - backblazeCredential: backblazeCredential ?? this.backblazeCredential, serverDomain: serverDomain ?? this.serverDomain, rootUser: rootUser ?? this.rootUser, serverDetails: serverDetails ?? this.serverDetails, @@ -202,7 +191,6 @@ class ServerInstallationNotFinished extends ServerInstallationState { providerApiToken: providerApiToken!, serverTypeIdentificator: serverTypeIdentificator!, dnsApiToken: dnsApiToken!, - backblazeCredential: backblazeCredential!, serverDomain: serverDomain!, rootUser: rootUser!, serverDetails: serverDetails!, @@ -219,7 +207,6 @@ class ServerInstallationEmpty extends ServerInstallationNotFinished { providerApiToken: null, serverTypeIdentificator: null, dnsApiToken: null, - backblazeCredential: null, serverDomain: null, rootUser: null, serverDetails: null, @@ -237,7 +224,6 @@ class ServerInstallationFinished extends ServerInstallationState { required String super.providerApiToken, required String super.serverTypeIdentificator, required String super.dnsApiToken, - required BackupsCredential super.backblazeCredential, required ServerDomain super.serverDomain, required User super.rootUser, required ServerHostingDetails super.serverDetails, @@ -252,7 +238,6 @@ class ServerInstallationFinished extends ServerInstallationState { providerApiToken, serverTypeIdentificator, dnsApiToken, - backblazeCredential, serverDomain, rootUser, serverDetails, @@ -270,7 +255,6 @@ enum RecoveryStep { serverProviderToken, serverSelection, dnsProviderToken, - backblazeToken, } enum ServerRecoveryCapabilities { @@ -292,7 +276,6 @@ class ServerInstallationRecovery extends ServerInstallationState { super.providerApiToken, super.serverTypeIdentificator, super.dnsApiToken, - super.backblazeCredential, super.serverDomain, super.rootUser, super.serverDetails, @@ -310,7 +293,6 @@ class ServerInstallationRecovery extends ServerInstallationState { providerApiToken, serverTypeIdentificator, dnsApiToken, - backblazeCredential, serverDomain, rootUser, serverDetails, @@ -324,7 +306,6 @@ class ServerInstallationRecovery extends ServerInstallationState { final String? providerApiToken, final String? serverTypeIdentificator, final String? dnsApiToken, - final BackupsCredential? backblazeCredential, final ServerDomain? serverDomain, final User? rootUser, final ServerHostingDetails? serverDetails, @@ -336,7 +317,6 @@ class ServerInstallationRecovery extends ServerInstallationState { serverTypeIdentificator: serverTypeIdentificator ?? this.serverTypeIdentificator, dnsApiToken: dnsApiToken ?? this.dnsApiToken, - backblazeCredential: backblazeCredential ?? this.backblazeCredential, serverDomain: serverDomain ?? this.serverDomain, rootUser: rootUser ?? this.rootUser, serverDetails: serverDetails ?? this.serverDetails, @@ -348,7 +328,6 @@ class ServerInstallationRecovery extends ServerInstallationState { providerApiToken: providerApiToken!, serverTypeIdentificator: serverTypeIdentificator!, dnsApiToken: dnsApiToken!, - backblazeCredential: backblazeCredential!, serverDomain: serverDomain!, rootUser: rootUser!, serverDetails: serverDetails!, diff --git a/lib/ui/pages/backups/backup_details.dart b/lib/ui/pages/backups/backup_details.dart index 344876b1..6df24927 100644 --- a/lib/ui/pages/backups/backup_details.dart +++ b/lib/ui/pages/backups/backup_details.dart @@ -15,6 +15,7 @@ import 'package:selfprivacy/ui/components/jobs_content/server_job_card.dart'; import 'package:selfprivacy/ui/layouts/brand_hero_screen.dart'; import 'package:selfprivacy/ui/components/brand_icons/brand_icons.dart'; import 'package:selfprivacy/ui/helpers/modals.dart'; +import 'package:selfprivacy/ui/pages/backups/backup_provider_picker.dart'; import 'package:selfprivacy/ui/pages/backups/change_period_modal.dart'; import 'package:selfprivacy/ui/pages/backups/change_rotation_quotas_modal.dart'; import 'package:selfprivacy/ui/pages/backups/copy_encryption_key_modal.dart'; @@ -75,9 +76,7 @@ class BackupDetailsPage extends StatelessWidget { BrandButton.rised( onPressed: preventActions ? null - : () async { - await context.read().initializeBackups(); - }, + : () => context.pushRoute(BackupProviderPicker()), text: 'backup.initialize'.tr(), ), ], diff --git a/lib/ui/pages/backups/backup_provider_picker.dart b/lib/ui/pages/backups/backup_provider_picker.dart new file mode 100644 index 00000000..f54a35bd --- /dev/null +++ b/lib/ui/pages/backups/backup_provider_picker.dart @@ -0,0 +1,65 @@ +import 'package:cubit_form/cubit_form.dart'; +import 'package:easy_localization/easy_localization.dart'; +import 'package:flutter/material.dart'; +import 'package:selfprivacy/logic/cubit/forms/setup/initializing/backblaze_form_cubit.dart'; +import 'package:selfprivacy/logic/cubit/support_system/support_system_cubit.dart'; +import 'package:selfprivacy/ui/components/buttons/brand_button.dart'; +import 'package:selfprivacy/ui/layouts/responsive_layout_with_infobox.dart'; + +class BackupProviderPicker extends StatelessWidget { + const BackupProviderPicker({ + super.key, + }); + + @override + Widget build(final BuildContext context) => ResponsiveLayoutWithInfobox( + topChild: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + '${'initializing.connect_to_server_provider'.tr()}Backblaze', + style: Theme.of(context).textTheme.headlineSmall, + ), + ], + ), + primaryColumn: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + CubitFormTextField( + autofocus: true, + formFieldCubit: context.read().keyId, + textAlign: TextAlign.center, + scrollPadding: const EdgeInsets.only(bottom: 70), + decoration: const InputDecoration( + hintText: 'KeyID', + ), + ), + const SizedBox(height: 16), + CubitFormTextField( + formFieldCubit: context.read().applicationKey, + textAlign: TextAlign.center, + scrollPadding: const EdgeInsets.only(bottom: 70), + decoration: const InputDecoration( + hintText: 'Master Application Key', + ), + ), + const SizedBox(height: 32), + BrandButton.rised( + onPressed: () => context.read().trySubmit(), + text: 'basis.connect'.tr(), + ), + const SizedBox(height: 10), + BrandButton.text( + onPressed: () { + context.read().showArticle( + article: 'how_backblaze', + context: context, + ); + Scaffold.of(context).openEndDrawer(); + }, + title: 'initializing.how'.tr(), + ), + ], + ), + ); +} diff --git a/lib/ui/pages/setup/initializing/initializing.dart b/lib/ui/pages/setup/initializing/initializing.dart index a681c07a..7eb2961a 100644 --- a/lib/ui/pages/setup/initializing/initializing.dart +++ b/lib/ui/pages/setup/initializing/initializing.dart @@ -42,7 +42,6 @@ class InitializingPage extends StatelessWidget { () => _stepServerProviderToken(cubit), () => _stepServerType(cubit), () => _stepDnsProviderToken(cubit), - () => _stepBackblaze(cubit), () => _stepDomain(cubit), () => _stepUser(cubit), () => _stepServer(cubit), @@ -254,69 +253,6 @@ class InitializingPage extends StatelessWidget { ), ); - Widget _stepBackblaze(final ServerInstallationCubit initializingCubit) => - BlocProvider( - create: (final context) => BackblazeFormCubit(initializingCubit), - child: Builder( - builder: (final context) { - final formCubitState = context.watch().state; - return ResponsiveLayoutWithInfobox( - topChild: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - '${'initializing.connect_to_server_provider'.tr()}Backblaze', - style: Theme.of(context).textTheme.headlineSmall, - ), - ], - ), - primaryColumn: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - CubitFormTextField( - autofocus: true, - formFieldCubit: context.read().keyId, - textAlign: TextAlign.center, - scrollPadding: const EdgeInsets.only(bottom: 70), - decoration: const InputDecoration( - hintText: 'KeyID', - ), - ), - const SizedBox(height: 16), - CubitFormTextField( - formFieldCubit: - context.read().applicationKey, - textAlign: TextAlign.center, - scrollPadding: const EdgeInsets.only(bottom: 70), - decoration: const InputDecoration( - hintText: 'Master Application Key', - ), - ), - const SizedBox(height: 32), - BrandButton.rised( - onPressed: formCubitState.isSubmitting - ? null - : () => context.read().trySubmit(), - text: 'basis.connect'.tr(), - ), - const SizedBox(height: 10), - BrandButton.text( - onPressed: () { - context.read().showArticle( - article: 'how_backblaze', - context: context, - ); - Scaffold.of(context).openEndDrawer(); - }, - title: 'initializing.how'.tr(), - ), - ], - ), - ); - }, - ), - ); - Widget _stepDomain(final ServerInstallationCubit initializingCubit) => BlocProvider( create: (final context) => DomainSetupCubit(initializingCubit)..load(), diff --git a/lib/ui/pages/setup/recovering/recovery_routing.dart b/lib/ui/pages/setup/recovering/recovery_routing.dart index 3ab5109a..4018a6d8 100644 --- a/lib/ui/pages/setup/recovering/recovery_routing.dart +++ b/lib/ui/pages/setup/recovering/recovery_routing.dart @@ -11,7 +11,6 @@ import 'package:selfprivacy/ui/pages/root_route.dart'; import 'package:selfprivacy/ui/pages/setup/recovering/recover_by_old_token.dart'; import 'package:selfprivacy/ui/pages/setup/recovering/recover_by_recovery_key.dart'; import 'package:selfprivacy/ui/pages/setup/recovering/recover_by_new_device_key.dart'; -import 'package:selfprivacy/ui/pages/setup/recovering/recovery_confirm_backblaze.dart'; import 'package:selfprivacy/ui/pages/setup/recovering/recovery_confirm_dns.dart'; import 'package:selfprivacy/ui/pages/setup/recovering/recovery_confirm_server.dart'; import 'package:selfprivacy/ui/pages/setup/recovering/recovery_server_provider_connected.dart'; @@ -58,9 +57,6 @@ class RecoveryRouting extends StatelessWidget { case RecoveryStep.dnsProviderToken: currentPage = const RecoveryConfirmDns(); break; - case RecoveryStep.backblazeToken: - currentPage = const RecoveryConfirmBackblaze(); - break; } }