mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-14 14:12:21 -06:00
Hooked notifications to status changes on document upload - some refactorings
This commit is contained in:
@@ -8,22 +8,40 @@ class DocumentDetailsCubit extends Cubit<DocumentDetailsState> {
|
||||
final PaperlessDocumentsApi _api;
|
||||
|
||||
DocumentDetailsCubit(this._api, DocumentModel initialDocument)
|
||||
: super(DocumentDetailsState(document: initialDocument));
|
||||
: super(DocumentDetailsState(document: initialDocument)) {
|
||||
loadSuggestions();
|
||||
}
|
||||
|
||||
Future<void> delete(DocumentModel document) async {
|
||||
await _api.delete(document);
|
||||
}
|
||||
|
||||
Future<void> loadSuggestions() async {
|
||||
final suggestions = await _api.findSuggestions(state.document);
|
||||
emit(state.copyWith(suggestions: suggestions));
|
||||
}
|
||||
|
||||
Future<void> loadFullContent() async {
|
||||
final doc = await _api.find(state.document.id);
|
||||
if (doc == null) {
|
||||
return;
|
||||
}
|
||||
emit(state.copyWith(
|
||||
isFullContentLoaded: true,
|
||||
fullContent: doc.content,
|
||||
));
|
||||
}
|
||||
|
||||
Future<void> assignAsn(DocumentModel document) async {
|
||||
if (document.archiveSerialNumber == null) {
|
||||
final int asn = await _api.findNextAsn();
|
||||
final updatedDocument =
|
||||
await _api.update(document.copyWith(archiveSerialNumber: asn));
|
||||
emit(DocumentDetailsState(document: updatedDocument));
|
||||
emit(state.copyWith(document: updatedDocument));
|
||||
}
|
||||
}
|
||||
|
||||
void replaceDocument(DocumentModel document) {
|
||||
emit(DocumentDetailsState(document: document));
|
||||
emit(state.copyWith(document: document));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,36 @@ part of 'document_details_cubit.dart';
|
||||
|
||||
class DocumentDetailsState with EquatableMixin {
|
||||
final DocumentModel document;
|
||||
final bool isFullContentLoaded;
|
||||
final String? fullContent;
|
||||
final FieldSuggestions suggestions;
|
||||
|
||||
const DocumentDetailsState({
|
||||
required this.document,
|
||||
this.suggestions = const FieldSuggestions(),
|
||||
this.isFullContentLoaded = false,
|
||||
this.fullContent,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [document];
|
||||
List<Object?> get props => [
|
||||
document,
|
||||
suggestions,
|
||||
isFullContentLoaded,
|
||||
fullContent,
|
||||
];
|
||||
|
||||
DocumentDetailsState copyWith({
|
||||
DocumentModel? document,
|
||||
FieldSuggestions? suggestions,
|
||||
bool? isFullContentLoaded,
|
||||
String? fullContent,
|
||||
}) {
|
||||
return DocumentDetailsState(
|
||||
document: document ?? this.document,
|
||||
suggestions: suggestions ?? this.suggestions,
|
||||
isFullContentLoaded: isFullContentLoaded ?? this.isFullContentLoaded,
|
||||
fullContent: fullContent ?? this.fullContent,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user