WIP - More decoupling of data layer from ui layer

This commit is contained in:
Anton Stubenbord
2022-12-09 00:54:39 +01:00
parent 75fa2f7713
commit c9694fa8d0
87 changed files with 2508 additions and 1879 deletions

View File

@@ -9,13 +9,8 @@ import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_mobile/di_initializer.dart';
import 'package:paperless_mobile/features/login/bloc/authentication_cubit.dart';
@injectable
class DocumentScannerCubit extends Cubit<List<File>> {
final PaperlessDocumentsApi _api;
static List<File> initialState = [];
DocumentScannerCubit(this._api) : super(initialState);
DocumentScannerCubit() : super(const []);
void addScan(File file) => emit([...state, file]);
@@ -39,41 +34,9 @@ class DocumentScannerCubit extends Cubit<List<File>> {
}
}
imageCache.clear();
emit(initialState);
emit([]);
} catch (_) {
throw const PaperlessServerException(ErrorCode.scanRemoveFailed);
}
}
Future<void> uploadDocument(
Uint8List bytes,
String fileName, {
required String title,
required void Function(DocumentModel document)? onConsumptionFinished,
int? documentType,
int? correspondent,
Iterable<int> tags = const [],
DateTime? createdAt,
}) async {
final auth = getIt<AuthenticationCubit>().state.authentication;
if (auth == null) {
throw const PaperlessServerException(ErrorCode.notAuthenticated);
}
await _api.create(
bytes,
filename: fileName,
title: title,
documentType: documentType,
correspondent: correspondent,
tags: tags,
createdAt: createdAt,
authToken: auth.token!,
serverUrl: auth.serverUrl,
);
if (onConsumptionFinished != null) {
_api
.waitForConsumptionFinished(fileName, title)
.then((value) => onConsumptionFinished(value));
}
}
}