From 4da4ed6afd653048acc29c46e9de379856a94325 Mon Sep 17 00:00:00 2001 From: NaiJi Date: Fri, 2 Jun 2023 19:04:23 -0300 Subject: [PATCH] feat: Move current installation dialogue error to installation state --- .../server_installation_cubit.dart | 29 +++---------------- .../server_installation_repository.dart | 1 + .../server_installation_state.dart | 18 +++++++++++- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/lib/logic/cubit/server_installation/server_installation_cubit.dart b/lib/logic/cubit/server_installation/server_installation_cubit.dart index 4a011248..6fa7d569 100644 --- a/lib/logic/cubit/server_installation/server_installation_cubit.dart +++ b/lib/logic/cubit/server_installation/server_installation_cubit.dart @@ -19,7 +19,6 @@ import 'package:selfprivacy/logic/models/server_basic_info.dart'; import 'package:selfprivacy/logic/cubit/server_installation/server_installation_repository.dart'; import 'package:selfprivacy/logic/models/server_provider_location.dart'; import 'package:selfprivacy/logic/models/server_type.dart'; -import 'package:selfprivacy/ui/helpers/modals.dart'; export 'package:provider/provider.dart'; @@ -256,31 +255,11 @@ class ServerInstallationCubit extends Cubit { ); if (!result.success && result.data != null) { - CallbackDialogueBranching branching = result.data!; - //while (!dialoguesResolved) { - showPopUpAlert( - alertTitle: branching.title, - description: branching.description, - actionButtonTitle: branching.choices[1].title, - actionButtonOnPressed: () async { - final branchingResult = await branching.choices[1].callback!(); - if (branchingResult.data == null) { - return; - } - - branching = branchingResult.data!; - }, - cancelButtonTitle: branching.choices[0].title, - cancelButtonOnPressed: () async { - final branchingResult = await branching.choices[0].callback!(); - if (branchingResult.data == null) { - return; - } - - branching = branchingResult.data!; - }, + emit( + (state as ServerInstallationNotFinished).copyWith( + installationDialoguePopUp: result.data, + ), ); - //} } } diff --git a/lib/logic/cubit/server_installation/server_installation_repository.dart b/lib/logic/cubit/server_installation/server_installation_repository.dart index 9b3fa46b..9444718e 100644 --- a/lib/logic/cubit/server_installation/server_installation_repository.dart +++ b/lib/logic/cubit/server_installation/server_installation_repository.dart @@ -79,6 +79,7 @@ class ServerInstallationRepository { if (box.get(BNames.hasFinalChecked, defaultValue: false)) { StagingOptions.verifyCertificate = true; return ServerInstallationFinished( + installationDialoguePopUp: null, providerApiToken: providerApiToken!, serverTypeIdentificator: serverTypeIdentificator ?? '', dnsApiToken: dnsApiToken!, diff --git a/lib/logic/cubit/server_installation/server_installation_state.dart b/lib/logic/cubit/server_installation/server_installation_state.dart index 5ceaafdd..c6356c36 100644 --- a/lib/logic/cubit/server_installation/server_installation_state.dart +++ b/lib/logic/cubit/server_installation/server_installation_state.dart @@ -12,6 +12,7 @@ abstract class ServerInstallationState extends Equatable { required this.isServerStarted, required this.isServerResetedFirstTime, required this.isServerResetedSecondTime, + required this.installationDialoguePopUp, }); @override @@ -25,6 +26,7 @@ abstract class ServerInstallationState extends Equatable { serverDetails, isServerStarted, isServerResetedFirstTime, + installationDialoguePopUp ]; final String? providerApiToken; @@ -37,6 +39,7 @@ abstract class ServerInstallationState extends Equatable { final bool isServerStarted; final bool isServerResetedFirstTime; final bool isServerResetedSecondTime; + final CallbackDialogueBranching? installationDialoguePopUp; bool get isServerProviderApiKeyFilled => providerApiToken != null; bool get isServerTypeFilled => serverTypeIdentificator != null; @@ -96,6 +99,7 @@ class TimerState extends ServerInstallationNotFinished { isServerResetedFirstTime: dataState.isServerResetedFirstTime, isServerResetedSecondTime: dataState.isServerResetedSecondTime, dnsMatches: dataState.dnsMatches, + installationDialoguePopUp: dataState.installationDialoguePopUp, ); final ServerInstallationNotFinished dataState; @@ -138,6 +142,7 @@ class ServerInstallationNotFinished extends ServerInstallationState { super.serverDomain, super.rootUser, super.serverDetails, + super.installationDialoguePopUp, }); final bool isLoading; final Map? dnsMatches; @@ -155,6 +160,7 @@ class ServerInstallationNotFinished extends ServerInstallationState { isServerResetedFirstTime, isLoading, dnsMatches, + installationDialoguePopUp, ]; ServerInstallationNotFinished copyWith({ @@ -170,6 +176,7 @@ class ServerInstallationNotFinished extends ServerInstallationState { final bool? isServerResetedSecondTime, final bool? isLoading, final Map? dnsMatches, + final CallbackDialogueBranching? installationDialoguePopUp, }) => ServerInstallationNotFinished( providerApiToken: providerApiToken ?? this.providerApiToken, @@ -187,6 +194,8 @@ class ServerInstallationNotFinished extends ServerInstallationState { isServerResetedSecondTime ?? this.isServerResetedSecondTime, isLoading: isLoading ?? this.isLoading, dnsMatches: dnsMatches ?? this.dnsMatches, + installationDialoguePopUp: + installationDialoguePopUp ?? this.installationDialoguePopUp, ); ServerInstallationFinished finish() => ServerInstallationFinished( @@ -200,6 +209,7 @@ class ServerInstallationNotFinished extends ServerInstallationState { isServerStarted: isServerStarted, isServerResetedFirstTime: isServerResetedFirstTime, isServerResetedSecondTime: isServerResetedSecondTime, + installationDialoguePopUp: installationDialoguePopUp, ); } @@ -218,6 +228,7 @@ class ServerInstallationEmpty extends ServerInstallationNotFinished { isServerResetedSecondTime: false, isLoading: false, dnsMatches: null, + installationDialoguePopUp: null, ); } @@ -233,6 +244,7 @@ class ServerInstallationFinished extends ServerInstallationState { required super.isServerStarted, required super.isServerResetedFirstTime, required super.isServerResetedSecondTime, + required super.installationDialoguePopUp, }); @override @@ -246,6 +258,7 @@ class ServerInstallationFinished extends ServerInstallationState { serverDetails, isServerStarted, isServerResetedFirstTime, + installationDialoguePopUp, ]; } @@ -287,6 +300,7 @@ class ServerInstallationRecovery extends ServerInstallationState { isServerStarted: true, isServerResetedFirstTime: true, isServerResetedSecondTime: true, + installationDialoguePopUp: null, ); final RecoveryStep currentStep; final ServerRecoveryCapabilities recoveryCapabilities; @@ -302,7 +316,8 @@ class ServerInstallationRecovery extends ServerInstallationState { serverDetails, isServerStarted, isServerResetedFirstTime, - currentStep + currentStep, + installationDialoguePopUp ]; ServerInstallationRecovery copyWith({ @@ -340,5 +355,6 @@ class ServerInstallationRecovery extends ServerInstallationState { isServerStarted: true, isServerResetedFirstTime: true, isServerResetedSecondTime: true, + installationDialoguePopUp: null, ); }