feat: Add debug logs for label loading

This commit is contained in:
Anton Stubenbord
2023-06-02 15:03:18 +02:00
parent 6896c13f3b
commit 29a0e73286
9 changed files with 108 additions and 61 deletions

View File

@@ -8,9 +8,7 @@ import 'package:paperless_mobile/core/repository/persistent_repository.dart';
class LabelRepository extends PersistentRepository<LabelRepositoryState> {
final PaperlessLabelsApi _api;
LabelRepository(this._api) : super(const LabelRepositoryState()) {
initialize();
}
LabelRepository(this._api) : super(const LabelRepositoryState());
Future<void> initialize() {
debugPrint("Initializing labels...");
@@ -19,7 +17,9 @@ class LabelRepository extends PersistentRepository<LabelRepositoryState> {
findAllDocumentTypes(),
findAllStoragePaths(),
findAllTags(),
]);
]).catchError((error) {
debugPrint(error.toString());
}, test: (error) => false);
}
Future<Tag> createTag(Tag object) async {
@@ -87,11 +87,15 @@ class LabelRepository extends PersistentRepository<LabelRepositoryState> {
}
Future<Iterable<Correspondent>> findAllCorrespondents([Iterable<int>? ids]) async {
debugPrint("Loading correspondents...");
final correspondents = await _api.getCorrespondents(ids);
final updatedState = {...state.correspondents}
..addEntries(correspondents.map((e) => MapEntry(e.id!, e)));
debugPrint("${correspondents.length} correspondents successfully loaded.");
final updatedState = {
...state.correspondents,
}..addAll({for (var element in correspondents) element.id!: element});
debugPrint("Pushing new correspondents state.");
emit(state.copyWith(correspondents: updatedState));
debugPrint("New correspondents state pushed.");
return correspondents;
}

View File

@@ -27,7 +27,6 @@ class _DocumentMetaDataWidgetState extends State<DocumentMetaDataWidget> {
Widget build(BuildContext context) {
return BlocBuilder<DocumentDetailsCubit, DocumentDetailsState>(
builder: (context, state) {
debugPrint("Building state...");
if (state.metaData == null) {
return const SliverToBoxAdapter(
child: Center(

View File

@@ -65,7 +65,10 @@ class DocumentsState extends DocumentPagingState {
documentTypes,
tags,
storagePaths,
...super.props,
super.filter,
super.hasLoaded,
super.isLoading,
super.value,
];
@override

View File

@@ -438,36 +438,53 @@ class _DocumentsPageState extends State<DocumentsPage> with SingleTickerProvider
}
void _addTagToFilter(int tagId) {
final cubit = context.read<DocumentsCubit>();
try {
final tagsQuery = context.read<DocumentsCubit>().state.filter.tags is IdsTagsQuery
? context.read<DocumentsCubit>().state.filter.tags as IdsTagsQuery
: const IdsTagsQuery();
if (tagsQuery.include.contains(tagId)) {
context.read<DocumentsCubit>().updateCurrentFilter(
cubit.state.filter.tags.maybeMap(
ids: (state) {
if (state.include.contains(tagId)) {
cubit.updateCurrentFilter(
(filter) => filter.copyWith(
tags: tagsQuery.copyWith(
include: tagsQuery.include.whereNot((id) => id == tagId).toList(),
exclude: tagsQuery.exclude.whereNot((id) => id == tagId).toList()),
tags: state.copyWith(
include: state.include.whereNot((element) => element == tagId).toList(),
),
),
);
} else if (state.exclude.contains(tagId)) {
cubit.updateCurrentFilter(
(filter) => filter.copyWith(
tags: state.copyWith(
exclude: state.exclude.whereNot((element) => element == tagId).toList(),
),
),
);
} else {
context.read<DocumentsCubit>().updateCurrentFilter(
cubit.updateCurrentFilter(
(filter) => filter.copyWith(
tags: tagsQuery.copyWith(include: [...tagsQuery.include, tagId]),
tags: state.copyWith(include: [...state.include, tagId]),
),
);
}
},
orElse: () {
cubit.updateCurrentFilter(
(filter) => filter.copyWith(tags: TagsQuery.ids(include: [tagId])),
);
},
);
} on PaperlessServerException catch (error, stackTrace) {
showErrorMessage(context, error, stackTrace);
}
}
void _addCorrespondentToFilter(int? correspondentId) {
if (correspondentId == null) return;
final cubit = context.read<DocumentsCubit>();
try {
final correspondent = cubit.state.filter.correspondent;
if (correspondent is SetIdQueryParameter) {
if (correspondentId == null || correspondent.id == correspondentId) {
cubit.state.filter.correspondent.maybeWhen(
fromId: (id) {
if (id == correspondentId) {
cubit.updateCurrentFilter(
(filter) => filter.copyWith(correspondent: const IdQueryParameter.unset()),
);
@@ -476,18 +493,25 @@ class _DocumentsPageState extends State<DocumentsPage> with SingleTickerProvider
(filter) => filter.copyWith(correspondent: IdQueryParameter.fromId(correspondentId)),
);
}
}
},
orElse: () {
cubit.updateCurrentFilter(
(filter) => filter.copyWith(correspondent: IdQueryParameter.fromId(correspondentId)),
);
},
);
} on PaperlessServerException catch (error, stackTrace) {
showErrorMessage(context, error, stackTrace);
}
}
void _addDocumentTypeToFilter(int? documentTypeId) {
if (documentTypeId == null) return;
final cubit = context.read<DocumentsCubit>();
try {
final documentType = cubit.state.filter.documentType;
if (documentType is SetIdQueryParameter) {
if (documentTypeId == null || documentType.id == documentTypeId) {
cubit.state.filter.documentType.maybeWhen(
fromId: (id) {
if (id == documentTypeId) {
cubit.updateCurrentFilter(
(filter) => filter.copyWith(documentType: const IdQueryParameter.unset()),
);
@@ -496,18 +520,25 @@ class _DocumentsPageState extends State<DocumentsPage> with SingleTickerProvider
(filter) => filter.copyWith(documentType: IdQueryParameter.fromId(documentTypeId)),
);
}
}
},
orElse: () {
cubit.updateCurrentFilter(
(filter) => filter.copyWith(documentType: IdQueryParameter.fromId(documentTypeId)),
);
},
);
} on PaperlessServerException catch (error, stackTrace) {
showErrorMessage(context, error, stackTrace);
}
}
void _addStoragePathToFilter(int? pathId) {
if (pathId == null) return;
final cubit = context.read<DocumentsCubit>();
try {
final path = cubit.state.filter.documentType;
if (path is SetIdQueryParameter) {
if (pathId == null || path.id == pathId) {
cubit.state.filter.storagePath.maybeWhen(
fromId: (id) {
if (id == pathId) {
cubit.updateCurrentFilter(
(filter) => filter.copyWith(storagePath: const IdQueryParameter.unset()),
);
@@ -516,7 +547,13 @@ class _DocumentsPageState extends State<DocumentsPage> with SingleTickerProvider
(filter) => filter.copyWith(storagePath: IdQueryParameter.fromId(pathId)),
);
}
}
},
orElse: () {
cubit.updateCurrentFilter(
(filter) => filter.copyWith(storagePath: IdQueryParameter.fromId(pathId)),
);
},
);
} on PaperlessServerException catch (error, stackTrace) {
showErrorMessage(context, error, stackTrace);
}

View File

@@ -1,3 +1,4 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:paperless_mobile/core/repository/label_repository.dart';
@@ -86,6 +87,8 @@ class DocumentListItem extends DocumentItem {
const TextSpan(text: '\u30FB'),
TextSpan(
text: labels.documentTypes[document.documentType]?.name,
recognizer: TapGestureRecognizer()
..onTap = () => onDocumentTypeSelected?.call(document.documentType),
),
]
: null,

View File

@@ -219,8 +219,10 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
];
final routes = <Widget>[
const DocumentsPage(),
if (LocalUserAccount.current.paperlessUser
.hasPermission(PermissionAction.add, PermissionTarget.document))
if (LocalUserAccount.current.paperlessUser.hasPermission(
PermissionAction.add,
PermissionTarget.document,
))
const ScannerPage(),
const LabelsPage(),
const InboxPage(),

View File

@@ -98,7 +98,7 @@ class HomeRoute extends StatelessWidget {
return MultiProvider(
providers: [
ProxyProvider<PaperlessLabelsApi, LabelRepository>(
update: (context, value, previous) => LabelRepository(value),
update: (context, value, previous) => LabelRepository(value)..initialize(),
),
ProxyProvider<PaperlessSavedViewsApi, SavedViewRepository>(
update: (context, value, previous) => SavedViewRepository(value)..initialize(),

View File

@@ -44,13 +44,15 @@ mixin DocumentPagingBlocMixin<State extends DocumentPagingState> on BlocBase<Sta
emit(state.copyWithPaged(isLoading: true));
final result = await api.findAll(filter.copyWith(page: 1));
emit(state.copyWithPaged(
emit(
state.copyWithPaged(
filter: filter,
value: [result],
hasLoaded: true,
));
),
);
} finally {
await onFilterUpdated(filter);
// await onFilterUpdated(filter);
emit(state.copyWithPaged(isLoading: false));
}
}

View File

@@ -2,16 +2,13 @@ import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:hive_flutter/adapters.dart';
import 'package:paperless_mobile/core/config/hive/hive_config.dart';
import 'package:paperless_mobile/core/database/tables/global_settings.dart';
import 'package:paperless_mobile/core/database/tables/local_user_account.dart';
import 'package:paperless_mobile/features/home/view/model/api_version.dart';
import 'package:paperless_mobile/features/login/cubit/authentication_cubit.dart';
import 'package:paperless_mobile/features/login/model/login_form_credentials.dart';
import 'package:paperless_mobile/features/login/view/login_page.dart';
import 'package:paperless_mobile/features/settings/view/dialogs/switch_account_dialog.dart';
import 'package:paperless_mobile/features/settings/view/pages/switching_accounts_page.dart';
import 'package:paperless_mobile/features/settings/view/widgets/global_settings_builder.dart';
import 'package:paperless_mobile/features/settings/view/widgets/user_avatar.dart';
import 'package:paperless_mobile/features/users/view/widgets/user_account_list_tile.dart';
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
import 'package:provider/provider.dart';
@@ -26,7 +23,7 @@ class ManageAccountsPage extends StatelessWidget {
// This is one of the few places where the currentLoggedInUser can be null
// (exactly after loggin out as the current user to be precise).
if (globalSettings.currentLoggedInUser == null) {
return SizedBox.shrink();
return const SizedBox.shrink();
}
return ValueListenableBuilder(
valueListenable: Hive.box<LocalUserAccount>(HiveBoxes.localUserAccount).listenable(),