feat: Add view type selection to linked documents view

This commit is contained in:
Anton Stubenbord
2023-02-10 16:09:36 +01:00
parent fc0b3240bb
commit 9abce08ef2
3 changed files with 66 additions and 23 deletions

View File

@@ -1,11 +1,15 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_mobile/core/notifier/document_changed_notifier.dart';
import 'package:paperless_mobile/features/paged_document_view/model/paged_documents_state.dart';
import 'package:paperless_mobile/features/paged_document_view/paged_documents_mixin.dart';
import 'package:paperless_mobile/features/settings/model/view_type.dart';
part 'linked_documents_state.dart';
class LinkedDocumentsCubit extends Cubit<LinkedDocumentsState>
part 'linked_documents_cubit.g.dart';
class LinkedDocumentsCubit extends HydratedCubit<LinkedDocumentsState>
with PagedDocumentsMixin {
@override
final PaperlessDocumentsApi api;
@@ -35,4 +39,18 @@ class LinkedDocumentsCubit extends Cubit<LinkedDocumentsState>
replace(document);
}
}
void setViewType(ViewType type) {
emit(state.copyWith(viewType: type));
}
@override
LinkedDocumentsState? fromJson(Map<String, dynamic> json) {
return LinkedDocumentsState.fromJson(json);
}
@override
Map<String, dynamic>? toJson(LinkedDocumentsState state) {
return state.toJson();
}
}

View File

@@ -1,7 +1,11 @@
part of 'linked_documents_cubit.dart';
@JsonSerializable(ignoreUnannotated: true)
class LinkedDocumentsState extends PagedDocumentsState {
@JsonKey()
final ViewType viewType;
const LinkedDocumentsState({
this.viewType = ViewType.list,
super.filter,
super.isLoading,
super.hasLoaded,
@@ -13,12 +17,14 @@ class LinkedDocumentsState extends PagedDocumentsState {
bool? isLoading,
bool? hasLoaded,
List<PagedSearchResult<DocumentModel>>? value,
ViewType? viewType,
}) {
return LinkedDocumentsState(
filter: filter ?? this.filter,
isLoading: isLoading ?? this.isLoading,
hasLoaded: hasLoaded ?? this.hasLoaded,
value: value ?? this.value,
viewType: viewType ?? this.viewType,
);
}
@@ -39,9 +45,12 @@ class LinkedDocumentsState extends PagedDocumentsState {
@override
List<Object?> get props => [
filter,
isLoading,
hasLoaded,
value,
viewType,
...super.props,
];
factory LinkedDocumentsState.fromJson(Map<String, dynamic> json) =>
_$LinkedDocumentsStateFromJson(json);
Map<String, dynamic> toJson() => _$LinkedDocumentsStateToJson(this);
}

View File

@@ -3,6 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_mobile/core/bloc/connectivity_cubit.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/linked_documents/cubit/linked_documents_cubit.dart';
import 'package:paperless_mobile/generated/l10n.dart';
import 'package:paperless_mobile/helpers/message_helpers.dart';
@@ -43,28 +44,43 @@ class _LinkedDocumentsPageState extends State<LinkedDocumentsPage> {
return Scaffold(
appBar: AppBar(
title: Text(S.of(context).linkedDocumentsPageTitle),
actions: [
BlocBuilder<LinkedDocumentsCubit, LinkedDocumentsState>(
builder: (context, state) {
return ViewTypeSelectionWidget(
viewType: state.viewType,
onChanged: context.read<LinkedDocumentsCubit>().setViewType,
);
},
),
],
),
body: BlocBuilder<LinkedDocumentsCubit, LinkedDocumentsState>(
builder: (context, state) {
return BlocBuilder<ConnectivityCubit, ConnectivityState>(
builder: (context, connectivity) {
return DefaultAdaptiveDocumentsView(
scrollController: _scrollController,
documents: state.documents,
hasInternetConnection: connectivity.isConnected,
isLabelClickable: false,
isLoading: state.isLoading,
hasLoaded: state.hasLoaded,
onTap: (document) {
Navigator.pushNamed(
context,
DocumentDetailsRoute.routeName,
arguments: DocumentDetailsRouteArguments(
document: document,
isLabelClickable: false,
),
);
},
return CustomScrollView(
controller: _scrollController,
slivers: [
SliverAdaptiveDocumentsView(
viewType: state.viewType,
documents: state.documents,
hasInternetConnection: connectivity.isConnected,
isLabelClickable: false,
isLoading: state.isLoading,
hasLoaded: state.hasLoaded,
onTap: (document) {
Navigator.pushNamed(
context,
DocumentDetailsRoute.routeName,
arguments: DocumentDetailsRouteArguments(
document: document,
isLabelClickable: false,
),
);
},
),
],
);
},
);