mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-08 14:07:49 -06:00
fix: Change return type of upload route
This commit is contained in:
@@ -208,7 +208,7 @@ class _ScannerPageState extends State<ScannerPage>
|
|||||||
final file = await _assembleFileBytes(
|
final file = await _assembleFileBytes(
|
||||||
context.read<DocumentScannerCubit>().state,
|
context.read<DocumentScannerCubit>().state,
|
||||||
);
|
);
|
||||||
final taskId = await Navigator.of(context).push<String?>(
|
final uploadResult = await Navigator.of(context).push<DocumentUploadResult>(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (_) => LabelRepositoriesProvider(
|
builder: (_) => LabelRepositoriesProvider(
|
||||||
child: BlocProvider(
|
child: BlocProvider(
|
||||||
@@ -228,10 +228,12 @@ class _ScannerPageState extends State<ScannerPage>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (taskId != null) {
|
if ((uploadResult?.success ?? false) && uploadResult?.taskId != null) {
|
||||||
// For paperless version older than 1.11.3, task id will always be null!
|
// For paperless version older than 1.11.3, task id will always be null!
|
||||||
context.read<DocumentScannerCubit>().reset();
|
context.read<DocumentScannerCubit>().reset();
|
||||||
context.read<TaskStatusCubit>().listenToTaskChanges(taskId);
|
context
|
||||||
|
.read<TaskStatusCubit>()
|
||||||
|
.listenToTaskChanges(uploadResult!.taskId!);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,13 @@ import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
|
|||||||
|
|
||||||
import 'package:paperless_mobile/helpers/message_helpers.dart';
|
import 'package:paperless_mobile/helpers/message_helpers.dart';
|
||||||
|
|
||||||
|
class DocumentUploadResult {
|
||||||
|
final bool success;
|
||||||
|
final String? taskId;
|
||||||
|
|
||||||
|
DocumentUploadResult(this.success, this.taskId);
|
||||||
|
}
|
||||||
|
|
||||||
class DocumentUploadPreparationPage extends StatefulWidget {
|
class DocumentUploadPreparationPage extends StatefulWidget {
|
||||||
final Uint8List fileBytes;
|
final Uint8List fileBytes;
|
||||||
final String? title;
|
final String? title;
|
||||||
@@ -259,13 +266,19 @@ class _DocumentUploadPreparationPageState
|
|||||||
createdAt: createdAt,
|
createdAt: createdAt,
|
||||||
);
|
);
|
||||||
showSnackBar(
|
showSnackBar(
|
||||||
context, S.of(context)!.documentSuccessfullyUploadedProcessing);
|
context,
|
||||||
Navigator.pop(context, taskId);
|
S.of(context)!.documentSuccessfullyUploadedProcessing,
|
||||||
|
);
|
||||||
|
Navigator.pop(
|
||||||
|
context,
|
||||||
|
DocumentUploadResult(true, taskId),
|
||||||
|
);
|
||||||
} on PaperlessServerException catch (error, stackTrace) {
|
} on PaperlessServerException catch (error, stackTrace) {
|
||||||
showErrorMessage(context, error, stackTrace);
|
showErrorMessage(context, error, stackTrace);
|
||||||
} on PaperlessValidationErrors catch (errors) {
|
} on PaperlessValidationErrors catch (errors) {
|
||||||
setState(() => _errors = errors);
|
setState(() => _errors = errors);
|
||||||
} catch (unknownError, stackTrace) {
|
} catch (unknownError, stackTrace) {
|
||||||
|
debugPrint(unknownError.toString());
|
||||||
showErrorMessage(
|
showErrorMessage(
|
||||||
context, const PaperlessServerException.unknown(), stackTrace);
|
context, const PaperlessServerException.unknown(), stackTrace);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -156,27 +156,26 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
|
|||||||
final extension = p.extension(mediaFile.path);
|
final extension = p.extension(mediaFile.path);
|
||||||
if (await File(mediaFile.path).exists()) {
|
if (await File(mediaFile.path).exists()) {
|
||||||
final bytes = File(mediaFile.path).readAsBytesSync();
|
final bytes = File(mediaFile.path).readAsBytesSync();
|
||||||
final success = await Navigator.push<bool>(
|
final result = await Navigator.push<DocumentUploadResult>(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => BlocProvider.value(
|
builder: (context) => BlocProvider.value(
|
||||||
value: DocumentUploadCubit(
|
value: DocumentUploadCubit(
|
||||||
documentApi: context.read(),
|
documentApi: context.read(),
|
||||||
tagRepository: context.read(),
|
tagRepository: context.read(),
|
||||||
correspondentRepository: context.read(),
|
correspondentRepository: context.read(),
|
||||||
documentTypeRepository: context.read(),
|
documentTypeRepository: context.read(),
|
||||||
),
|
|
||||||
child: DocumentUploadPreparationPage(
|
|
||||||
fileBytes: bytes,
|
|
||||||
filename: filename,
|
|
||||||
title: filename,
|
|
||||||
fileExtension: extension,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
) ??
|
child: DocumentUploadPreparationPage(
|
||||||
false;
|
fileBytes: bytes,
|
||||||
if (success) {
|
filename: filename,
|
||||||
|
title: filename,
|
||||||
|
fileExtension: extension,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (result?.success ?? false) {
|
||||||
await Fluttertoast.showToast(
|
await Fluttertoast.showToast(
|
||||||
msg: S.of(context)!.documentSuccessfullyUploadedProcessing,
|
msg: S.of(context)!.documentSuccessfullyUploadedProcessing,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user