mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2026-01-31 14:24:58 -06:00
Removed suggestions from inbox, added translations, added paging to inbox, visual updates, changed default matching algorithm to auto
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hydrated_bloc/hydrated_bloc.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_mobile/core/repository/label_repository.dart';
|
||||
@@ -9,8 +7,9 @@ import 'package:paperless_mobile/core/repository/state/impl/correspondent_reposi
|
||||
import 'package:paperless_mobile/core/repository/state/impl/document_type_repository_state.dart';
|
||||
import 'package:paperless_mobile/core/repository/state/impl/tag_repository_state.dart';
|
||||
import 'package:paperless_mobile/features/inbox/bloc/state/inbox_state.dart';
|
||||
import 'package:paperless_mobile/features/paged_document_view/documents_paging_mixin.dart';
|
||||
|
||||
class InboxCubit extends HydratedCubit<InboxState> {
|
||||
class InboxCubit extends HydratedCubit<InboxState> with DocumentsPagingMixin {
|
||||
final LabelRepository<Tag, TagRepositoryState> _tagsRepository;
|
||||
final LabelRepository<Correspondent, CorrespondentRepositoryState>
|
||||
_correspondentRepository;
|
||||
@@ -21,6 +20,9 @@ class InboxCubit extends HydratedCubit<InboxState> {
|
||||
|
||||
final List<StreamSubscription> _subscriptions = [];
|
||||
|
||||
@override
|
||||
PaperlessDocumentsApi get api => _documentsApi;
|
||||
|
||||
InboxCubit(
|
||||
this._tagsRepository,
|
||||
this._documentsApi,
|
||||
@@ -67,105 +69,83 @@ class InboxCubit extends HydratedCubit<InboxState> {
|
||||
final inboxTags = await _tagsRepository.findAll().then(
|
||||
(tags) => tags.where((t) => t.isInboxTag ?? false).map((t) => t.id!),
|
||||
);
|
||||
|
||||
if (inboxTags.isEmpty) {
|
||||
// no inbox tags = no inbox items.
|
||||
return emit(
|
||||
state.copyWith(
|
||||
isLoaded: true,
|
||||
inboxItems: [],
|
||||
hasLoaded: true,
|
||||
value: [],
|
||||
inboxTags: [],
|
||||
),
|
||||
);
|
||||
}
|
||||
final inboxDocuments = await _documentsApi
|
||||
.findAll(DocumentFilter(
|
||||
tags: AnyAssignedTagsQuery(tagIds: inboxTags),
|
||||
sortField: SortField.added,
|
||||
))
|
||||
.then((psr) => psr.results);
|
||||
final newState = state.copyWith(
|
||||
isLoaded: true,
|
||||
inboxItems: inboxDocuments,
|
||||
inboxTags: inboxTags,
|
||||
return updateFilter(
|
||||
filter: DocumentFilter(
|
||||
sortField: SortField.added,
|
||||
tags: IdsTagsQuery.fromIds(inboxTags),
|
||||
),
|
||||
);
|
||||
emit(newState);
|
||||
}
|
||||
|
||||
///
|
||||
/// Updates the document with all inbox tags removed and removes the document
|
||||
/// from the currently loaded inbox documents.
|
||||
/// from the inbox.
|
||||
///
|
||||
Future<Iterable<int>> remove(DocumentModel document) async {
|
||||
Future<Iterable<int>> removeFromInbox(DocumentModel document) async {
|
||||
final tagsToRemove =
|
||||
document.tags.toSet().intersection(state.inboxTags.toSet());
|
||||
|
||||
final updatedTags = {...document.tags}..removeAll(tagsToRemove);
|
||||
|
||||
await _documentsApi.update(
|
||||
document.copyWith(
|
||||
tags: updatedTags,
|
||||
overwriteTags: true,
|
||||
),
|
||||
await api.update(
|
||||
document.copyWith(tags: updatedTags),
|
||||
);
|
||||
emit(
|
||||
state.copyWith(
|
||||
isLoaded: true,
|
||||
inboxItems: state.inboxItems.where((doc) => doc.id != document.id),
|
||||
),
|
||||
);
|
||||
|
||||
await remove(document);
|
||||
return tagsToRemove;
|
||||
}
|
||||
|
||||
///
|
||||
/// Adds the previously removed tags to the document and performs an update.
|
||||
///
|
||||
Future<void> undoRemove(
|
||||
Future<void> undoRemoveFromInbox(
|
||||
DocumentModel document,
|
||||
Iterable<int> removedTags,
|
||||
) async {
|
||||
final updatedDoc = document.copyWith(
|
||||
tags: {...document.tags, ...removedTags},
|
||||
overwriteTags: true,
|
||||
);
|
||||
await _documentsApi.update(updatedDoc);
|
||||
emit(state.copyWith(
|
||||
isLoaded: true,
|
||||
inboxItems: [...state.inboxItems, updatedDoc]
|
||||
..sort((d1, d2) => d2.added.compareTo(d1.added)),
|
||||
));
|
||||
return reload();
|
||||
}
|
||||
|
||||
///
|
||||
/// Removes inbox tags from all documents in the inbox.
|
||||
///
|
||||
Future<void> clearInbox() async {
|
||||
await _documentsApi.bulkAction(
|
||||
BulkModifyTagsAction.removeTags(
|
||||
state.inboxItems.map((e) => e.id),
|
||||
state.inboxTags,
|
||||
),
|
||||
);
|
||||
emit(state.copyWith(
|
||||
isLoaded: true,
|
||||
inboxItems: [],
|
||||
));
|
||||
emit(state.copyWith(isLoading: true));
|
||||
try {
|
||||
await _documentsApi.bulkAction(
|
||||
BulkModifyTagsAction.removeTags(
|
||||
state.documents.map((e) => e.id),
|
||||
state.inboxTags,
|
||||
),
|
||||
);
|
||||
emit(state.copyWith(
|
||||
hasLoaded: true,
|
||||
value: [],
|
||||
));
|
||||
} finally {
|
||||
emit(state.copyWith(isLoading: false));
|
||||
}
|
||||
}
|
||||
|
||||
void replaceUpdatedDocument(DocumentModel document) {
|
||||
if (document.tags.any((id) => state.inboxTags.contains(id))) {
|
||||
// If replaced document still has inbox tag assigned:
|
||||
emit(state.copyWith(
|
||||
inboxItems:
|
||||
state.inboxItems.map((e) => e.id == document.id ? document : e),
|
||||
));
|
||||
replace(document);
|
||||
} else {
|
||||
// Remove tag from inbox.
|
||||
emit(
|
||||
state.copyWith(
|
||||
inboxItems:
|
||||
state.inboxItems.where((element) => element.id != document.id)),
|
||||
);
|
||||
// Remove document from inbox.
|
||||
remove(document);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,48 +154,10 @@ class InboxCubit extends HydratedCubit<InboxState> {
|
||||
final int asn = await _documentsApi.findNextAsn();
|
||||
final updatedDocument = await _documentsApi
|
||||
.update(document.copyWith(archiveSerialNumber: asn));
|
||||
emit(
|
||||
state.copyWith(
|
||||
inboxItems: state.inboxItems
|
||||
.map((e) => e.id == document.id ? updatedDocument : e)),
|
||||
);
|
||||
replace(updatedDocument);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateDocument(DocumentModel document) async {
|
||||
final updatedDocument = await _documentsApi.update(document);
|
||||
emit(
|
||||
state.copyWith(
|
||||
inboxItems: state.inboxItems.map(
|
||||
(e) => e.id == document.id ? updatedDocument : e,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> deleteDocument(DocumentModel document) async {
|
||||
int deletedId = await _documentsApi.delete(document);
|
||||
emit(
|
||||
state.copyWith(
|
||||
inboxItems: state.inboxItems.where(
|
||||
(element) => element.id != deletedId,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void loadSuggestions() {
|
||||
state.inboxItems
|
||||
.whereNot((doc) => state.suggestions.containsKey(doc.id))
|
||||
.map((e) => _documentsApi.findSuggestions(e))
|
||||
.forEach((suggestion) async {
|
||||
final s = await suggestion;
|
||||
emit(state.copyWith(
|
||||
suggestions: {...state.suggestions, s.documentId!: s},
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
void acknowledgeHint() {
|
||||
emit(state.copyWith(isHintAcknowledged: true));
|
||||
}
|
||||
|
||||
@@ -1,57 +1,56 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:paperless_mobile/features/paged_document_view/model/documents_paged_state.dart';
|
||||
|
||||
part 'inbox_state.g.dart';
|
||||
|
||||
@JsonSerializable(
|
||||
ignoreUnannotated: true,
|
||||
)
|
||||
class InboxState with EquatableMixin {
|
||||
final bool isLoaded;
|
||||
|
||||
class InboxState extends DocumentsPagedState {
|
||||
final Iterable<int> inboxTags;
|
||||
|
||||
final Iterable<DocumentModel> inboxItems;
|
||||
|
||||
final Map<int, Tag> availableTags;
|
||||
|
||||
final Map<int, DocumentType> availableDocumentTypes;
|
||||
|
||||
final Map<int, Correspondent> availableCorrespondents;
|
||||
|
||||
final Map<int, FieldSuggestions> suggestions;
|
||||
@JsonKey()
|
||||
final bool isHintAcknowledged;
|
||||
|
||||
const InboxState({
|
||||
this.isLoaded = false,
|
||||
super.hasLoaded = false,
|
||||
super.isLoading = false,
|
||||
super.value = const [],
|
||||
super.filter = const DocumentFilter(),
|
||||
this.inboxTags = const [],
|
||||
this.inboxItems = const [],
|
||||
this.isHintAcknowledged = false,
|
||||
this.availableTags = const {},
|
||||
this.availableDocumentTypes = const {},
|
||||
this.availableCorrespondents = const {},
|
||||
this.suggestions = const {},
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
isLoaded,
|
||||
hasLoaded,
|
||||
isLoading,
|
||||
value,
|
||||
filter,
|
||||
inboxTags,
|
||||
inboxItems,
|
||||
documents,
|
||||
isHintAcknowledged,
|
||||
availableTags,
|
||||
availableDocumentTypes,
|
||||
availableCorrespondents,
|
||||
suggestions,
|
||||
];
|
||||
|
||||
InboxState copyWith({
|
||||
bool? isLoaded,
|
||||
bool? hasLoaded,
|
||||
bool? isLoading,
|
||||
Iterable<int>? inboxTags,
|
||||
Iterable<DocumentModel>? inboxItems,
|
||||
List<PagedSearchResult<DocumentModel>>? value,
|
||||
DocumentFilter? filter,
|
||||
bool? isHintAcknowledged,
|
||||
Map<int, Tag>? availableTags,
|
||||
Map<int, Correspondent>? availableCorrespondents,
|
||||
@@ -59,8 +58,9 @@ class InboxState with EquatableMixin {
|
||||
Map<int, FieldSuggestions>? suggestions,
|
||||
}) {
|
||||
return InboxState(
|
||||
isLoaded: isLoaded ?? this.isLoaded,
|
||||
inboxItems: inboxItems ?? this.inboxItems,
|
||||
hasLoaded: hasLoaded ?? super.hasLoaded,
|
||||
isLoading: isLoading ?? super.isLoading,
|
||||
value: value ?? super.value,
|
||||
inboxTags: inboxTags ?? this.inboxTags,
|
||||
isHintAcknowledged: isHintAcknowledged ?? this.isHintAcknowledged,
|
||||
availableCorrespondents:
|
||||
@@ -68,7 +68,7 @@ class InboxState with EquatableMixin {
|
||||
availableDocumentTypes:
|
||||
availableDocumentTypes ?? this.availableDocumentTypes,
|
||||
availableTags: availableTags ?? this.availableTags,
|
||||
suggestions: suggestions ?? this.suggestions,
|
||||
filter: filter ?? super.filter,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -76,4 +76,20 @@ class InboxState with EquatableMixin {
|
||||
_$InboxStateFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$InboxStateToJson(this);
|
||||
|
||||
@override
|
||||
InboxState copyWithPaged({
|
||||
bool? hasLoaded,
|
||||
bool? isLoading,
|
||||
List<PagedSearchResult<DocumentModel>>? value,
|
||||
DocumentFilter?
|
||||
filter, // Ignored as filter does not change while inbox is open
|
||||
}) {
|
||||
return copyWith(
|
||||
hasLoaded: hasLoaded,
|
||||
isLoading: isLoading,
|
||||
value: value,
|
||||
filter: filter,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,71 +23,104 @@ class InboxPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _InboxPageState extends State<InboxPage> {
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
final _emptyStateRefreshIndicatorKey = GlobalKey<RefreshIndicatorState>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
initializeDateFormatting();
|
||||
_scrollController.addListener(_listenForLoadNewData);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_scrollController.removeListener(_listenForLoadNewData);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _listenForLoadNewData() {
|
||||
final currState = context.read<InboxCubit>().state;
|
||||
if (_scrollController.offset >=
|
||||
_scrollController.position.maxScrollExtent * 0.75 &&
|
||||
!currState.isLoading &&
|
||||
!currState.isLastPageLoaded) {
|
||||
try {
|
||||
context.read<InboxCubit>().loadMore();
|
||||
} on PaperlessServerException catch (error, stackTrace) {
|
||||
showErrorMessage(context, error, stackTrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
const _progressBarHeight = 4.0;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(S.of(context).bottomNavInboxPageLabel),
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
appBar: PreferredSize(
|
||||
preferredSize:
|
||||
const Size.fromHeight(kToolbarHeight + _progressBarHeight),
|
||||
child: BlocBuilder<InboxCubit, InboxState>(
|
||||
builder: (context, state) {
|
||||
return AppBar(
|
||||
title: Text(S.of(context).bottomNavInboxPageLabel),
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
actions: [
|
||||
if (state.hasLoaded)
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
child: ColoredBox(
|
||||
color: Theme.of(context).colorScheme.secondaryContainer,
|
||||
child: Text(
|
||||
state.value.isEmpty
|
||||
? '0'
|
||||
: '${state.value.first.count} ' +
|
||||
S.of(context).inboxPageUnseenText,
|
||||
textAlign: TextAlign.start,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
).paddedSymmetrically(horizontal: 4.0),
|
||||
),
|
||||
),
|
||||
).paddedSymmetrically(horizontal: 8)
|
||||
],
|
||||
bottom: PreferredSize(
|
||||
preferredSize: const Size.fromHeight(4),
|
||||
child: state.isLoading && state.hasLoaded
|
||||
? const LinearProgressIndicator()
|
||||
: const SizedBox(height: _progressBarHeight),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
actions: [
|
||||
BlocBuilder<InboxCubit, InboxState>(
|
||||
builder: (context, state) {
|
||||
return Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
child: ColoredBox(
|
||||
color: Theme.of(context).colorScheme.secondaryContainer,
|
||||
child: Text(
|
||||
'${state.inboxItems.length} ${S.of(context).inboxPageUnseenText}',
|
||||
textAlign: TextAlign.start,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
).paddedSymmetrically(horizontal: 4.0),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
).paddedSymmetrically(horizontal: 8)
|
||||
],
|
||||
),
|
||||
floatingActionButton: BlocBuilder<InboxCubit, InboxState>(
|
||||
builder: (context, state) {
|
||||
if (!state.isLoaded || state.inboxItems.isEmpty) {
|
||||
if (!state.hasLoaded || state.documents.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
return FloatingActionButton.extended(
|
||||
label: Text(S.of(context).inboxPageMarkAllAsSeenLabel),
|
||||
icon: const Icon(Icons.done_all),
|
||||
onPressed: state.isLoaded && state.inboxItems.isNotEmpty
|
||||
onPressed: state.hasLoaded && state.documents.isNotEmpty
|
||||
? () => _onMarkAllAsSeen(
|
||||
state.inboxItems,
|
||||
state.documents,
|
||||
state.inboxTags,
|
||||
)
|
||||
: null,
|
||||
);
|
||||
},
|
||||
),
|
||||
body: BlocConsumer<InboxCubit, InboxState>(
|
||||
listenWhen: (previous, current) =>
|
||||
!previous.isLoaded && current.isLoaded,
|
||||
listener: (context, state) =>
|
||||
context.read<InboxCubit>().loadSuggestions(),
|
||||
body: BlocBuilder<InboxCubit, InboxState>(
|
||||
builder: (context, state) {
|
||||
if (!state.isLoaded) {
|
||||
if (!state.hasLoaded) {
|
||||
return const DocumentsListLoadingWidget();
|
||||
}
|
||||
|
||||
if (state.inboxItems.isEmpty) {
|
||||
if (state.documents.isEmpty) {
|
||||
return InboxEmptyWidget(
|
||||
emptyStateRefreshIndicatorKey: _emptyStateRefreshIndicatorKey,
|
||||
);
|
||||
@@ -95,7 +128,7 @@ class _InboxPageState extends State<InboxPage> {
|
||||
|
||||
// Build a list of slivers alternating between SliverToBoxAdapter
|
||||
// (group header) and a SliverList (inbox items).
|
||||
final List<Widget> slivers = _groupByDate(state.inboxItems)
|
||||
final List<Widget> slivers = _groupByDate(state.documents)
|
||||
.entries
|
||||
.map(
|
||||
(entry) => [
|
||||
@@ -148,6 +181,7 @@ class _InboxPageState extends State<InboxPage> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: CustomScrollView(
|
||||
controller: _scrollController,
|
||||
slivers: [
|
||||
SliverToBoxAdapter(
|
||||
child: HintCard(
|
||||
@@ -157,7 +191,7 @@ class _InboxPageState extends State<InboxPage> {
|
||||
context.read<InboxCubit>().acknowledgeHint(),
|
||||
),
|
||||
),
|
||||
...slivers
|
||||
...slivers,
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -234,7 +268,7 @@ class _InboxPageState extends State<InboxPage> {
|
||||
|
||||
Future<bool> _onItemDismissed(DocumentModel doc) async {
|
||||
try {
|
||||
final removedTags = await context.read<InboxCubit>().remove(doc);
|
||||
final removedTags = await context.read<InboxCubit>().removeFromInbox(doc);
|
||||
showSnackBar(
|
||||
context,
|
||||
S.of(context).inboxPageDocumentRemovedMessageText,
|
||||
@@ -261,7 +295,9 @@ class _InboxPageState extends State<InboxPage> {
|
||||
Iterable<int> removedTags,
|
||||
) async {
|
||||
try {
|
||||
await context.read<InboxCubit>().undoRemove(document, removedTags);
|
||||
await context
|
||||
.read<InboxCubit>()
|
||||
.undoRemoveFromInbox(document, removedTags);
|
||||
} on PaperlessServerException catch (error, stackTrace) {
|
||||
showErrorMessage(context, error, stackTrace);
|
||||
}
|
||||
|
||||
@@ -1,25 +1,18 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_mobile/core/repository/provider/label_repositories_provider.dart';
|
||||
import 'package:paperless_mobile/core/repository/state/impl/correspondent_repository_state.dart';
|
||||
import 'package:paperless_mobile/core/repository/state/impl/document_type_repository_state.dart';
|
||||
import 'package:paperless_mobile/extensions/date_time_extensions.dart';
|
||||
import 'package:paperless_mobile/extensions/flutter_extensions.dart';
|
||||
import 'package:paperless_mobile/features/document_details/bloc/document_details_cubit.dart';
|
||||
import 'package:paperless_mobile/features/document_details/view/pages/document_details_page.dart';
|
||||
import 'package:paperless_mobile/features/documents/view/widgets/delete_document_confirmation_dialog.dart';
|
||||
import 'package:paperless_mobile/features/documents/view/widgets/document_preview.dart';
|
||||
import 'package:paperless_mobile/features/inbox/bloc/inbox_cubit.dart';
|
||||
import 'package:paperless_mobile/features/inbox/bloc/state/inbox_state.dart';
|
||||
import 'package:paperless_mobile/features/labels/tags/view/widgets/tags_widget.dart';
|
||||
import 'package:paperless_mobile/features/labels/view/widgets/label_text.dart';
|
||||
import 'package:paperless_mobile/generated/l10n.dart';
|
||||
import 'package:paperless_mobile/util.dart';
|
||||
|
||||
class InboxItem extends StatefulWidget {
|
||||
static const _a4AspectRatio = 1 / 1.4142;
|
||||
@@ -37,6 +30,8 @@ class InboxItem extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _InboxItemState extends State<InboxItem> {
|
||||
// late final Future<FieldSuggestions> _fieldSuggestions;
|
||||
|
||||
bool _isAsnAssignLoading = false;
|
||||
|
||||
@override
|
||||
@@ -65,7 +60,7 @@ class _InboxItemState extends State<InboxItem> {
|
||||
}
|
||||
},
|
||||
child: SizedBox(
|
||||
height: 180,
|
||||
height: 200,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -128,54 +123,66 @@ class _InboxItemState extends State<InboxItem> {
|
||||
) ??
|
||||
false;
|
||||
if (shouldDelete) {
|
||||
context.read<InboxCubit>().deleteDocument(widget.document);
|
||||
context.read<InboxCubit>().delete(widget.document);
|
||||
}
|
||||
},
|
||||
),
|
||||
];
|
||||
return BlocBuilder<InboxCubit, InboxState>(
|
||||
builder: (context, state) {
|
||||
return Row(
|
||||
// return FutureBuilder<FieldSuggestions>(
|
||||
// future: _fieldSuggestions,
|
||||
// builder: (context, snapshot) {
|
||||
// List<Widget>? suggestions;
|
||||
// if (!snapshot.hasData) {
|
||||
// suggestions = [
|
||||
// const SizedBox(width: 4),
|
||||
// ];
|
||||
// } else {
|
||||
// if (snapshot.data!.hasSuggestions) {
|
||||
// suggestions = [
|
||||
// const SizedBox(width: 4),
|
||||
// ..._buildSuggestionChips(
|
||||
// chipShape,
|
||||
// snapshot.data!,
|
||||
// context.watch<InboxCubit>().state,
|
||||
// ),
|
||||
// ];
|
||||
// }
|
||||
// }
|
||||
|
||||
return Row(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.bolt_outlined),
|
||||
SizedBox(
|
||||
width: 40,
|
||||
child: Text(
|
||||
S.of(context).inboxPageQuickActionsLabel,
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 2,
|
||||
style: Theme.of(context).textTheme.labelSmall,
|
||||
),
|
||||
),
|
||||
const VerticalDivider(
|
||||
indent: 16,
|
||||
endIndent: 16,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(width: 4.0),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
children: [
|
||||
...actions,
|
||||
if (state.suggestions[widget.document.id] != null) ...[
|
||||
const SizedBox(width: 4),
|
||||
..._buildSuggestionChips(
|
||||
chipShape,
|
||||
state.suggestions[widget.document.id]!,
|
||||
state,
|
||||
)
|
||||
]
|
||||
],
|
||||
const Icon(Icons.bolt_outlined),
|
||||
SizedBox(
|
||||
width: 40,
|
||||
child: Text(
|
||||
S.of(context).inboxPageQuickActionsLabel,
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 2,
|
||||
style: Theme.of(context).textTheme.labelSmall,
|
||||
),
|
||||
),
|
||||
const VerticalDivider(
|
||||
indent: 16,
|
||||
endIndent: 16,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 4.0),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
children: [
|
||||
...actions,
|
||||
// if (suggestions != null) ...suggestions,
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
// );
|
||||
// },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -274,97 +281,103 @@ class _InboxItemState extends State<InboxItem> {
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _buildSuggestionChips(
|
||||
OutlinedBorder chipShape,
|
||||
FieldSuggestions suggestions,
|
||||
InboxState state,
|
||||
) {
|
||||
return [
|
||||
...suggestions.correspondents
|
||||
.whereNot((e) => widget.document.correspondent == e)
|
||||
.map(
|
||||
(e) => ActionChip(
|
||||
avatar: const Icon(Icons.person_outline),
|
||||
shape: chipShape,
|
||||
label: Text(state.availableCorrespondents[e]?.name ?? ''),
|
||||
onPressed: () {
|
||||
context
|
||||
.read<InboxCubit>()
|
||||
.updateDocument(widget.document.copyWith(
|
||||
correspondent: e,
|
||||
overwriteCorrespondent: true,
|
||||
))
|
||||
.then((value) => showSnackBar(
|
||||
context,
|
||||
S
|
||||
.of(context)
|
||||
.inboxPageSuggestionSuccessfullyAppliedMessage));
|
||||
},
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
...suggestions.documentTypes
|
||||
.whereNot((e) => widget.document.documentType == e)
|
||||
.map(
|
||||
(e) => ActionChip(
|
||||
avatar: const Icon(Icons.description_outlined),
|
||||
shape: chipShape,
|
||||
label: Text(state.availableDocumentTypes[e]?.name ?? ''),
|
||||
onPressed: () => context
|
||||
.read<InboxCubit>()
|
||||
.updateDocument(widget.document
|
||||
.copyWith(documentType: e, overwriteDocumentType: true))
|
||||
.then((value) => showSnackBar(
|
||||
context,
|
||||
S
|
||||
.of(context)
|
||||
.inboxPageSuggestionSuccessfullyAppliedMessage)),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
...suggestions.tags
|
||||
.whereNot((e) => widget.document.tags.contains(e))
|
||||
.map(
|
||||
(e) => ActionChip(
|
||||
avatar: const Icon(Icons.label_outline),
|
||||
shape: chipShape,
|
||||
label: Text(state.availableTags[e]?.name ?? ''),
|
||||
onPressed: () {
|
||||
context
|
||||
.read<InboxCubit>()
|
||||
.updateDocument(widget.document.copyWith(
|
||||
tags: {...widget.document.tags, e}.toList(),
|
||||
overwriteTags: true,
|
||||
))
|
||||
.then((value) => showSnackBar(
|
||||
context,
|
||||
S
|
||||
.of(context)
|
||||
.inboxPageSuggestionSuccessfullyAppliedMessage));
|
||||
},
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
...suggestions.dates
|
||||
.whereNot((e) => widget.document.created.isEqualToIgnoringDate(e))
|
||||
.map(
|
||||
(e) => ActionChip(
|
||||
avatar: const Icon(Icons.calendar_today_outlined),
|
||||
shape: chipShape,
|
||||
label: Text(
|
||||
"${S.of(context).documentCreatedPropertyLabel}: ${DateFormat.yMd().format(e)}",
|
||||
),
|
||||
onPressed: () => context
|
||||
.read<InboxCubit>()
|
||||
.updateDocument(widget.document.copyWith(created: e))
|
||||
.then((value) => showSnackBar(
|
||||
context,
|
||||
S
|
||||
.of(context)
|
||||
.inboxPageSuggestionSuccessfullyAppliedMessage)),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
].expand((element) => [element, const SizedBox(width: 4)]).toList();
|
||||
}
|
||||
// List<Widget> _buildSuggestionChips(
|
||||
// OutlinedBorder chipShape,
|
||||
// FieldSuggestions suggestions,
|
||||
// InboxState state,
|
||||
// ) {
|
||||
// return [
|
||||
// ...suggestions.correspondents
|
||||
// .whereNot((e) => widget.document.correspondent == e)
|
||||
// .map(
|
||||
// (e) => ActionChip(
|
||||
// avatar: const Icon(Icons.person_outline),
|
||||
// shape: chipShape,
|
||||
// label: Text(state.availableCorrespondents[e]?.name ?? ''),
|
||||
// onPressed: () {
|
||||
// context
|
||||
// .read<InboxCubit>()
|
||||
// .update(
|
||||
// widget.document.copyWith(correspondent: () => e),
|
||||
// )
|
||||
// .then((value) => showSnackBar(
|
||||
// context,
|
||||
// S
|
||||
// .of(context)
|
||||
// .inboxPageSuggestionSuccessfullyAppliedMessage));
|
||||
// },
|
||||
// ),
|
||||
// )
|
||||
// .toList(),
|
||||
// ...suggestions.documentTypes
|
||||
// .whereNot((e) => widget.document.documentType == e)
|
||||
// .map(
|
||||
// (e) => ActionChip(
|
||||
// avatar: const Icon(Icons.description_outlined),
|
||||
// shape: chipShape,
|
||||
// label: Text(state.availableDocumentTypes[e]?.name ?? ''),
|
||||
// onPressed: () => context
|
||||
// .read<InboxCubit>()
|
||||
// .update(
|
||||
// widget.document.copyWith(documentType: () => e),
|
||||
// shouldReload: false,
|
||||
// )
|
||||
// .then((value) => showSnackBar(
|
||||
// context,
|
||||
// S
|
||||
// .of(context)
|
||||
// .inboxPageSuggestionSuccessfullyAppliedMessage)),
|
||||
// ),
|
||||
// )
|
||||
// .toList(),
|
||||
// ...suggestions.tags
|
||||
// .whereNot((e) => widget.document.tags.contains(e))
|
||||
// .map(
|
||||
// (e) => ActionChip(
|
||||
// avatar: const Icon(Icons.label_outline),
|
||||
// shape: chipShape,
|
||||
// label: Text(state.availableTags[e]?.name ?? ''),
|
||||
// onPressed: () {
|
||||
// context
|
||||
// .read<InboxCubit>()
|
||||
// .update(
|
||||
// widget.document.copyWith(
|
||||
// tags: {...widget.document.tags, e}.toList(),
|
||||
// ),
|
||||
// shouldReload: false,
|
||||
// )
|
||||
// .then((value) => showSnackBar(
|
||||
// context,
|
||||
// S
|
||||
// .of(context)
|
||||
// .inboxPageSuggestionSuccessfullyAppliedMessage));
|
||||
// },
|
||||
// ),
|
||||
// )
|
||||
// .toList(),
|
||||
// ...suggestions.dates
|
||||
// .whereNot((e) => widget.document.created.isEqualToIgnoringDate(e))
|
||||
// .map(
|
||||
// (e) => ActionChip(
|
||||
// avatar: const Icon(Icons.calendar_today_outlined),
|
||||
// shape: chipShape,
|
||||
// label: Text(
|
||||
// "${S.of(context).documentCreatedPropertyLabel}: ${DateFormat.yMd().format(e)}",
|
||||
// ),
|
||||
// onPressed: () => context
|
||||
// .read<InboxCubit>()
|
||||
// .update(
|
||||
// widget.document.copyWith(created: e),
|
||||
// shouldReload: false,
|
||||
// )
|
||||
// .then((value) => showSnackBar(
|
||||
// context,
|
||||
// S
|
||||
// .of(context)
|
||||
// .inboxPageSuggestionSuccessfullyAppliedMessage)),
|
||||
// ),
|
||||
// )
|
||||
// .toList(),
|
||||
// ].expand((element) => [element, const SizedBox(width: 4)]).toList();
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user