mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-09-29 16:06:36 +08:00
f1bdb2e2ef
- 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
34 lines
765 B
TypeScript
34 lines
765 B
TypeScript
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];
|
|
};
|