fix: model download state is not updated accordingly

This commit is contained in:
Louis 2023-11-16 17:53:01 +07:00
parent 38b2e5e7a2
commit c5d4163869
2 changed files with 7 additions and 2 deletions

View File

@ -105,7 +105,7 @@ export default function EventHandler({ children }: { children: ReactNode }) {
function handleDownloadSuccess(state: any) { function handleDownloadSuccess(state: any) {
if (state && state.fileName && state.success === true) { if (state && state.fileName && state.success === true) {
state.fileName = state.fileName.replace('models/', '') state.fileName = state.fileName.split('/').pop() ?? ''
setDownloadStateSuccess(state.fileName) setDownloadStateSuccess(state.fileName)
const model = models.find((e) => e.id === state.fileName) const model = models.find((e) => e.id === state.fileName)
if (model) if (model)

View File

@ -27,6 +27,11 @@ export default function EventListenerWrapper({ children }: PropsWithChildren) {
const { setDownloadedModels, downloadedModels } = useGetDownloadedModels() const { setDownloadedModels, downloadedModels } = useGetDownloadedModels()
const { setDownloadState, setDownloadStateSuccess, setDownloadStateFailed } = const { setDownloadState, setDownloadStateSuccess, setDownloadStateFailed } =
useDownloadState() useDownloadState()
const downloadedModelRef = useRef(downloadedModels)
useEffect(() => {
downloadedModelRef.current = downloadedModels
}, [downloadedModels])
useEffect(() => { useEffect(() => {
if (window && window.electronAPI) { if (window && window.electronAPI) {
@ -60,7 +65,7 @@ export default function EventListenerWrapper({ children }: PropsWithChildren) {
.get<ModelPlugin>(PluginType.Model) .get<ModelPlugin>(PluginType.Model)
?.saveModel(model) ?.saveModel(model)
.then(() => { .then(() => {
setDownloadedModels([...downloadedModels, model]) setDownloadedModels([...downloadedModelRef.current, model])
}) })
} }
} }