Skip to content

Commit

Permalink
Merge pull request #1787 from ardriveapp/PE-6426-unable-to-open-share…
Browse files Browse the repository at this point in the history
…d-drives-from-mobile

PE-6426: unable to open shared drives from mobile
  • Loading branch information
thiagocarvalhodev authored Jul 16, 2024
2 parents 912803d + 38feaf2 commit dc825f5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
11 changes: 8 additions & 3 deletions lib/blocs/drive_attach/drive_attach_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,15 @@ class DriveAttachCubit extends Cubit<DriveAttachState> {
profileKey: _profileKey,
);

_drivesBloc.selectDrive(driveId);

emit(DriveAttachSuccess());
unawaited(_syncBloc.startSync());

/// Wait for the sync to finish before syncing the newly attached drive.
await _syncBloc.waitCurrentSync();

/// Then, sync and select the newly attached drive.
unawaited(_syncBloc
.startSync()
.then((value) => _drivesBloc.selectDrive(driveId)));

PlausibleEventTracker.trackAttachDrive(
drivePrivacy: drivePrivacy,
Expand Down
13 changes: 7 additions & 6 deletions lib/components/drive_attach_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ class _DriveAttachFormState extends State<DriveAttachForm> {
if (state is DriveAttachInvalidDriveKey) {
showArDriveDialog(
context,
content: ArDriveStandardModal(
content: ArDriveStandardModalNew(
title: appLocalizationsOf(context).error,
description: appLocalizationsOf(context).invalidKeyFile,
),
);
} else if (state is DriveAttachDriveNotFound) {
showArDriveDialog(
context,
content: ArDriveStandardModal(
content: ArDriveStandardModalNew(
title: appLocalizationsOf(context).error,
description: appLocalizationsOf(context)
.validationAttachDriveCouldNotBeFound,
Expand All @@ -110,18 +110,19 @@ class _DriveAttachFormState extends State<DriveAttachForm> {
builder: (context, state) {
if (state is DriveAttachInProgress) {
return ProgressDialog(
useNewArDriveUI: true,
title: appLocalizationsOf(context).attachingDriveEmphasized,
);
}

return ArDriveStandardModal(
return ArDriveStandardModalNew(
title: appLocalizationsOf(context).attachDriveEmphasized,
content: SizedBox(
width: kMediumDialogWidth,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ArDriveTextField(
ArDriveTextFieldNew(
controller:
context.read<DriveAttachCubit>().driveIdController,
autofocus: true,
Expand All @@ -140,7 +141,7 @@ class _DriveAttachFormState extends State<DriveAttachForm> {
),
const SizedBox(height: 16),
if (state is DriveAttachPrivate)
ArDriveTextField(
ArDriveTextFieldNew(
controller:
context.read<DriveAttachCubit>().driveKeyController,
autofocus: true,
Expand All @@ -156,7 +157,7 @@ class _DriveAttachFormState extends State<DriveAttachForm> {
hintText: appLocalizationsOf(context).driveKey,
),
const SizedBox(height: 16),
ArDriveTextField(
ArDriveTextFieldNew(
controller:
context.read<DriveAttachCubit>().driveNameController,
hintText: appLocalizationsOf(context).driveName,
Expand Down
3 changes: 3 additions & 0 deletions lib/pages/drive_detail/drive_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ class _DriveDetailPageState extends State<DriveDetailPage> {
}
},
child: BlocBuilder<DriveDetailCubit, DriveDetailState>(
buildWhen: (previous, current) {
return context.read<SyncCubit>().state is! SyncInProgress;
},
builder: (context, driveDetailState) {
if (driveDetailState is DriveDetailLoadInProgress) {
return const Center(child: CircularProgressIndicator());
Expand Down
15 changes: 11 additions & 4 deletions lib/sync/domain/cubit/sync_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ class SyncCubit extends Cubit<SyncState> {
restartArConnectSyncOnFocus();
}

/// Waits for the current sync to finish.
Future<void> waitCurrentSync() async {
if (state is! SyncIdle) {
await for (var state in stream) {
if (state is SyncIdle || state is SyncFailure) {
break;
}
}
}
}

void createSyncStream() async {
logger.d('Creating sync stream to periodically call sync automatically');

Expand Down Expand Up @@ -206,12 +217,8 @@ class SyncCubit extends Cubit<SyncState> {
);
}

final currentBlockHeight = await _syncRepository.getCurrentBlockHeight();

_promptToSnapshotBloc.add(const SyncRunning(isRunning: true));

logger.d('Current block height number $currentBlockHeight');

await for (var syncProgress in _syncRepository.syncAllDrives(
wallet: wallet,
password: password,
Expand Down
5 changes: 4 additions & 1 deletion test/blocs/drive_attach_cubit_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void main() {
arweave = MockArweaveService();
syncBloc = MockSyncBloc();
drivesBloc = MockDrivesCubit();
when(() => arweave.getLatestDriveEntityWithId(validDriveId)).thenAnswer(
when(() => arweave.getLatestDriveEntityWithId(validDriveId)).thenAnswer(
(_) => Future.value(
DriveEntity(
id: validDriveId,
Expand Down Expand Up @@ -93,6 +93,9 @@ void main() {

when(() => syncBloc.startSync()).thenAnswer((_) => Future.value(null));

when(() => syncBloc.waitCurrentSync())
.thenAnswer((_) => Future.value(null));

driveAttachCubit = DriveAttachCubit(
arweave: arweave,
driveDao: driveDao,
Expand Down

0 comments on commit dc825f5

Please sign in to comment.