feat: Add more user related state to hive

This commit is contained in:
Anton Stubenbord
2023-04-23 16:48:11 +02:00
parent 1b9e4fbb81
commit 5c0ef7f853
32 changed files with 408 additions and 272 deletions

View File

@@ -13,7 +13,8 @@ import 'package:paperless_mobile/features/paged_document_view/cubit/document_pag
part 'inbox_cubit.g.dart';
part 'inbox_state.dart';
class InboxCubit extends HydratedCubit<InboxState> with DocumentPagingBlocMixin {
class InboxCubit extends HydratedCubit<InboxState>
with DocumentPagingBlocMixin {
final LabelRepository _labelRepository;
final PaperlessDocumentsApi _documentsApi;
@@ -31,12 +32,17 @@ class InboxCubit extends HydratedCubit<InboxState> with DocumentPagingBlocMixin
this._statsApi,
this._labelRepository,
this.notifier,
) : super(InboxState(labels: _labelRepository.state)) {
) : super(InboxState(
labels: _labelRepository.state,
)) {
notifier.addListener(
this,
onDeleted: remove,
onUpdated: (document) {
if (document.tags.toSet().intersection(state.inboxTags.toSet()).isEmpty) {
if (document.tags
.toSet()
.intersection(state.inboxTags.toSet())
.isEmpty) {
remove(document);
emit(state.copyWith(itemsInInboxCount: state.itemsInInboxCount - 1));
} else {
@@ -135,7 +141,8 @@ class InboxCubit extends HydratedCubit<InboxState> with DocumentPagingBlocMixin
/// from the inbox.
///
Future<Iterable<int>> removeFromInbox(DocumentModel document) async {
final tagsToRemove = document.tags.toSet().intersection(state.inboxTags.toSet());
final tagsToRemove =
document.tags.toSet().intersection(state.inboxTags.toSet());
final updatedTags = {...document.tags}..removeAll(tagsToRemove);
final updatedDocument = await api.update(
@@ -189,8 +196,8 @@ class InboxCubit extends HydratedCubit<InboxState> with DocumentPagingBlocMixin
Future<void> assignAsn(DocumentModel document) async {
if (document.archiveSerialNumber == null) {
final int asn = await _documentsApi.findNextAsn();
final updatedDocument =
await _documentsApi.update(document.copyWith(archiveSerialNumber: () => asn));
final updatedDocument = await _documentsApi
.update(document.copyWith(archiveSerialNumber: () => asn));
replace(updatedDocument);
}