mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-10-02 00:46:38 +08:00
feat(frontend): implement AJAX no-refresh UX improvements (#276)
- Add dashboard auto-refresh with 5s polling and visibility-aware pause - Harden node realtime reconnection with exponential backoff and polling fallback - Implement local state patching for forward/tunnel/user mutations - Add batch operation progress feedback UI - Add shared list-state helpers for replace/remove operations - Preserve derived UI state during server payload merges Closes #276 Entire-Checkpoint: 7d6188355d7f
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
export const removeItemsById = <T extends { id: number }>(
|
||||
items: T[],
|
||||
ids: Iterable<number>,
|
||||
): T[] => {
|
||||
const idSet = new Set(ids);
|
||||
|
||||
return items.filter((item) => !idSet.has(item.id));
|
||||
};
|
||||
|
||||
export const replaceItemById = <T extends { id: number }>(
|
||||
items: T[],
|
||||
nextItem: T,
|
||||
): T[] => {
|
||||
return items.map((item) => (item.id === nextItem.id ? nextItem : item));
|
||||
};
|
||||
|
||||
export const upsertItemById = <T extends { id: number }>(
|
||||
items: T[],
|
||||
nextItem: T,
|
||||
options?: { prepend?: boolean },
|
||||
): T[] => {
|
||||
const existingIndex = items.findIndex((item) => item.id === nextItem.id);
|
||||
|
||||
if (existingIndex >= 0) {
|
||||
return replaceItemById(items, nextItem);
|
||||
}
|
||||
|
||||
if (options?.prepend) {
|
||||
return [nextItem, ...items];
|
||||
}
|
||||
|
||||
return [...items, nextItem];
|
||||
};
|
||||
Reference in New Issue
Block a user