Skip to content

Commit

Permalink
fest(auto-update manifests)
Browse files Browse the repository at this point in the history
- finish implementation for desktop
  • Loading branch information
thiagocarvalhodev committed Oct 9, 2024
1 parent 4597f37 commit 7336cab
Show file tree
Hide file tree
Showing 5 changed files with 629 additions and 271 deletions.
36 changes: 22 additions & 14 deletions lib/blocs/upload/upload_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,18 @@ class UploadCubit extends Cubit<UploadState> {
final List<FileEntry> _selectedManifestFiles = [];

UploadMethod? _manifestUploadMethod;
UploadPaymentMethodInfo? _manifestUploadPaymentMethodInfo;
bool? _manifestUploadCanUpload;

bool _isManifestsUploadCancelled = false;

void selectManifestFile(FileEntry file) {
final readyState = state as UploadReady;

final newReadyState = readyState.copyWith(
selectedManifests: List.of(_selectedManifestFiles)..add(file));

_selectedManifestFiles.add(file);

emit((state as UploadReady)
.copyWith(selectedManifests: _selectedManifestFiles));
emit(newReadyState);
}

void unselectManifestFile(FileEntry file) {
Expand All @@ -124,8 +126,6 @@ class UploadCubit extends Cubit<UploadState> {
void setManifestUploadMethod(
UploadMethod method, UploadPaymentMethodInfo info, bool canUpload) {
_manifestUploadMethod = method;
_manifestUploadPaymentMethodInfo = info;
_manifestUploadCanUpload = canUpload;
}

Future<void> prepareManifestUpload() async {
Expand Down Expand Up @@ -315,7 +315,7 @@ class UploadCubit extends Cubit<UploadState> {
),
);

emit(UploadReviewWithArnsName(readyState: readyState));
emit(UploadReview(readyState: readyState));
}

void changeShowArnsNameSelection(bool showArnsNameSelection) {
Expand Down Expand Up @@ -367,6 +367,8 @@ class UploadCubit extends Cubit<UploadState> {
UploadPaymentMethodInfo paymentInfo,
bool canUpload,
) async {
bool showSettings = _manifestFiles.isNotEmpty;

logger.d('Upload method set to $method');
_uploadMethod = method;

Expand Down Expand Up @@ -397,7 +399,8 @@ class UploadCubit extends Cubit<UploadState> {
arnsCheckboxChecked: _showArnsNameSelectionCheckBoxValue,
totalSize: await _getTotalSize(),
selectedManifests: _selectedManifestFiles,
showSettings: true,
showSettings: showSettings,
canShowSettings: showSettings,
manifestFiles: _manifestFiles,
),
);
Expand Down Expand Up @@ -438,8 +441,9 @@ class UploadCubit extends Cubit<UploadState> {
arnsCheckboxChecked: _showArnsNameSelectionCheckBoxValue,
totalSize: await _getTotalSize(),
selectedManifests: _selectedManifestFiles,
showSettings: true,
showSettings: showSettings,
manifestFiles: _manifestFiles,
canShowSettings: showSettings,
),
);
}
Expand All @@ -450,6 +454,8 @@ class UploadCubit extends Cubit<UploadState> {
if (state is UploadReady) {
if (_showArnsNameSelectionCheckBoxValue) {
showArnsNameSelection(state as UploadReady);
} else if (_selectedManifestFiles.isNotEmpty) {
emit(UploadReview(readyState: state as UploadReady));
} else {
final readyState = state as UploadReady;
startUpload(
Expand Down Expand Up @@ -533,8 +539,8 @@ class UploadCubit extends Cubit<UploadState> {
licenseCategory: licenseCategory,
);
emit(prevState);
} else if (state is UploadReviewWithArnsName) {
final reviewWithArnsName = state as UploadReviewWithArnsName;
} else if (state is UploadReview) {
final reviewWithArnsName = state as UploadReview;
final readyState = reviewWithArnsName.readyState.copyWith(
showArnsNameSelection: false,
);
Expand All @@ -553,7 +559,7 @@ class UploadCubit extends Cubit<UploadState> {
reviewWithLicense.readyState.paymentInfo.uploadPlanForTurbo,
licenseStateConfigured: reviewWithLicense.licenseState,
);
} else if (state is UploadReviewWithArnsName) {
} else if (state is UploadReview) {
startUploadWithArnsName();
}
}
Expand Down Expand Up @@ -931,7 +937,9 @@ class UploadCubit extends Cubit<UploadState> {
);

_manifestFiles = await _manifestRepository.getManifestFilesInFolder(
folderId: _targetFolder.id);
folderId: _targetFolder.id,
driveId: _targetDrive.id,
);

// if there are no files that can be used to generate a thumbnail, we disable the option
if (!containsSupportedImageTypeForThumbnailGeneration) {
Expand Down Expand Up @@ -965,7 +973,7 @@ class UploadCubit extends Cubit<UploadState> {

/// Upload
void startUploadWithArnsName() {
final reviewWithArnsName = state as UploadReviewWithArnsName;
final reviewWithArnsName = state as UploadReview;

startUpload(
uploadPlanForAr:
Expand Down
20 changes: 7 additions & 13 deletions lib/blocs/upload/upload_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class UploadReady extends UploadState {
final List<FileEntry> selectedManifests;
final List<FileEntry> manifestFiles;
final bool showSettings;
final bool canShowSettings;

final bool isArConnect;

Expand All @@ -129,6 +130,7 @@ class UploadReady extends UploadState {
required this.totalSize,
required this.selectedManifests,
required this.showSettings,
required this.canShowSettings,
required this.manifestFiles,
});

Expand All @@ -151,6 +153,7 @@ class UploadReady extends UploadState {
int? totalSize,
List<FileEntry>? selectedManifests,
List<FileEntry>? manifestFiles,
bool? canShowSettings,
}) {
return UploadReady(
loadingArNSNames: loadingArNSNames ?? this.loadingArNSNames,
Expand All @@ -171,21 +174,12 @@ class UploadReady extends UploadState {
selectedManifests: selectedManifests ?? this.selectedManifests,
showSettings: showSettings ?? this.showSettings,
manifestFiles: manifestFiles ?? this.manifestFiles,
canShowSettings: canShowSettings ?? this.canShowSettings,
);
}

@override
List<Object?> get props => [
paymentInfo,
isNextButtonEnabled,
showArnsNameSelection,
loadingArNSNamesError,
loadingArNSNames,
showArnsCheckbox,
arnsCheckboxChecked,
showSettings,
isArConnect,
];
List<Object?> get props => [UniqueKey()];

@override
toString() => 'UploadReady { paymentInfo: $paymentInfo }';
Expand Down Expand Up @@ -221,10 +215,10 @@ class UploadConfiguringLicense extends UploadState {
'UploadConfiguringLicense { paymentInfo: ${readyState.paymentInfo} }';
}

class UploadReviewWithArnsName extends UploadState {
class UploadReview extends UploadState {
final UploadReady readyState;

UploadReviewWithArnsName({required this.readyState});
UploadReview({required this.readyState});
}

/// [UploadReviewWithLicense] means that the upload + license is being reviewed by the user and awaiting confirmation to begin upload.
Expand Down
Loading

0 comments on commit 7336cab

Please sign in to comment.