* feat: model hub revamp UI * chore: model description - consistent markdown css * chore: add model versions dropdown * chore: integrate APIs - model sources * chore: update model display name * chore: lint fix * chore: page transition animation * feat: model search dropdown - deeplink * chore: bump cortex version * chore: add remote model sources * chore: model download state * chore: fix model metadata label * chore: polish model detail page markdown * test: fix test cases * chore: initialize default Hub model sources * chore: fix model stats * chore: clean up click outside and inside hooks * feat: change hub banner * chore: lint fix * chore: fix css long model id
61 lines
1.9 KiB
TypeScript
61 lines
1.9 KiB
TypeScript
import { useCallback, useMemo } from 'react'
|
|
|
|
import { ImportingModel } from '@janhq/core'
|
|
import { useSetAtom } from 'jotai'
|
|
|
|
import { AlertCircle } from 'lucide-react'
|
|
|
|
import { setImportModelStageAtom } from '@/hooks/useImportModel'
|
|
|
|
import { toGigabytes } from '@/utils/converter'
|
|
|
|
import { editingModelIdAtom } from '../EditModelInfoModal'
|
|
import ImportInProgressIcon from '../ImportInProgressIcon'
|
|
import ImportSuccessIcon from '../ImportSuccessIcon'
|
|
|
|
type Props = {
|
|
model: ImportingModel
|
|
}
|
|
|
|
const ImportingModelItem = ({ model }: Props) => {
|
|
const setImportModelStage = useSetAtom(setImportModelStageAtom)
|
|
const setEditingModelId = useSetAtom(editingModelIdAtom)
|
|
|
|
const onEditModelInfoClick = useCallback(() => {
|
|
setEditingModelId(model.importId)
|
|
setImportModelStage('EDIT_MODEL_INFO')
|
|
}, [setImportModelStage, setEditingModelId, model.importId])
|
|
|
|
const onDeleteModelClick = useCallback(() => {}, [])
|
|
|
|
const displayStatus = useMemo(() => {
|
|
if (model.status === 'FAILED') {
|
|
return 'Failed'
|
|
} else {
|
|
return toGigabytes(model.size)
|
|
}
|
|
}, [model.status, model.size])
|
|
|
|
return (
|
|
<div className="flex w-full flex-row items-center space-x-3 rounded-lg border border-[hsla(var(--app-border))] px-4 py-3">
|
|
<p className="line-clamp-1 flex-1 font-semibold text-[hsla(var(--text-secondary))]">
|
|
{model.name}
|
|
</p>
|
|
<p className="text-[hsla(var(--text-secondary))]">{displayStatus}</p>
|
|
|
|
{model.status === 'IMPORTED' && (
|
|
<ImportSuccessIcon onEditModelClick={onEditModelInfoClick} />
|
|
)}
|
|
{(model.status === 'IMPORTING' || model.status === 'PREPARING') && (
|
|
<ImportInProgressIcon
|
|
percentage={model.percentage ?? 0}
|
|
onDeleteModelClick={onDeleteModelClick}
|
|
/>
|
|
)}
|
|
{model.status === 'FAILED' && <AlertCircle size={24} />}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default ImportingModelItem
|