Project NOMAD is an offline-first knowledge and education server. Wikipedia, thousands of books, courses, maps, and optional local AI, all running on hardware you own with no internet required.
TypeScript
fix(content): refresh installed ZIMs when a download completes to prune ghost entries (#1099)
chriscrosstalk063c78488972
diff --git a/admin/inertia/pages/settings/zim/remote-explorer.tsx b/admin/inertia/pages/settings/zim/remote-explorer.tsxindex bdfe53f1..4e42b0f2 100644--- a/admin/inertia/pages/settings/zim/remote-explorer.tsx+++ b/admin/inertia/pages/settings/zim/remote-explorer.tsx@@ -174,6 +174,26 @@ export default function ZimRemoteExplorer() {}, [data, downloads, localFiles])const hasMore = useMemo(() => data?.pages[data.pages.length - 1]?.has_more || false, [data])+ // When a ZIM download drops off the polled downloads list it has completed (or been+ // cancelled). The installed-files query (refetchOnWindowFocus is off) won't otherwise+ // refresh, so a just-installed ZIM stays absent from `localFiles` and reappears in the+ // accumulated remote pages as a ghost entry. Refresh it so the item is pruned.+ const prevDownloadKeysRef = useRef<Set<string>>(new Set())+ useEffect(() => {+ const currentKeys = new Set((downloads ?? []).map((d) => d.jobId))+ let anyRemoved = false+ for (const key of prevDownloadKeysRef.current) {+ if (!currentKeys.has(key)) {+ anyRemoved = true+ break+ }+ }+ prevDownloadKeysRef.current = currentKeys+ if (anyRemoved) {+ queryClient.invalidateQueries({ queryKey: [ZIM_FILES_KEY] })+ }+ }, [downloads, queryClient])+const fetchOnBottomReached = useCallback((parentRef?: HTMLDivElement | null) => {if (parentRef) {