Skip to content

Commit

Permalink
feat: improve task refresh logic
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasn committed May 5, 2024
1 parent 4ebb4f8 commit 742bd59
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
24 changes: 17 additions & 7 deletions lib/blocs/journal/journal_page_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,29 @@ class JournalPageCubit extends Cubit<JournalPageState> {
);
}

String idMapper(JournalEntity entity) => entity.meta.id;

_updateNotifications.updateStream
.throttleTime(
const Duration(milliseconds: 500),
leading: false,
trailing: true,
)
.listen((event) {
.listen((event) async {
if (_isVisible) {
final displayedIds =
state.pagingController.itemList?.map((e) => e.meta.id).toSet() ??
{};

if (displayedIds.contains(event.id)) {
refreshQuery();
if (showTasks) {
final newIds = (await _runQuery(0)).map(idMapper).toSet();
if (!setEquals(_lastIds, newIds)) {
_lastIds = newIds;
await refreshQuery();
}
} else {
final displayedIds =
state.pagingController.itemList?.map(idMapper).toSet() ?? {};

if (displayedIds.contains(event.id)) {
await refreshQuery();
}
}
}
});
Expand All @@ -122,6 +131,7 @@ class JournalPageCubit extends Cubit<JournalPageState> {
bool taskAsListView = true;

Set<String> _fullTextMatches = {};
Set<String> _lastIds = {};
Set<String> _selectedTaskStatuses = {
'OPEN',
'GROOMED',
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: lotti
description: Achieve your goals and keep your data private with Lotti.
publish_to: 'none'
version: 0.9.459+2504
version: 0.9.459+2505

msix_config:
display_name: LottiApp
Expand Down

0 comments on commit 742bd59

Please sign in to comment.