chore: remove conditional on dataloader

This commit is contained in:
Faisal Amir 2024-11-18 16:48:27 +07:00
parent 5c512ae7b4
commit b8e521164b
2 changed files with 9 additions and 6 deletions

View File

@ -38,9 +38,7 @@ const DataLoader: React.FC<Props> = ({ children }) => {
const { loadDataModel, isUpdated } = useModels()
useEffect(() => {
// Listen for model updates
if (isUpdated) {
loadDataModel()
}
}, [isUpdated, loadDataModel])
useEffect(() => {

View File

@ -1,4 +1,4 @@
import { useCallback, useEffect } from 'react'
import { useCallback, useEffect, useRef } from 'react'
import {
ExtensionTypeEnum,
@ -29,10 +29,15 @@ import {
const useModels = () => {
const setDownloadedModels = useSetAtom(downloadedModelsAtom)
const setExtensionModels = useSetAtom(configuredModelsAtom)
const hasFetchedDownloadedModels = useRef(false) // Track whether the function has been executed
let isUpdated = false
const getData = useCallback(() => {
if (hasFetchedDownloadedModels.current) return
const getDownloadedModels = async () => {
hasFetchedDownloadedModels.current = true
const localModels = (await getModels()).map((e) => ({
...e,
name: ModelManager.instance().models.get(e.id)?.name ?? e.id,
@ -72,7 +77,7 @@ const useModels = () => {
// Fetch all data
getExtensionModels()
getDownloadedModels()
}, [setDownloadedModels, setExtensionModels])
}, [])
const reloadData = useDebouncedCallback(() => getData(), 300)
@ -91,7 +96,7 @@ const useModels = () => {
events.off(ModelEvent.OnModelsUpdate, async () => {})
}
}
}, [getData, isUpdated, reloadData])
}, [isUpdated, reloadData])
return {
loadDataModel: getData,