feat: Externalize settings into LocalUserAppState, fix bugs

This commit is contained in:
Anton Stubenbord
2023-04-26 01:29:14 +02:00
parent 8c2a6928b4
commit 37c9559888
41 changed files with 340 additions and 316 deletions

View File

@@ -145,7 +145,7 @@ class _LabelsPageState extends State<LabelsPage> with SingleTickerProviderStateM
LabelTabView<Correspondent>(
labels: context.watch<LabelCubit>().state.correspondents,
filterBuilder: (label) => DocumentFilter(
correspondent: IdQueryParameter.fromId(label.id),
correspondent: IdQueryParameter.fromId(label.id!),
pageSize: label.documentCount ?? 0,
),
onEdit: _openEditCorrespondentPage,
@@ -166,7 +166,7 @@ class _LabelsPageState extends State<LabelsPage> with SingleTickerProviderStateM
LabelTabView<DocumentType>(
labels: context.watch<LabelCubit>().state.documentTypes,
filterBuilder: (label) => DocumentFilter(
documentType: IdQueryParameter.fromId(label.id),
documentType: IdQueryParameter.fromId(label.id!),
pageSize: label.documentCount ?? 0,
),
onEdit: _openEditDocumentTypePage,
@@ -218,7 +218,7 @@ class _LabelsPageState extends State<LabelsPage> with SingleTickerProviderStateM
labels: context.watch<LabelCubit>().state.storagePaths,
onEdit: _openEditStoragePathPage,
filterBuilder: (label) => DocumentFilter(
storagePath: IdQueryParameter.fromId(label.id),
storagePath: IdQueryParameter.fromId(label.id!),
pageSize: label.documentCount ?? 0,
),
contentBuilder: (path) => Text(path.path),

View File

@@ -80,11 +80,12 @@ class _FullscreenLabelFormState<T extends Label> extends State<FullscreenLabelFo
final index = AutocompleteHighlightedOption.of(context);
final value = index.isNegative ? null : options.elementAt(index);
widget.onSubmit(
returnValue: IdQueryParameter.fromId(
value?.whenOrNull(
fromId: (id) => id,
),
));
returnValue: value?.maybeWhen(
fromId: (id) => IdQueryParameter.fromId(id),
orElse: () => const IdQueryParameter.unset(),
) ??
const IdQueryParameter.unset(),
);
},
autofocus: true,
style: theme.textTheme.bodyLarge?.apply(
@@ -167,7 +168,7 @@ class _FullscreenLabelFormState<T extends Label> extends State<FullscreenLabelFo
if (widget.initialValue == null) {
// If nothing is selected yet, show all options first.
for (final option in widget.options.values) {
yield IdQueryParameter.fromId(option.id);
yield IdQueryParameter.fromId(option.id!);
}
if (widget.showNotAssignedOption) {
yield const IdQueryParameter.notAssigned();
@@ -189,7 +190,7 @@ class _FullscreenLabelFormState<T extends Label> extends State<FullscreenLabelFo
if (initialValue is SetIdQueryParameter && option.id == initialValue.id) {
continue;
}
yield IdQueryParameter.fromId(option.id);
yield IdQueryParameter.fromId(option.id!);
}
}
} else {
@@ -198,7 +199,7 @@ class _FullscreenLabelFormState<T extends Label> extends State<FullscreenLabelFo
widget.options.values.where((e) => e.name.trim().toLowerCase().contains(normalizedQuery));
if (matches.isNotEmpty) {
for (final match in matches) {
yield IdQueryParameter.fromId(match.id);
yield IdQueryParameter.fromId(match.id!);
}
if (widget.showNotAssignedOption) {
yield const IdQueryParameter.notAssigned();
@@ -225,7 +226,7 @@ class _FullscreenLabelFormState<T extends Label> extends State<FullscreenLabelFo
unset: () => S.of(context)!.startTyping,
notAssigned: () => S.of(context)!.notAssigned,
anyAssigned: () => S.of(context)!.anyAssigned,
fromId: (id) => widget.options[id]!.name,
fromId: (id) => widget.options[id]?.name ?? S.of(context)!.startTyping,
);
}

View File

@@ -49,7 +49,7 @@ class LabelFormField<T extends Label> extends StatelessWidget {
unset: () => '',
notAssigned: () => S.of(context)!.notAssigned,
anyAssigned: () => S.of(context)!.anyAssigned,
fromId: (id) => options[id]!.name,
fromId: (id) => options[id]?.name,
) ??
'';
}
@@ -142,7 +142,7 @@ class LabelFormField<T extends Label> extends StatelessWidget {
child: ActionChip(
label: Text(suggestion.name),
onPressed: () => field.didChange(
IdQueryParameter.fromId(suggestion.id),
IdQueryParameter.fromId(suggestion.id!),
),
),
);

View File

@@ -5,7 +5,7 @@ import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_mobile/core/config/hive/hive_config.dart';
import 'package:paperless_mobile/features/linked_documents/cubit/linked_documents_cubit.dart';
import 'package:paperless_mobile/features/linked_documents/view/linked_documents_page.dart';
import 'package:paperless_mobile/core/database/tables/user_account.dart';
import 'package:paperless_mobile/core/database/tables/local_user_account.dart';
import 'package:paperless_mobile/core/database/tables/global_settings.dart';
import 'package:paperless_mobile/helpers/format_helpers.dart';