Faisal Amir 424b00338e
feat: revamp thread screen (#802)
* Make thread screen as default screen

* Blank state when user have not any model

* Cleanup topbar thread screen

* Improve style right panel

* Add instructions right panel

* Styling thread list history

* Resolve conflict

* Default title new thread

* Fix trigger panel sidebar

* Make default right panel false when no activethread

* Fix CI test

* chore: assistant instruction with system prompt

* Fix title and blank state explore the hub

* Claenup style thread screen and add buble message for assitant

* Remove unused import

* Styling more menus on thread list and right panel, and make max height textarea 400 pixel

* Finished revamp ui thread

* Finished system monitor UI

* Style box running models

* Make animate right panel more smooth

* Add status arround textarea for starting model info

* Temporary disable hide left panel

* chore: system resource monitoring update

* copy nits

* chore: typo

* Reverse icon chevron accordion

* Move my models into setting page

---------

Co-authored-by: Louis <louis@jan.ai>
Co-authored-by: 0xSage <n@pragmatic.vc>
2023-12-04 10:55:47 +07:00

94 lines
2.9 KiB
TypeScript

import { Fragment } from 'react'
import { ExtensionType } from '@janhq/core'
import { ModelExtension } from '@janhq/core'
import {
Progress,
Modal,
ModalContent,
Button,
ModalHeader,
ModalTitle,
ModalTrigger,
} from '@janhq/uikit'
import { useDownloadState } from '@/hooks/useDownloadState'
import { formatDownloadPercentage } from '@/utils/converter'
import { extensionManager } from '@/extension'
export default function DownloadingState() {
const { downloadStates } = useDownloadState()
const totalCurrentProgress = downloadStates
.map((a) => a.size.transferred + a.size.transferred)
.reduce((partialSum, a) => partialSum + a, 0)
const totalSize = downloadStates
.map((a) => a.size.total + a.size.total)
.reduce((partialSum, a) => partialSum + a, 0)
const totalPercentage = ((totalCurrentProgress / totalSize) * 100).toFixed(2)
return (
<Fragment>
{downloadStates?.length > 0 && (
<Modal>
<ModalTrigger asChild>
<div className="relative block">
<Button size="sm" themes="outline">
<span>{downloadStates.length} Downloading model</span>
</Button>
<span
className="absolute left-0 h-full rounded-md rounded-l-md bg-primary/20"
style={{
width: `${totalPercentage}%`,
}}
/>
</div>
</ModalTrigger>
<ModalContent>
<ModalHeader>
<ModalTitle>Downloading model</ModalTitle>
</ModalHeader>
{downloadStates.map((item, i) => {
return (
<div className="pt-2" key={i}>
<Progress
className="mb-2 h-2"
value={
formatDownloadPercentage(item?.percent, {
hidePercentage: true,
}) as number
}
/>
<div className="flex items-center justify-between gap-x-2">
<div className="flex gap-x-2">
<p className="line-clamp-1">{item?.modelId}</p>
<span>{formatDownloadPercentage(item?.percent)}</span>
</div>
<Button
themes="outline"
size="sm"
onClick={() => {
if (item?.modelId) {
extensionManager
.get<ModelExtension>(ExtensionType.Model)
?.cancelModelDownload(item.modelId)
}
}}
>
Cancel
</Button>
</div>
</div>
)
})}
</ModalContent>
</Modal>
)}
</Fragment>
)
}