Faisal Amir 539b467141
ui: interface revamp (#429)
* 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>
2023-10-24 10:59:12 +07:00

86 lines
2.5 KiB
TypeScript

import React, { useMemo } from 'react'
import { formatDownloadPercentage, toGigabytes } from '@utils/converter'
import Image from 'next/image'
import useDownloadModel from '@hooks/useDownloadModel'
import { modelDownloadStateAtom } from '@helpers/atoms/DownloadState.atom'
import { atom, useAtomValue } from 'jotai'
import { useGetDownloadedModels } from '@hooks/useGetDownloadedModels'
import SimpleTag from '../SimpleTag'
import { RamRequired, UsecaseTag } from '../SimpleTag/TagType'
type Props = {
model: Product
modelVersion: ModelVersion
isRecommended: boolean
}
const ModelVersionItem: React.FC<Props> = ({
model,
modelVersion,
isRecommended,
}) => {
const { downloadModel } = useDownloadModel()
const { downloadedModels } = useGetDownloadedModels()
const isDownloaded =
downloadedModels.find((model) => model._id === modelVersion._id) != null
const downloadAtom = useMemo(
() => atom((get) => get(modelDownloadStateAtom)[modelVersion._id ?? '']),
[modelVersion._id]
)
const downloadState = useAtomValue(downloadAtom)
const onDownloadClick = () => {
downloadModel(model, modelVersion)
}
let downloadButton = (
<button
className="text-sm font-medium text-indigo-600"
onClick={onDownloadClick}
>
Download
</button>
)
if (downloadState) {
downloadButton = (
<div>{formatDownloadPercentage(downloadState.percent)}</div>
)
} else if (isDownloaded) {
downloadButton = <div>Downloaded</div>
}
const { maxRamRequired, usecase } = modelVersion
return (
<div className="border-border flex items-center justify-between gap-4 border-t pb-3 pl-3 pr-4 pt-3 first:border-t-0">
<div className="flex items-center gap-2">
<span className="font-sm text-muted-foreground mb-4 line-clamp-1 flex-1">
{modelVersion.name}
</span>
</div>
<div className="flex items-center gap-4">
<div className="flex justify-end gap-2">
<SimpleTag
title={usecase}
type={UsecaseTag.UsecaseDefault}
clickable={false}
/>
<SimpleTag
title={`${toGigabytes(maxRamRequired)} RAM required`}
type={RamRequired.RamDefault}
clickable={false}
/>
<div className="bg-background border-border rounded-full border px-2.5 py-0.5 font-medium">
{toGigabytes(modelVersion.size)}
</div>
</div>
{downloadButton}
</div>
</div>
)
}
export default ModelVersionItem