mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-16 02:12:24 -06:00
Small refactorings to inbox
This commit is contained in:
@@ -18,16 +18,20 @@ class InboxCubit extends HydratedCubit<InboxState> with PagedDocumentsMixin {
|
||||
|
||||
final PaperlessDocumentsApi _documentsApi;
|
||||
|
||||
final PaperlessServerStatsApi _statsApi;
|
||||
|
||||
final List<StreamSubscription> _subscriptions = [];
|
||||
|
||||
@override
|
||||
PaperlessDocumentsApi get api => _documentsApi;
|
||||
|
||||
Timer? _taskTimer;
|
||||
InboxCubit(
|
||||
this._tagsRepository,
|
||||
this._documentsApi,
|
||||
this._correspondentRepository,
|
||||
this._documentTypeRepository,
|
||||
this._statsApi,
|
||||
) : super(
|
||||
InboxState(
|
||||
availableCorrespondents:
|
||||
@@ -60,6 +64,15 @@ class InboxCubit extends HydratedCubit<InboxState> with PagedDocumentsMixin {
|
||||
}
|
||||
}),
|
||||
);
|
||||
//TODO: Do this properly in a background task.
|
||||
_taskTimer = Timer.periodic(const Duration(seconds: 5), (timer) {
|
||||
refreshItemsInInboxCount();
|
||||
});
|
||||
}
|
||||
|
||||
void refreshItemsInInboxCount() async {
|
||||
final stats = await _statsApi.getServerStatistics();
|
||||
emit(state.copyWith(itemsInInboxCount: stats.documentsInInbox));
|
||||
}
|
||||
|
||||
///
|
||||
@@ -175,9 +188,10 @@ class InboxCubit extends HydratedCubit<InboxState> with PagedDocumentsMixin {
|
||||
|
||||
@override
|
||||
Future<void> close() {
|
||||
_subscriptions.forEach((element) {
|
||||
element.cancel();
|
||||
});
|
||||
_taskTimer?.cancel();
|
||||
for (var sub in _subscriptions) {
|
||||
sub.cancel();
|
||||
}
|
||||
return super.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ class InboxState extends PagedDocumentsState {
|
||||
|
||||
final Map<int, Correspondent> availableCorrespondents;
|
||||
|
||||
final int itemsInInboxCount;
|
||||
|
||||
@JsonKey()
|
||||
final bool isHintAcknowledged;
|
||||
|
||||
@@ -29,6 +31,7 @@ class InboxState extends PagedDocumentsState {
|
||||
this.availableTags = const {},
|
||||
this.availableDocumentTypes = const {},
|
||||
this.availableCorrespondents = const {},
|
||||
this.itemsInInboxCount = 0,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -43,6 +46,7 @@ class InboxState extends PagedDocumentsState {
|
||||
availableTags,
|
||||
availableDocumentTypes,
|
||||
availableCorrespondents,
|
||||
itemsInInboxCount,
|
||||
];
|
||||
|
||||
InboxState copyWith({
|
||||
@@ -56,6 +60,7 @@ class InboxState extends PagedDocumentsState {
|
||||
Map<int, Correspondent>? availableCorrespondents,
|
||||
Map<int, DocumentType>? availableDocumentTypes,
|
||||
Map<int, FieldSuggestions>? suggestions,
|
||||
int? itemsInInboxCount,
|
||||
}) {
|
||||
return InboxState(
|
||||
hasLoaded: hasLoaded ?? super.hasLoaded,
|
||||
@@ -69,6 +74,7 @@ class InboxState extends PagedDocumentsState {
|
||||
availableDocumentTypes ?? this.availableDocumentTypes,
|
||||
availableTags: availableTags ?? this.availableTags,
|
||||
filter: filter ?? super.filter,
|
||||
itemsInInboxCount: itemsInInboxCount ?? this.itemsInInboxCount,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user