fix(knowledge): hold stale items during refresh to eliminate flicker
This commit is contained in:
@@ -115,12 +115,43 @@ class KnowledgeNotifier extends Notifier<KnowledgeState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> refresh() async {
|
Future<void> refresh() async {
|
||||||
state = KnowledgeState(
|
// Keep current items visible during re-fetch (no flicker).
|
||||||
noteType: state.noteType,
|
try {
|
||||||
activeTags: state.activeTags,
|
if (state.noteType == 'task') {
|
||||||
searchQuery: state.searchQuery,
|
final tasks = await ref.read(tasksApiProvider).getAll();
|
||||||
);
|
final items = {
|
||||||
await _fetchFromScratch();
|
for (final t in tasks) t.id: KnowledgeItem.fromTask(t),
|
||||||
|
};
|
||||||
|
state = state.copyWith(
|
||||||
|
ids: tasks.map((t) => t.id).toList(),
|
||||||
|
items: items,
|
||||||
|
totalIds: tasks.length,
|
||||||
|
hasMore: false,
|
||||||
|
);
|
||||||
|
await _loadCounts();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final (ids, total) = await _repo.fetchIds(
|
||||||
|
noteType: state.noteType,
|
||||||
|
tags: state.activeTags,
|
||||||
|
q: state.searchQuery,
|
||||||
|
limit: 50,
|
||||||
|
offset: 0,
|
||||||
|
);
|
||||||
|
// Hydrate the new IDs
|
||||||
|
final batch = await _repo.fetchBatch(ids);
|
||||||
|
final freshItems = {for (final item in batch) item.id: item};
|
||||||
|
state = state.copyWith(
|
||||||
|
ids: ids,
|
||||||
|
items: freshItems,
|
||||||
|
totalIds: total,
|
||||||
|
hasMore: ids.length < total,
|
||||||
|
);
|
||||||
|
await Future.wait([_loadCounts(), _loadTags()]);
|
||||||
|
} catch (_) {
|
||||||
|
// Silent — stale data is better than an error on refresh
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Scroll-triggered loaders ─────────────────────────────────────────────
|
// ── Scroll-triggered loaders ─────────────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user