mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-09 20:07:51 -06:00
WIP - Reimplemented document search
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:paperless_mobile/features/documents/view/widgets/list/document_l
|
||||
import 'package:paperless_mobile/features/linked_documents/bloc/linked_documents_cubit.dart';
|
||||
import 'package:paperless_mobile/features/linked_documents/bloc/state/linked_documents_state.dart';
|
||||
import 'package:paperless_mobile/generated/l10n.dart';
|
||||
import 'package:paperless_mobile/helpers/message_helpers.dart';
|
||||
|
||||
class LinkedDocumentsPage extends StatefulWidget {
|
||||
const LinkedDocumentsPage({super.key});
|
||||
@@ -17,6 +18,28 @@ class LinkedDocumentsPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _LinkedDocumentsPageState extends State<LinkedDocumentsPage> {
|
||||
final _scrollController = ScrollController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_scrollController.addListener(_listenForLoadNewData);
|
||||
}
|
||||
|
||||
void _listenForLoadNewData() async {
|
||||
final currState = context.read<LinkedDocumentsCubit>().state;
|
||||
if (_scrollController.offset >=
|
||||
_scrollController.position.maxScrollExtent * 0.75 &&
|
||||
!currState.isLoading &&
|
||||
!currState.isLastPageLoaded) {
|
||||
try {
|
||||
await context.read<LinkedDocumentsCubit>().loadMore();
|
||||
} on PaperlessServerException catch (error, stackTrace) {
|
||||
showErrorMessage(context, error, stackTrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -25,45 +48,14 @@ class _LinkedDocumentsPageState extends State<LinkedDocumentsPage> {
|
||||
),
|
||||
body: BlocBuilder<LinkedDocumentsCubit, LinkedDocumentsState>(
|
||||
builder: (context, state) {
|
||||
return Column(
|
||||
children: [
|
||||
Text(
|
||||
S.of(context).referencedDocumentsReadOnlyHintText,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
if (!state.isLoaded)
|
||||
const Expanded(child: DocumentsListLoadingWidget())
|
||||
else
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: state.documents?.results.length,
|
||||
itemBuilder: (context, index) {
|
||||
return DocumentListItem(
|
||||
isLabelClickable: false,
|
||||
document: state.documents!.results.elementAt(index),
|
||||
onTap: (doc) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => BlocProvider(
|
||||
create: (context) => DocumentDetailsCubit(
|
||||
context.read<PaperlessDocumentsApi>(),
|
||||
state.documents!.results.elementAt(index),
|
||||
),
|
||||
child: const DocumentDetailsPage(
|
||||
isLabelClickable: false,
|
||||
allowEdit: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
if (!state.hasLoaded) {
|
||||
return const DocumentsListLoadingWidget();
|
||||
}
|
||||
return ListView.builder(
|
||||
itemCount: state.documents.length,
|
||||
itemBuilder: (context, index) => DocumentListItem(
|
||||
document: state.documents[index],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user