Skip to content

Commit

Permalink
Merge pull request #1792 from ardriveapp/dev
Browse files Browse the repository at this point in the history
PE-6438: Release v2.49.3
  • Loading branch information
thiagocarvalhodev authored Jul 17, 2024
2 parents c9a637a + 7b52e00 commit 9cf5ce1
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 35 deletions.
1 change: 1 addition & 0 deletions android/fastlane/metadata/android/en-US/changelogs/139.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Improves handling of a few common errors
50 changes: 21 additions & 29 deletions lib/blocs/drive_detail/drive_detail_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:ardrive/core/activity_tracker.dart';
import 'package:ardrive/models/models.dart';
import 'package:ardrive/pages/pages.dart';
import 'package:ardrive/services/services.dart';
import 'package:ardrive/sync/domain/cubit/sync_cubit.dart';
import 'package:ardrive/utils/constants.dart';
import 'package:ardrive/utils/local_key_value_store.dart';
import 'package:ardrive/utils/logger.dart';
Expand All @@ -30,6 +31,7 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {
final ArDriveAuth _auth;
final ActivityTracker _activityTracker;
final BreadcrumbBuilder _breadcrumbBuilder;
final SyncCubit _syncCubit;

StreamSubscription? _folderSubscription;
final _defaultAvailableRowsPerPage = [25, 50, 75, 100];
Expand All @@ -54,12 +56,14 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {
required ActivityTracker activityTracker,
required ArDriveAuth auth,
required BreadcrumbBuilder breadcrumbBuilder,
required SyncCubit syncCubit,
}) : _profileCubit = profileCubit,
_activityTracker = activityTracker,
_driveDao = driveDao,
_auth = auth,
_configService = configService,
_breadcrumbBuilder = breadcrumbBuilder,
_syncCubit = syncCubit,
super(DriveDetailLoadInProgress()) {
if (driveId.isEmpty) {
return;
Expand Down Expand Up @@ -97,6 +101,9 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {
DriveOrder contentOrderBy = DriveOrder.name,
OrderingMode contentOrderingMode = OrderingMode.asc,
}) async {
/// always wait for the current sync to finish before opening a new folder
await _syncCubit.waitCurrentSync();

try {
_selectedItem = null;
_allImagesOfCurrentFolder = null;
Expand All @@ -106,35 +113,6 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {
emit(DriveDetailLoadInProgress());

await _folderSubscription?.cancel();
// For attaching drives. If drive is not found, emit state to prompt drive attach
await _driveDao
.driveById(driveId: driveId)
.getSingleOrNull()
.then((value) async {
logger.d('Drive with id $driveId found');

if (value == null) {
logger.d('Drive with id $driveId not found');

emit(DriveDetailLoadNotFound());
return;
}

try {
await _driveDao
.folderById(
driveId: driveId,
folderId: folderId ?? value.rootFolderId,
)
.getSingle();
} catch (e) {
logger
.d('Folder with id ${folderId ?? value.rootFolderId} not found');

emit(DriveInitialLoading());
return;
}
});

_folderSubscription =
Rx.combineLatest3<Drive, FolderWithContents, ProfileState, void>(
Expand Down Expand Up @@ -259,6 +237,20 @@ class DriveDetailCubit extends Cubit<DriveDetailState> {
} catch (e, stacktrace) {
logger.e('An error occured mouting the drive explorer', e, stacktrace);
}

_folderSubscription?.onError((e) {
if (e is FolderNotFoundInDriveException) {
emit(DriveInitialLoading());
return;
}

if (e is DriveNotFoundException) {
emit(DriveDetailLoadNotFound());
return;
}

logger.e('An error occured mouting the drive explorer', e);
});
}

List<ArDriveDataTableItem> parseEntitiesToDatatableItem({
Expand Down
38 changes: 33 additions & 5 deletions lib/models/daos/drive_dao/drive_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -362,16 +362,21 @@ class DriveDao extends DatabaseAccessor<Database> with _$DriveDaoMixin {
if (folderId == null) {
return driveById(driveId: driveId).watchSingleOrNull().switchMap((drive) {
if (drive == null) {
throw Exception('Drive with id $driveId not found');
throw DriveNotFoundException(driveId);
}

return folderById(driveId: driveId, folderId: drive.rootFolderId)
.watchSingleOrNull()
.switchMap((folder) {
return watchFolderContents(driveId,
folderId: folder!.id,
orderBy: orderBy,
orderingMode: orderingMode);
if (folder == null) {
throw FolderNotFoundInDriveException(driveId, drive.rootFolderId);
}
return watchFolderContents(
driveId,
folderId: folder.id,
orderBy: orderBy,
orderingMode: orderingMode,
);
});
});
}
Expand Down Expand Up @@ -656,3 +661,26 @@ class DriveDao extends DatabaseAccessor<Database> with _$DriveDaoMixin {
});
}
}

class FolderNotFoundInDriveException implements Exception {
final String driveId;
final String folderId;

FolderNotFoundInDriveException(this.driveId, this.folderId);

@override
String toString() {
return 'Folder with id $folderId not found in drive with id $driveId';
}
}

class DriveNotFoundException implements Exception {
final String driveId;

DriveNotFoundException(this.driveId);

@override
String toString() {
return 'Drive with id $driveId not found';
}
}
1 change: 1 addition & 0 deletions lib/pages/app_router_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class AppRouterDelegate extends RouterDelegate<AppRoutePath>
breadcrumbBuilder: BreadcrumbBuilder(
context.read<FolderRepository>(),
),
syncCubit: context.read<SyncCubit>(),
),
child: MultiBlocListener(
listeners: [
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Secure, permanent storage

publish_to: 'none'

version: 2.49.2
version: 2.49.3

environment:
sdk: '>=3.2.0 <4.0.0'
Expand Down

0 comments on commit 9cf5ce1

Please sign in to comment.