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 {
|
||||
state = KnowledgeState(
|
||||
noteType: state.noteType,
|
||||
activeTags: state.activeTags,
|
||||
searchQuery: state.searchQuery,
|
||||
);
|
||||
await _fetchFromScratch();
|
||||
// Keep current items visible during re-fetch (no flicker).
|
||||
try {
|
||||
if (state.noteType == 'task') {
|
||||
final tasks = await ref.read(tasksApiProvider).getAll();
|
||||
final items = {
|
||||
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 ─────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user