mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-08 14:07:49 -06:00
Hooked notifications to status changes on document upload - some refactorings
This commit is contained in:
@@ -55,17 +55,16 @@ class DocumentUploadCubit extends Cubit<DocumentUploadState> {
|
||||
));
|
||||
}
|
||||
|
||||
Future<void> upload(
|
||||
Future<String?> upload(
|
||||
Uint8List bytes, {
|
||||
required String filename,
|
||||
required String title,
|
||||
required void Function(DocumentModel document)? onConsumptionFinished,
|
||||
int? documentType,
|
||||
int? correspondent,
|
||||
Iterable<int> tags = const [],
|
||||
DateTime? createdAt,
|
||||
}) async {
|
||||
await _documentApi.create(
|
||||
return await _documentApi.create(
|
||||
bytes,
|
||||
filename: filename,
|
||||
title: title,
|
||||
@@ -74,11 +73,6 @@ class DocumentUploadCubit extends Cubit<DocumentUploadState> {
|
||||
tags: tags,
|
||||
createdAt: createdAt,
|
||||
);
|
||||
if (onConsumptionFinished != null) {
|
||||
_documentApi
|
||||
.waitForConsumptionFinished(filename, title)
|
||||
.then((value) => onConsumptionFinished(value));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -25,14 +25,12 @@ class DocumentUploadPreparationPage extends StatefulWidget {
|
||||
final String? title;
|
||||
final String? filename;
|
||||
final String? fileExtension;
|
||||
final void Function(DocumentModel)? onSuccessfullyConsumed;
|
||||
|
||||
const DocumentUploadPreparationPage({
|
||||
Key? key,
|
||||
required this.fileBytes,
|
||||
this.title,
|
||||
this.filename,
|
||||
this.onSuccessfullyConsumed,
|
||||
this.fileExtension,
|
||||
}) : super(key: key);
|
||||
|
||||
@@ -236,19 +234,18 @@ class _DocumentUploadPreparationPageState
|
||||
final correspondent =
|
||||
fv[DocumentModel.correspondentKey] as IdQueryParameter;
|
||||
|
||||
await cubit.upload(
|
||||
final taskId = await cubit.upload(
|
||||
widget.fileBytes,
|
||||
filename:
|
||||
_padWithPdfExtension(_formKey.currentState?.value[fkFileName]),
|
||||
title: title,
|
||||
onConsumptionFinished: widget.onSuccessfullyConsumed,
|
||||
documentType: docType.id,
|
||||
correspondent: correspondent.id,
|
||||
tags: tags.ids,
|
||||
createdAt: createdAt,
|
||||
);
|
||||
showSnackBar(context, S.of(context).documentUploadSuccessText);
|
||||
Navigator.pop(context, true);
|
||||
Navigator.pop(context, taskId);
|
||||
} on PaperlessServerException catch (error, stackTrace) {
|
||||
showErrorMessage(context, error, stackTrace);
|
||||
} on PaperlessValidationErrors catch (errors) {
|
||||
|
||||
Reference in New Issue
Block a user