Faisal Amir 2394c13065
ui: standalone UIKit and refactor (#557)
* Eslint import order

* Initial Uikit

* Rename file with camelCase

* Remove unused code

* Remove unused code

* Set position traficlight mac

* Grouping Ribbon, Topbar and Bottombar as layout

* Added image brand

* Moving feature toggle into context folder

* Fix active state of setting menu

* Cleanup downloadModel atom helper

* Cleanup useGetConfigureModel

* Added wave animation

* Create useMainViewState intead of import helper atom

* Remove unused code

* Take a back switch ui

* Toggle using switch component

* Add dynamic primary color

* Cleanup import

* Added uikit scroll area

* Add best practice form

* Added toaster container

* Fix loader container

* Add hooks useDownloadState

* Added tooltip on ribbon menu

* Added case user multiple download model

* Adjust input style with bigger ring

* Restyle my model screen

* Replace useStartStop model with useActiveModel

* Import icon using Icon name

* Fix missing login loading start and stop model

* WIP integrate with cmdk

* Move layout search bar on middle of app

* Added function cancel download

* Cleanup model explore

* Cleanup unused code

* Move app version in bototmbar or footer

* WIP chat screen

* WIP chat screen

* Cleanup style and remove unsed code

* Added command for showing downloaded model

* Fix missing keyframe loader dot animation

* Conditional loader of plugin setting

* WIP history list message

* chore: rebase main

* Adding script ui into root package

* Fix different version react hooks form

* Add close toaster

* Added status model active or not on list of command

* Conditional showing info if user don't have a model

* Disabled toolbar chat when user not yet have convo

* chore: fix state

* fix: get resource atom

* Fix conditional bottom bar

* fix: model download state

* Fix font

* Improve icon my model

* Add toaster delete chat

* Remove test classname

* Fix scroll chat body

* Fix scrolling chat body

* chore: add message update

* Add uikit into depedencies on root package

* Update chat flow

* Fix hot reload ui changes

* Increate background color chat screen light mode

* Added visual conversation active state

* Added build:uikit on gh actions

* chore: attempt to fix CI

* fix: deps

* fix: tests

* chore: attempt to fix CI

---------

Co-authored-by: Louis <louis@jan.ai>
2023-11-07 21:27:11 +07:00

119 lines
3.7 KiB
TypeScript

/* eslint-disable react/display-name */
import { forwardRef, useEffect, useState } from 'react'
import { ModelCatalog } from '@janhq/core/lib/types'
import { Badge } from '@janhq/uikit'
import useGetMostSuitableModelVersion from '@/hooks/useGetMostSuitableModelVersion'
import ExploreModelItemHeader from '@/screens/ExploreModels/ExploreModelItemHeader'
import ModelVersionList from '@/screens/ExploreModels/ModelVersionList'
import { toGigabytes } from '@/utils/converter'
import { displayDate } from '@/utils/datetime'
type Props = {
model: ModelCatalog
}
const ExploreModelItem = forwardRef<HTMLDivElement, Props>(({ model }, ref) => {
const [show, setShow] = useState(false)
const { availableVersions } = model
const { suitableModel, getMostSuitableModelVersion } =
useGetMostSuitableModelVersion()
useEffect(() => {
getMostSuitableModelVersion(availableVersions)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [availableVersions])
if (!suitableModel) {
return null
}
const { quantMethod, bits, maxRamRequired, usecase } = suitableModel
return (
<div
ref={ref}
className="mb-4 flex flex-col rounded-md border border-border bg-background/60"
>
<ExploreModelItemHeader
suitableModel={suitableModel}
exploreModel={model}
/>
<div className="flex flex-col p-4">
<div className="mb-4 flex flex-col gap-1">
<span className="font-semibold">About</span>
<p>{model.longDescription}</p>
</div>
<div className="mb-4 flex space-x-6 border-b border-border pb-4">
<div>
<span className="font-semibold">Author</span>
<p className="mt-1 font-medium">{model.author}</p>
</div>
<div>
<span className="mb-1 font-semibold">Compatibility</span>
<div className="mt-1 flex gap-2">
<Badge themes="secondary" className="line-clamp-1 max-w-[400px]">
{usecase}
</Badge>
<Badge themes="secondary" className="line-clamp-1">
{toGigabytes(maxRamRequired)} RAM required
</Badge>
</div>
</div>
</div>
<div className="grid grid-cols-3 items-center gap-4">
<div>
<span className="font-semibold">Version</span>
<div className="mt-2 flex space-x-2">
<Badge themes="outline">v{model.version}</Badge>
{quantMethod && <Badge themes="outline">{quantMethod}</Badge>}
<Badge themes="outline">{`${bits} Bits`}</Badge>
</div>
</div>
<div>
<span className="font-semibold">Release Date</span>
<p className="mt-1 ">{displayDate(model.releaseDate)}</p>
</div>
<div>
<span className="font-semibold">Tags</span>
<div className="mt-2 flex space-x-2">
{model.tags.map((tag, i) => (
<Badge key={i} themes="outline">
{tag}
</Badge>
))}
</div>
</div>
</div>
{model.availableVersions?.length > 0 && (
<div className="mt-5 w-full rounded-md border border-border bg-background p-2">
<button onClick={() => setShow(!show)} className="w-full">
{!show
? '+ Show Available Versions'
: '- Collapse Available Versions'}
</button>
{show && (
<ModelVersionList
model={model}
versions={model.availableVersions}
recommendedVersion={suitableModel?._id ?? ''}
/>
)}
</div>
)}
</div>
</div>
)
})
export default ExploreModelItem