jan/web/helpers/atoms/DownloadState.atom.ts
Louis d29d076a3e
fix: #396 - allow user to cancel a model download (#530)
* fix: #396 - allow user to cancel model download

* chore: fix typo
2023-11-02 19:58:56 +07:00

31 lines
861 B
TypeScript

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)
}
)