Files
strata/apps/host/src/lib/kept-state.ts
T
Niko1221 1237d9a5fa downloads and models: live progress, parts counted, choices kept, clear NVFP4 names, More versions list
- native state: the host's 'native' events are applied at once; the light poll (1 s while a job runs, none while hidden) is no longer
  held by a slow forced read; a read that never answers is dropped after 20 s
- install progress: every file of the model is counted (parts, picture reader beside the model folders, NVFP4 packs by their pinned sizes);
  the bar no longer sits at 99 % while the picture reader downloads; the screen names the part (part 2 of 4) and lists the parts
- a config is 'ready' only when every part of a multi-part GGUF is whole
- Models page keeps version, context, computer use, picture reading and expert choices across tabs; Read pictures is on for a version that
  is not downloaded yet; the running download is named
- version list: smaller rows, a Downloaded tag, NVFP4 / NVFP4-NVIDIA / NVFP4-QAD named by who made them with one line each
- first-run page: the four recommended versions, then a More versions list (the Models page list)
2026-10-18 20:47:43 +02:00

24 lines
1.2 KiB
TypeScript

import { useCallback, useEffect, useState, type Dispatch, type SetStateAction } from 'react';
/**
* A piece of screen state that survives leaving the screen. The Models page keeps its choices (version, context, computer use, picture
* reading ...) in useState, so going to Monitor and back reset them and a person lost track of what they were downloading. Kept values
* live in memory for the whole session (not on disk: a new start begins from the installed model again).
*/
const kept = new Map<string, unknown>();
export function useKept<T>(key: string, initial: T): [T, Dispatch<SetStateAction<T>>] {
const [value, setValue] = useState<T>(() => (kept.has(key) ? kept.get(key) as T : initial));
useEffect(() => { kept.set(key, value); }, [key, value]);
const set = useCallback<Dispatch<SetStateAction<T>>>(next => setValue(old => {
const result = typeof next === 'function' ? (next as (o: T) => T)(old) : next;
kept.set(key, result);
return result;
}), [key]);
return [value, set];
}
export const keptValue = <T,>(key: string): T | undefined => kept.get(key) as T | undefined;
/** Forget everything kept (tests, and a changed installation). */
export const forgetKept = () => kept.clear();