* feat: adding create bot functionality Signed-off-by: James <james@jan.ai> * update the temperature progress bar Signed-off-by: James <james@jan.ai> * WIP baselayout * Mapping plugins with available preferences * Added loader component * WIP working another screen * Cleanup types and avoid import one by one * Prepare bottom bar * Add css variables colors to enable user select the accent * Enable change accent color * Seperate css variable * Fix conflict * Add blank state of my model empty * Restyle explore models page * Enable user config left sidebar * Restyle my models page * WIP styling chat page * Restyling chat message * Fix conflict * Adde form preferences setting plugins * Fixed form bot info * Sidebar bot chat * Showing rightbar for both setting when user created bot * Fix style bot info * Using overflow auto intead of scroll * Remove script built UI from root package * Fix missig import * Resolve error linter * fix e2e tests Signed-off-by: James <james@jan.ai> --------- Signed-off-by: James <james@jan.ai> Co-authored-by: James <james@jan.ai>
98 lines
2.8 KiB
TypeScript
98 lines
2.8 KiB
TypeScript
import SimpleTag from '../SimpleTag'
|
|
import PrimaryButton from '../PrimaryButton'
|
|
import { formatDownloadPercentage, toGigabytes } from '@utils/converter'
|
|
import SecondaryButton from '../SecondaryButton'
|
|
import { useCallback, useEffect, useMemo } from 'react'
|
|
import useGetPerformanceTag from '@hooks/useGetPerformanceTag'
|
|
import useDownloadModel from '@hooks/useDownloadModel'
|
|
import { useGetDownloadedModels } from '@hooks/useGetDownloadedModels'
|
|
import { modelDownloadStateAtom } from '@helpers/atoms/DownloadState.atom'
|
|
import { atom, useAtomValue, useSetAtom } from 'jotai'
|
|
import { Button } from '@uikit'
|
|
import {
|
|
MainViewState,
|
|
setMainViewStateAtom,
|
|
} from '@helpers/atoms/MainView.atom'
|
|
|
|
type Props = {
|
|
suitableModel: ModelVersion
|
|
exploreModel: Product
|
|
}
|
|
|
|
const ExploreModelItemHeader: React.FC<Props> = ({
|
|
suitableModel,
|
|
exploreModel,
|
|
}) => {
|
|
const { downloadModel } = useDownloadModel()
|
|
const { downloadedModels } = useGetDownloadedModels()
|
|
const { performanceTag, title, getPerformanceForModel } =
|
|
useGetPerformanceTag()
|
|
const downloadAtom = useMemo(
|
|
() => atom((get) => get(modelDownloadStateAtom)[suitableModel._id]),
|
|
[suitableModel._id]
|
|
)
|
|
const downloadState = useAtomValue(downloadAtom)
|
|
const setMainViewState = useSetAtom(setMainViewStateAtom)
|
|
|
|
useEffect(() => {
|
|
getPerformanceForModel(suitableModel)
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [suitableModel])
|
|
|
|
const onDownloadClick = useCallback(() => {
|
|
downloadModel(exploreModel, suitableModel)
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [exploreModel, suitableModel])
|
|
|
|
const isDownloaded =
|
|
downloadedModels.find((model) => model._id === suitableModel._id) != null
|
|
|
|
let downloadButton = (
|
|
<Button themes="accent" onClick={() => onDownloadClick()}>
|
|
{suitableModel.size
|
|
? `Download (${toGigabytes(suitableModel.size)})`
|
|
: 'Download'}
|
|
</Button>
|
|
)
|
|
|
|
if (isDownloaded) {
|
|
downloadButton = (
|
|
<Button
|
|
size="sm"
|
|
themes="accent"
|
|
onClick={() => {
|
|
setMainViewState(MainViewState.MyModel)
|
|
}}
|
|
>
|
|
View Downloaded Model
|
|
</Button>
|
|
)
|
|
}
|
|
|
|
if (downloadState != null) {
|
|
// downloading
|
|
downloadButton = (
|
|
<SecondaryButton
|
|
disabled
|
|
title={`Downloading (${formatDownloadPercentage(
|
|
downloadState.percent
|
|
)})`}
|
|
/>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<div className="border-border bg-background/50 flex items-center justify-between rounded-t-md border-b px-4 py-2">
|
|
<div className="flex items-center gap-2">
|
|
<span>{exploreModel.name}</span>
|
|
{performanceTag && (
|
|
<SimpleTag title={title} type={performanceTag} clickable={false} />
|
|
)}
|
|
</div>
|
|
{downloadButton}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default ExploreModelItemHeader
|