jan/web/app/_helpers/atoms/DownloadState.atom.ts
NamH 00c944c0b5
Add empty model conversation (#254)
* add empty conversation model selection

Signed-off-by: James <james@jan.ai>

* chore: using secondary button instead of sidebar button

Signed-off-by: James <james@jan.ai>

---------

Signed-off-by: James <james@jan.ai>
Co-authored-by: James <james@jan.ai>
2023-10-02 19:36:10 -07:00

33 lines
933 B
TypeScript

import { DownloadState } from "@/_models/DownloadState";
import { atom } from "jotai";
// download states
export const modelDownloadStateAtom = atom<Record<string, DownloadState>>({});
export const setDownloadStateAtom = atom(
null,
(get, set, state: DownloadState) => {
const currentState = { ...get(modelDownloadStateAtom) };
console.debug(
`current download state for ${state.fileName} is ${JSON.stringify(state)}`
);
currentState[state.fileName] = state;
set(modelDownloadStateAtom, currentState);
}
);
export const setDownloadStateSuccessAtom = atom(
null,
(get, set, fileName: string) => {
const currentState = { ...get(modelDownloadStateAtom) };
const state = currentState[fileName];
if (!state) {
console.error(`Cannot find download state for ${fileName}`);
return;
}
delete currentState[fileName];
set(modelDownloadStateAtom, currentState);
}
);