WIP - Reimplemented document search

This commit is contained in:
Anton Stubenbord
2023-01-28 23:06:27 +01:00
parent a7b980ae71
commit b697dc7d8d
34 changed files with 949 additions and 677 deletions

View File

@@ -1,25 +1,15 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_mobile/features/linked_documents/bloc/state/linked_documents_state.dart';
import 'package:paperless_mobile/features/paged_document_view/paged_documents_mixin.dart';
class LinkedDocumentsCubit extends Cubit<LinkedDocumentsState> {
final PaperlessDocumentsApi _api;
class LinkedDocumentsCubit extends Cubit<LinkedDocumentsState>
with PagedDocumentsMixin {
@override
final PaperlessDocumentsApi api;
LinkedDocumentsCubit(this._api, DocumentFilter filter)
: super(LinkedDocumentsState(filter: filter)) {
_initialize();
}
Future<void> _initialize() async {
final documents = await _api.findAll(
state.filter.copyWith(
pageSize: 100,
),
);
emit(LinkedDocumentsState(
isLoaded: true,
documents: documents,
filter: state.filter,
));
LinkedDocumentsCubit(this.api, DocumentFilter filter)
: super(const LinkedDocumentsState()) {
updateFilter(filter: filter);
}
}

View File

@@ -1,13 +1,48 @@
import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_mobile/features/paged_document_view/model/paged_documents_state.dart';
class LinkedDocumentsState {
final bool isLoaded;
final PagedSearchResult<DocumentModel>? documents;
final DocumentFilter filter;
LinkedDocumentsState({
required this.filter,
this.isLoaded = false,
this.documents,
class LinkedDocumentsState extends PagedDocumentsState {
const LinkedDocumentsState({
super.filter,
super.isLoading,
super.hasLoaded,
super.value,
});
LinkedDocumentsState copyWith({
DocumentFilter? filter,
bool? isLoading,
bool? hasLoaded,
List<PagedSearchResult<DocumentModel>>? value,
}) {
return LinkedDocumentsState(
filter: filter ?? this.filter,
isLoading: isLoading ?? this.isLoading,
hasLoaded: hasLoaded ?? this.hasLoaded,
value: value ?? this.value,
);
}
@override
LinkedDocumentsState copyWithPaged({
bool? hasLoaded,
bool? isLoading,
List<PagedSearchResult<DocumentModel>>? value,
DocumentFilter? filter,
}) {
return copyWith(
hasLoaded: hasLoaded,
isLoading: isLoading,
value: value,
filter: filter,
);
}
@override
List<Object?> get props => [
filter,
isLoading,
hasLoaded,
value,
];
}