mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-09 16:07:57 -06:00
feat: Add view type selection to linked documents view
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user