From 1f3222e9c2a0936a500ab35b1994ecdff185a83a Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Wed, 30 Oct 2024 11:47:56 -0300 Subject: [PATCH 1/6] fix attach drives --- lib/blocs/drive_detail/drive_detail_cubit.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/blocs/drive_detail/drive_detail_cubit.dart b/lib/blocs/drive_detail/drive_detail_cubit.dart index 46b7948e0..a240714ad 100644 --- a/lib/blocs/drive_detail/drive_detail_cubit.dart +++ b/lib/blocs/drive_detail/drive_detail_cubit.dart @@ -290,11 +290,11 @@ class DriveDetailCubit extends Cubit { emit(DriveDetailLoadNotFound()); return; } - - logger.e('An error occured mouting the drive explorer', e); }); - await _folderSubscription?.asFuture(); + await _folderSubscription?.asFuture().catchError((e, stacktrace) { + emit(DriveDetailLoadNotFound()); + }); } List parseEntitiesToDatatableItem({ From 516f220290ecd1a25b0c5a2b63271a06222599bf Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Wed, 30 Oct 2024 12:01:00 -0300 Subject: [PATCH 2/6] bump version and release notes --- android/fastlane/metadata/android/en-US/changelogs/160.txt | 1 + pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 android/fastlane/metadata/android/en-US/changelogs/160.txt diff --git a/android/fastlane/metadata/android/en-US/changelogs/160.txt b/android/fastlane/metadata/android/en-US/changelogs/160.txt new file mode 100644 index 000000000..e0085b262 --- /dev/null +++ b/android/fastlane/metadata/android/en-US/changelogs/160.txt @@ -0,0 +1 @@ +- Fixes an issue attaching drives diff --git a/pubspec.yaml b/pubspec.yaml index 73c39ad21..686aa3a0c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: Secure, permanent storage publish_to: 'none' -version: 2.57.0 +version: 2.57.1 environment: sdk: '>=3.2.0 <4.0.0' From c9b1563309891e54254aae94686079ee1bd0f512 Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Wed, 30 Oct 2024 12:57:32 -0300 Subject: [PATCH 3/6] Update drive_detail_cubit.dart --- lib/blocs/drive_detail/drive_detail_cubit.dart | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/blocs/drive_detail/drive_detail_cubit.dart b/lib/blocs/drive_detail/drive_detail_cubit.dart index a240714ad..9b535a4ae 100644 --- a/lib/blocs/drive_detail/drive_detail_cubit.dart +++ b/lib/blocs/drive_detail/drive_detail_cubit.dart @@ -101,6 +101,8 @@ class DriveDetailCubit extends Cubit { } Future changeDrive(String driveId) async { + logger.d('changeDrive on cubit: $driveId'); + final drive = await _driveDao.driveById(driveId: driveId).getSingleOrNull(); if (drive == null) { @@ -138,15 +140,22 @@ class DriveDetailCubit extends Cubit { _folderSubscription = Rx.combineLatest3( _driveRepository.watchDrive(driveId: driveId), - _driveDao.watchFolderContents( + _driveDao + .watchFolderContents( driveId, orderBy: contentOrderBy, orderingMode: contentOrderingMode, folderId: folderId, - ), + ) + .handleError((e) { + if (e is DriveNotFoundException) { + emit(DriveDetailLoadNotFound()); + } + }), _profileCubit.stream.startWith(ProfileCheckingAvailability()), (drive, folderContents, _) async { if (isClosed) { + logger.d('drive detail cubit is closed'); return; } From bbd06098c1fa9a101da3b53f97a2ab596b5c9f2a Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Wed, 30 Oct 2024 14:19:09 -0300 Subject: [PATCH 4/6] Update drive_attach_cubit.dart --- lib/blocs/drive_attach/drive_attach_cubit.dart | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/blocs/drive_attach/drive_attach_cubit.dart b/lib/blocs/drive_attach/drive_attach_cubit.dart index d98b83c0d..508d008a6 100644 --- a/lib/blocs/drive_attach/drive_attach_cubit.dart +++ b/lib/blocs/drive_attach/drive_attach_cubit.dart @@ -141,15 +141,17 @@ class DriveAttachCubit extends Cubit { profileKey: _profileKey, ); - emit(DriveAttachSuccess()); - /// Wait for the sync to finish before syncing the newly attached drive. - await _syncBloc.waitCurrentSync(); + _syncBloc.waitCurrentSync().then((value) { + logger.d('after sync drives attach'); + + /// Then, sync and select the newly attached drive. + unawaited(_syncBloc.startSync()); - /// Then, sync and select the newly attached drive. - unawaited(_syncBloc - .startSync() - .then((value) => _drivesBloc.selectDrive(driveId))); + _drivesBloc.selectDrive(driveId); + }); + + emit(DriveAttachSuccess()); PlausibleEventTracker.trackAttachDrive( drivePrivacy: drivePrivacy, From ebc7033884be340873a7f33e3c61d3c0c9ae87ed Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Wed, 30 Oct 2024 14:22:37 -0300 Subject: [PATCH 5/6] fix --- lib/blocs/drive_attach/drive_attach_cubit.dart | 4 ++++ lib/blocs/drives/drives_cubit.dart | 4 ++++ lib/components/drive_attach_form.dart | 2 ++ lib/components/new_button/new_button.dart | 15 ++++++++++++--- lib/pages/app_router_delegate.dart | 1 + lib/pages/drive_detail/drive_detail_page.dart | 4 ++++ 6 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/blocs/drive_attach/drive_attach_cubit.dart b/lib/blocs/drive_attach/drive_attach_cubit.dart index 508d008a6..8a51f2c39 100644 --- a/lib/blocs/drive_attach/drive_attach_cubit.dart +++ b/lib/blocs/drive_attach/drive_attach_cubit.dart @@ -24,6 +24,7 @@ class DriveAttachCubit extends Cubit { final SyncCubit _syncBloc; final DrivesCubit _drivesBloc; final SecretKey? _profileKey; + final DriveDetailCubit _driveDetailCubit; final driveNameController = TextEditingController(); final driveKeyController = TextEditingController(); @@ -40,11 +41,13 @@ class DriveAttachCubit extends Cubit { required DriveDao driveDao, required SyncCubit syncBloc, required DrivesCubit drivesBloc, + required DriveDetailCubit driveDetailCubit, }) : _arweave = arweave, _driveDao = driveDao, _syncBloc = syncBloc, _drivesBloc = drivesBloc, _profileKey = profileKey, + _driveDetailCubit = driveDetailCubit, super(DriveAttachInitial()) { initializeForm( driveId: initialDriveId, @@ -149,6 +152,7 @@ class DriveAttachCubit extends Cubit { unawaited(_syncBloc.startSync()); _drivesBloc.selectDrive(driveId); + _driveDetailCubit.changeDrive(driveId); }); emit(DriveAttachSuccess()); diff --git a/lib/blocs/drives/drives_cubit.dart b/lib/blocs/drives/drives_cubit.dart index dad88a7a9..2b26dcb01 100644 --- a/lib/blocs/drives/drives_cubit.dart +++ b/lib/blocs/drives/drives_cubit.dart @@ -7,6 +7,7 @@ import 'package:ardrive/blocs/prompt_to_snapshot/prompt_to_snapshot_event.dart'; import 'package:ardrive/core/activity_tracker.dart'; import 'package:ardrive/models/models.dart'; import 'package:ardrive/user/repositories/user_preferences_repository.dart'; +import 'package:ardrive/utils/logger.dart'; import 'package:ardrive/utils/user_utils.dart'; import 'package:ardrive_utils/ardrive_utils.dart'; import 'package:drift/drift.dart'; @@ -125,6 +126,7 @@ class DrivesCubit extends Cubit { } void selectDrive(String driveId) { + logger.d('selectDrive: $driveId'); final profileIsLoggedIn = _profileCubit.state is ProfileLoggedIn; final canCreateNewDrive = profileIsLoggedIn; final DrivesState state; @@ -141,6 +143,8 @@ class DrivesCubit extends Cubit { } _userPreferencesRepository.saveLastSelectedDriveId(driveId); + + logger.d('selectDrive: $driveId, state: $state'); emit(state); } diff --git a/lib/components/drive_attach_form.dart b/lib/components/drive_attach_form.dart index df51d49df..699e0d201 100644 --- a/lib/components/drive_attach_form.dart +++ b/lib/components/drive_attach_form.dart @@ -20,6 +20,7 @@ Future attachDrive({ DriveID? driveId, String? driveName, SecretKey? driveKey, + required DriveDetailCubit driveDetailCubit, }) { final profileState = context.read().state; final profileKey = @@ -30,6 +31,7 @@ Future attachDrive({ context, content: BlocProvider( create: (context) => DriveAttachCubit( + driveDetailCubit: driveDetailCubit, initialDriveId: driveId, initialDriveName: driveName, initialDriveKey: driveKey, diff --git a/lib/components/new_button/new_button.dart b/lib/components/new_button/new_button.dart index 4da43b896..c46c6cbd9 100644 --- a/lib/components/new_button/new_button.dart +++ b/lib/components/new_button/new_button.dart @@ -320,7 +320,10 @@ class NewButton extends StatelessWidget { return [ ArDriveNewButtonItem( - onClick: () => attachDrive(context: context), + onClick: () => attachDrive( + context: context, + driveDetailCubit: context.read(), + ), name: appLocalizations.attachDrive, icon: ArDriveIcons.iconAttachDrive(size: defaultIconSize), ), @@ -440,7 +443,10 @@ class NewButton extends StatelessWidget { } else { return [ ArDriveNewButtonItem( - onClick: () => attachDrive(context: context), + onClick: () => attachDrive( + context: context, + driveDetailCubit: context.read(), + ), name: appLocalizations.attachDrive, icon: ArDriveIcons.iconAttachDrive(size: defaultIconSize), ), @@ -538,7 +544,10 @@ class NewButton extends StatelessWidget { } else { return [ ArDriveNewButtonItem( - onClick: () => attachDrive(context: context), + onClick: () => attachDrive( + context: context, + driveDetailCubit: context.read(), + ), name: appLocalizations.attachDrive, icon: ArDriveIcons.iconAttachDrive(size: defaultIconSize), ), diff --git a/lib/pages/app_router_delegate.dart b/lib/pages/app_router_delegate.dart index bd9016cb5..b2d1f131d 100644 --- a/lib/pages/app_router_delegate.dart +++ b/lib/pages/app_router_delegate.dart @@ -222,6 +222,7 @@ class AppRouterDelegate extends RouterDelegate driveId: driveId, driveName: driveName, driveKey: sharedDriveKey, + driveDetailCubit: context.read(), ).then((_) { sharedDriveKey = null; sharedRawDriveKey = null; diff --git a/lib/pages/drive_detail/drive_detail_page.dart b/lib/pages/drive_detail/drive_detail_page.dart index fdb05db35..c21d70149 100644 --- a/lib/pages/drive_detail/drive_detail_page.dart +++ b/lib/pages/drive_detail/drive_detail_page.dart @@ -132,7 +132,9 @@ class _DriveDetailPageState extends State { child: BlocListener( listener: (context, state) { if (state is DrivesLoadSuccess) { + logger.d('drive detail listener: ${state.selectedDriveId}'); if (state.userDrives.isNotEmpty) { + logger.d('drive detail listener: ${state.selectedDriveId}'); final driveDetailState = context.read().state; if (driveDetailState is DriveDetailLoadSuccess && @@ -140,6 +142,8 @@ class _DriveDetailPageState extends State { return; } + logger.d('changeDrive on listener: ${state.selectedDriveId}'); + context .read() .changeDrive(state.selectedDriveId!); From e9c56f7523615372edfc8fccdb0ded5585fdaf68 Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Wed, 30 Oct 2024 14:38:18 -0300 Subject: [PATCH 6/6] fix attach drives --- test/blocs/drive_attach_cubit_test.dart | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/blocs/drive_attach_cubit_test.dart b/test/blocs/drive_attach_cubit_test.dart index 2633bd2c6..d62b199dd 100644 --- a/test/blocs/drive_attach_cubit_test.dart +++ b/test/blocs/drive_attach_cubit_test.dart @@ -25,6 +25,7 @@ void main() { late SyncCubit syncBloc; late DrivesCubit drivesBloc; late DriveAttachCubit driveAttachCubit; + late MockDriveDetailCubit driveDetailCubit; const validPrivateDriveId = 'valid-private-drive-id'; const validPrivateDriveKeyBase64 = @@ -54,7 +55,9 @@ void main() { arweave = MockArweaveService(); syncBloc = MockSyncBloc(); drivesBloc = MockDrivesCubit(); - when(() => arweave.getLatestDriveEntityWithId(validDriveId)).thenAnswer( + driveDetailCubit = MockDriveDetailCubit(); + + when(() => arweave.getLatestDriveEntityWithId(validDriveId)).thenAnswer( (_) => Future.value( DriveEntity( id: validDriveId, @@ -102,6 +105,7 @@ void main() { syncBloc: syncBloc, drivesBloc: drivesBloc, profileKey: profileKey, + driveDetailCubit: driveDetailCubit, ); }); @@ -193,6 +197,7 @@ void main() { initialDriveId: validPrivateDriveId, initialDriveName: validDriveName, initialDriveKey: validPrivateDriveKey, + driveDetailCubit: driveDetailCubit, ), expect: () => [ DriveAttachPrivate(),