fix: duplicate model while searching
This commit is contained in:
parent
276a286853
commit
736790473e
@ -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 {
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user