feat: Add hive type adapters to api models, migrate to freezed

This commit is contained in:
Anton Stubenbord
2023-04-24 01:14:20 +02:00
parent 5c0ef7f853
commit 1f335119b3
67 changed files with 2075 additions and 1079 deletions

View File

@@ -13,8 +13,7 @@ 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;
@@ -39,10 +38,7 @@ class InboxCubit extends HydratedCubit<InboxState>
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 {
@@ -101,7 +97,7 @@ class InboxCubit extends HydratedCubit<InboxState>
updateFilter(
filter: DocumentFilter(
sortField: SortField.added,
tags: IdsTagsQuery.fromIds(inboxTags),
tags: TagsQuery.ids(include: inboxTags),
),
);
}
@@ -131,7 +127,7 @@ class InboxCubit extends HydratedCubit<InboxState>
updateFilter(
filter: DocumentFilter(
sortField: SortField.added,
tags: IdsTagsQuery.fromIds(inboxTags),
tags: TagsQuery.ids(include: inboxTags),
),
);
}
@@ -141,8 +137,7 @@ class InboxCubit extends HydratedCubit<InboxState>
/// 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(
@@ -196,8 +191,8 @@ class InboxCubit extends HydratedCubit<InboxState>
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);
}
@@ -222,4 +217,7 @@ class InboxCubit extends HydratedCubit<InboxState>
_labelRepository.removeListener(this);
return super.close();
}
@override
Future<void> onFilterUpdated(DocumentFilter filter) async {}
}