feat: Add query highlight fragments to detailed view, fix build

This commit is contained in:
Anton Stubenbord
2023-02-24 14:29:19 +01:00
parent 6cf88b6fdc
commit ce39190723
9 changed files with 153 additions and 93 deletions

View File

@@ -5,6 +5,7 @@ import 'package:paperless_mobile/core/notifier/document_changed_notifier.dart';
import 'package:paperless_mobile/features/paged_document_view/cubit/document_paging_bloc_mixin.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:paperless_mobile/features/paged_document_view/cubit/paged_documents_state.dart';
import 'package:paperless_mobile/features/settings/model/view_type.dart';
part 'document_search_state.dart';
@@ -33,7 +34,7 @@ class DocumentSearchCubit extends HydratedCubit<DocumentSearchState>
view: SearchView.results,
));
final searchFilter = DocumentFilter(
query: TextQuery.titleAndContent(query),
query: TextQuery.extended(query),
);
await updateFilter(filter: searchFilter);
@@ -48,6 +49,10 @@ class DocumentSearchCubit extends HydratedCubit<DocumentSearchState>
);
}
void updateViewType(ViewType viewType) {
emit(state.copyWith(viewType: viewType));
}
void removeHistoryEntry(String entry) {
emit(
state.copyWith(

View File

@@ -11,10 +11,13 @@ class DocumentSearchState extends DocumentPagingState {
final List<String> searchHistory;
final SearchView view;
final List<String> suggestions;
@JsonKey()
final ViewType viewType;
const DocumentSearchState({
this.view = SearchView.suggestions,
this.searchHistory = const [],
this.suggestions = const [],
this.viewType = ViewType.detailed,
super.filter,
super.hasLoaded,
super.isLoading,
@@ -27,6 +30,7 @@ class DocumentSearchState extends DocumentPagingState {
searchHistory,
suggestions,
view,
viewType,
];
@override
@@ -52,6 +56,7 @@ class DocumentSearchState extends DocumentPagingState {
DocumentFilter? filter,
List<String>? suggestions,
SearchView? view,
ViewType? viewType,
}) {
return DocumentSearchState(
value: value ?? this.value,
@@ -61,6 +66,7 @@ class DocumentSearchState extends DocumentPagingState {
searchHistory: searchHistory ?? this.searchHistory,
view: view ?? this.view,
suggestions: suggestions ?? this.suggestions,
viewType: viewType ?? this.viewType,
);
}

View File

@@ -7,6 +7,8 @@ import 'package:paperless_mobile/extensions/flutter_extensions.dart';
import 'package:paperless_mobile/features/document_search/cubit/document_search_cubit.dart';
import 'package:paperless_mobile/features/document_search/view/remove_history_entry_dialog.dart';
import 'package:paperless_mobile/features/documents/view/widgets/adaptive_documents_view.dart';
import 'package:paperless_mobile/features/documents/view/widgets/selection/view_type_selection_widget.dart';
import 'package:paperless_mobile/features/settings/model/view_type.dart';
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
import 'package:paperless_mobile/routes/document_details_route.dart';
@@ -168,7 +170,7 @@ class _DocumentSearchPageState extends State<DocumentSearchPage> {
alignment: Alignment.center,
transform: Matrix4.rotationY(math.pi),
child: IconButton(
icon: Icon(Icons.arrow_outward),
icon: const Icon(Icons.arrow_outward),
onPressed: () {
_queryController.text = '$suggestion ';
_queryController.selection = TextSelection.fromPosition(
@@ -181,9 +183,23 @@ class _DocumentSearchPageState extends State<DocumentSearchPage> {
}
Widget _buildResultsView(DocumentSearchState state) {
final header = Text(
S.of(context)!.results,
style: Theme.of(context).textTheme.labelSmall,
final header = Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
S.of(context)!.results,
style: Theme.of(context).textTheme.bodySmall,
),
BlocBuilder<DocumentSearchCubit, DocumentSearchState>(
builder: (context, state) {
return ViewTypeSelectionWidget(
viewType: state.viewType,
onChanged: (type) =>
context.read<DocumentSearchCubit>().updateViewType(type),
);
},
)
],
).padded();
return CustomScrollView(
slivers: [
@@ -196,6 +212,7 @@ class _DocumentSearchPageState extends State<DocumentSearchPage> {
)
else
SliverAdaptiveDocumentsView(
viewType: state.viewType,
documents: state.documents,
hasInternetConnection: true,
isLabelClickable: false,