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