fix: duplicate model while searching

This commit is contained in:
Louis 2025-08-12 11:17:00 +07:00
parent 276a286853
commit 736790473e
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2
2 changed files with 5 additions and 13 deletions

View File

@ -8,7 +8,6 @@ type ModelSourcesState = {
sources: CatalogModel[]
error: Error | null
loading: boolean
addSource: (source: CatalogModel) => void
fetchSources: () => Promise<void>
}
@ -18,15 +17,6 @@ export const useModelSources = create<ModelSourcesState>()(
sources: [],
error: null,
loading: false,
addSource: (source: CatalogModel) => {
set((state) => ({
sources: [
...state.sources.filter((e) => e.model_name !== source.model_name),
source,
],
}))
},
fetchSources: async () => {
set({ loading: true, error: null })
try {

View File

@ -73,7 +73,7 @@ function Hub() {
}
}, [])
const { sources, addSource, fetchSources, loading } = useModelSources()
const { sources, fetchSources, loading } = useModelSources()
const [searchValue, setSearchValue] = useState('')
const [sortSelected, setSortSelected] = useState('newest')
@ -187,14 +187,16 @@ function Hub() {
addModelSourceTimeoutRef.current = setTimeout(async () => {
try {
// Fetch HuggingFace repository information
const repoInfo = await fetchHuggingFaceRepo(e.target.value, huggingfaceToken)
const repoInfo = await fetchHuggingFaceRepo(
e.target.value,
huggingfaceToken
)
if (repoInfo) {
const catalogModel = convertHfRepoToCatalogModel(repoInfo)
if (
!sources.some((s) => s.model_name === catalogModel.model_name)
) {
setHuggingFaceRepo(catalogModel)
addSource(catalogModel)
}
}
} catch (error) {