From b23dc01fa1c7dd4410b1a330b26f7ca88d775dcb Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Fri, 13 Sep 2024 14:59:58 -0300 Subject: [PATCH 1/2] feat(arns): add close button --- .../assign_name_bloc/assign_name_bloc.dart | 9 ++++--- .../assign_name_bloc/assign_name_event.dart | 2 ++ .../assign_name_bloc/assign_name_state.dart | 2 ++ lib/arns/presentation/assign_name_modal.dart | 26 ++++++++++++++++--- lib/blocs/upload/upload_cubit.dart | 26 +++++++++++++++++++ lib/blocs/upload/upload_state.dart | 1 + lib/components/upload_form.dart | 11 ++++++++ lib/main.dart | 1 + .../ardrive_ui/lib/src/components/modal.dart | 10 ++++++- 9 files changed, 81 insertions(+), 7 deletions(-) diff --git a/lib/arns/presentation/assign_name_bloc/assign_name_bloc.dart b/lib/arns/presentation/assign_name_bloc/assign_name_bloc.dart index 2a508e781a..36d8a69adb 100644 --- a/lib/arns/presentation/assign_name_bloc/assign_name_bloc.dart +++ b/lib/arns/presentation/assign_name_bloc/assign_name_bloc.dart @@ -28,9 +28,8 @@ class AssignNameBloc extends Bloc { final walletAddress = await _auth.getWalletAddress(); - final names = await _arnsRepository.getAntRecordsForWallet( - walletAddress!, - ); + final names = await _arnsRepository.getAntRecordsForWallet(walletAddress!, + update: true); if (names.isEmpty) { emit(AssignNameEmptyState()); @@ -152,5 +151,9 @@ class AssignNameBloc extends Bloc { selectedUndername: _selectedUndername, )); }); + + on((event, emit) async { + emit(EmptySelection()); + }); } } diff --git a/lib/arns/presentation/assign_name_bloc/assign_name_event.dart b/lib/arns/presentation/assign_name_bloc/assign_name_event.dart index a5fd55362a..369f23dc63 100644 --- a/lib/arns/presentation/assign_name_bloc/assign_name_event.dart +++ b/lib/arns/presentation/assign_name_bloc/assign_name_event.dart @@ -15,6 +15,8 @@ final class LoadNames extends AssignNameEvent { }); } +final class CloseAssignName extends AssignNameEvent {} + final class SelectName extends AssignNameEvent { final ANTRecord name; diff --git a/lib/arns/presentation/assign_name_bloc/assign_name_state.dart b/lib/arns/presentation/assign_name_bloc/assign_name_state.dart index 02add380af..d2a8bc7c60 100644 --- a/lib/arns/presentation/assign_name_bloc/assign_name_state.dart +++ b/lib/arns/presentation/assign_name_bloc/assign_name_state.dart @@ -92,3 +92,5 @@ final class SelectionConfirmed extends AssignNameState { final class LoadingUndernames extends AssignNameState {} class SelectionFailed extends AssignNameState {} + +final class EmptySelection extends AssignNameState {} diff --git a/lib/arns/presentation/assign_name_modal.dart b/lib/arns/presentation/assign_name_modal.dart index 3155d073f4..388ad8dd80 100644 --- a/lib/arns/presentation/assign_name_modal.dart +++ b/lib/arns/presentation/assign_name_modal.dart @@ -3,10 +3,12 @@ import 'package:ardrive/arns/domain/arns_repository.dart'; import 'package:ardrive/arns/presentation/assign_name_bloc/assign_name_bloc.dart'; import 'package:ardrive/authentication/ardrive_auth.dart'; +import 'package:ardrive/blocs/blocs.dart'; import 'package:ardrive/blocs/drive_detail/drive_detail_cubit.dart'; import 'package:ardrive/misc/resources.dart'; import 'package:ardrive/pages/drive_detail/models/data_table_item.dart'; import 'package:ardrive/theme/theme.dart'; +import 'package:ardrive/utils/logger.dart'; import 'package:ardrive/utils/open_url.dart'; import 'package:ardrive/utils/show_general_dialog.dart'; import 'package:ardrive_ui/ardrive_ui.dart'; @@ -50,11 +52,15 @@ class AssignArNSNameModal extends StatelessWidget { this.updateARNSRecords = true, this.customLoadingText, this.customNameSelectionTitle, + this.onEmptySelection, + this.canClose = true, }); final FileDataTableItem? file; final DriveDetailCubit driveDetailCubit; final Function(SelectionConfirmed)? onSelectionConfirmed; + final Function(EmptySelection)? onEmptySelection; + final bool canClose; final bool justSelectName; final bool updateARNSRecords; final String? customLoadingText; @@ -77,6 +83,8 @@ class AssignArNSNameModal extends StatelessWidget { onSelectionConfirmed: onSelectionConfirmed, customLoadingText: customLoadingText, customNameSelectionTitle: customNameSelectionTitle, + onEmptySelection: onEmptySelection, + canClose: canClose, ), ); } @@ -91,14 +99,18 @@ class _AssignArNSNameModal extends StatefulWidget { this.onSelectionConfirmed, this.customLoadingText, this.customNameSelectionTitle, + this.onEmptySelection, + this.canClose = true, }); final DriveDetailCubit driveDetailCubit; final bool justSelectName; final FileDataTableItem? file; final Function(SelectionConfirmed)? onSelectionConfirmed; + final Function(EmptySelection)? onEmptySelection; final String? customLoadingText; final String? customNameSelectionTitle; + final bool canClose; @override State<_AssignArNSNameModal> createState() => _AssignArNSNameModalState(); @@ -129,6 +141,10 @@ class _AssignArNSNameModalState extends State<_AssignArNSNameModal> { if (current is SelectionConfirmed) { widget.onSelectionConfirmed?.call(current); } + + if (current is EmptySelection) { + widget.onEmptySelection?.call(current); + } }, buildWhen: (previous, current) { if (current is LoadingUndernames) { @@ -139,10 +155,14 @@ class _AssignArNSNameModalState extends State<_AssignArNSNameModal> { }, builder: (context, state) { return ArDriveStandardModalNew( - hasCloseButton: state is NamesLoaded || - state is UndernamesLoaded || - state is AssignNameEmptyState, + hasCloseButton: state is! ConfirmingSelection, title: _getTitle(state), + close: widget.canClose + ? null + : () { + logger.d('Closing assign name modal'); + context.read().add(CloseAssignName()); + }, width: (state is! NamesLoaded && state is! UndernamesLoaded && state is! LoadingNames) diff --git a/lib/blocs/upload/upload_cubit.dart b/lib/blocs/upload/upload_cubit.dart index 396773f988..0c758da480 100644 --- a/lib/blocs/upload/upload_cubit.dart +++ b/lib/blocs/upload/upload_cubit.dart @@ -228,6 +228,32 @@ class UploadCubit extends Cubit { } } + void cancelArnsNameSelection() { + if (state is UploadReady) { + logger.d('Cancelling ARNS name selection'); + + final readyState = state as UploadReady; + + showArnsNameSelectionCheckBoxValue = false; + + emit(readyState.copyWith( + showArnsNameSelection: false, + loadingArNSNames: false, + loadingArNSNamesError: false, + showArnsCheckbox: true, + )); + } else if (state is UploadReviewWithLicense) { + final reviewWithLicense = state as UploadReviewWithLicense; + final readyState = reviewWithLicense.readyState.copyWith( + showArnsNameSelection: false, + loadingArNSNames: false, + loadingArNSNamesError: false, + showArnsCheckbox: true, + ); + emit(readyState); + } + } + void reviewBack() { if (state is UploadReviewWithLicense) { final reviewWithLicense = state as UploadReviewWithLicense; diff --git a/lib/blocs/upload/upload_state.dart b/lib/blocs/upload/upload_state.dart index aeae8113ea..a855aa9389 100644 --- a/lib/blocs/upload/upload_state.dart +++ b/lib/blocs/upload/upload_state.dart @@ -155,6 +155,7 @@ class UploadReady extends UploadState { loadingArNSNamesError, loadingArNSNames, showArnsCheckbox, + ]; @override diff --git a/lib/components/upload_form.dart b/lib/components/upload_form.dart index 8425227a04..93a81f82cf 100644 --- a/lib/components/upload_form.dart +++ b/lib/components/upload_form.dart @@ -521,6 +521,8 @@ class _UploadFormState extends State { ), ); } else if (state is UploadReady) { + logger.d('UploadReady state: ${state.showArnsNameSelection}'); + if (state.showArnsNameSelection) { return AssignArNSNameModal( driveDetailCubit: widget.driveDetailCubit, @@ -529,6 +531,11 @@ class _UploadFormState extends State { context.read().selectUndername( name.selectedName, name.selectedUndername); }, + canClose: false, + onEmptySelection: (emptySelection) { + logger.d('Cancelling ARNS name selection'); + context.read().cancelArnsNameSelection(); + }, ); } @@ -777,6 +784,10 @@ class _UploadFormState extends State { undername: name.selectedUndername, ); }, + canClose: false, + onEmptySelection: (emptySelection) { + context.read().cancelArnsNameSelection(); + }, ); } diff --git a/lib/main.dart b/lib/main.dart index 1c6556f794..e3c31b42a3 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -83,6 +83,7 @@ void main() async { await _startApp(); }, (error, stackTrace) async { logger.e('Error caught.', error, stackTrace); + logger.d('Error: ${error.toString()}'); }); } diff --git a/packages/ardrive_ui/lib/src/components/modal.dart b/packages/ardrive_ui/lib/src/components/modal.dart index 3f8d7e05ac..e16ad851f7 100644 --- a/packages/ardrive_ui/lib/src/components/modal.dart +++ b/packages/ardrive_ui/lib/src/components/modal.dart @@ -684,6 +684,7 @@ class ArDriveStandardModalNew extends StatelessWidget { this.actions, this.width, this.hasCloseButton = false, + this.close, }); final String? title; @@ -692,6 +693,7 @@ class ArDriveStandardModalNew extends StatelessWidget { final Widget? content; final double? width; final bool hasCloseButton; + final Function()? close; @override Widget build(BuildContext context) { @@ -732,7 +734,13 @@ class ArDriveStandardModalNew extends StatelessWidget { if (hasCloseButton) ArDriveClickArea( child: GestureDetector( - onTap: () => Navigator.pop(context), + onTap: () { + if (close != null) { + close?.call(); + } else { + Navigator.pop(context); + } + }, child: const Align( alignment: Alignment.centerRight, child: ArDriveIcon( From 9d274cd1dbc2353e9cbb6dfa7bd210b2faee7c09 Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:01:06 -0300 Subject: [PATCH 2/2] Update assign_name_bloc.dart --- lib/arns/presentation/assign_name_bloc/assign_name_bloc.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/arns/presentation/assign_name_bloc/assign_name_bloc.dart b/lib/arns/presentation/assign_name_bloc/assign_name_bloc.dart index 36d8a69adb..088a65df99 100644 --- a/lib/arns/presentation/assign_name_bloc/assign_name_bloc.dart +++ b/lib/arns/presentation/assign_name_bloc/assign_name_bloc.dart @@ -28,8 +28,7 @@ class AssignNameBloc extends Bloc { final walletAddress = await _auth.getWalletAddress(); - final names = await _arnsRepository.getAntRecordsForWallet(walletAddress!, - update: true); + final names = await _arnsRepository.getAntRecordsForWallet(walletAddress!); if (names.isEmpty) { emit(AssignNameEmptyState());