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[] sources: CatalogModel[]
error: Error | null error: Error | null
loading: boolean loading: boolean
addSource: (source: CatalogModel) => void
fetchSources: () => Promise<void> fetchSources: () => Promise<void>
} }
@ -18,15 +17,6 @@ export const useModelSources = create<ModelSourcesState>()(
sources: [], sources: [],
error: null, error: null,
loading: false, loading: false,
addSource: (source: CatalogModel) => {
set((state) => ({
sources: [
...state.sources.filter((e) => e.model_name !== source.model_name),
source,
],
}))
},
fetchSources: async () => { fetchSources: async () => {
set({ loading: true, error: null }) set({ loading: true, error: null })
try { 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 [searchValue, setSearchValue] = useState('')
const [sortSelected, setSortSelected] = useState('newest') const [sortSelected, setSortSelected] = useState('newest')
@ -187,14 +187,16 @@ function Hub() {
addModelSourceTimeoutRef.current = setTimeout(async () => { addModelSourceTimeoutRef.current = setTimeout(async () => {
try { try {
// Fetch HuggingFace repository information // Fetch HuggingFace repository information
const repoInfo = await fetchHuggingFaceRepo(e.target.value, huggingfaceToken) const repoInfo = await fetchHuggingFaceRepo(
e.target.value,
huggingfaceToken
)
if (repoInfo) { if (repoInfo) {
const catalogModel = convertHfRepoToCatalogModel(repoInfo) const catalogModel = convertHfRepoToCatalogModel(repoInfo)
if ( if (
!sources.some((s) => s.model_name === catalogModel.model_name) !sources.some((s) => s.model_name === catalogModel.model_name)
) { ) {
setHuggingFaceRepo(catalogModel) setHuggingFaceRepo(catalogModel)
addSource(catalogModel)
} }
} }
} catch (error) { } catch (error) {