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

106 lines
3.1 KiB
TypeScript

import { Fragment, useState, useEffect } from 'react'
import {
CommandModal,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandShortcut,
CommandList,
} from '@janhq/uikit'
import { MessageCircleIcon, SettingsIcon, LayoutGridIcon } from 'lucide-react'
import ShortCut from '@/containers/Shortcut'
import { MainViewState } from '@/constants/screens'
import { useMainViewState } from '@/hooks/useMainViewState'
export default function CommandSearch() {
const { setMainViewState } = useMainViewState()
const [open, setOpen] = useState(false)
const menus = [
{
name: 'Chat',
icon: (
<MessageCircleIcon size={16} className="mr-3 text-muted-foreground" />
),
state: MainViewState.Thread,
},
{
name: 'Hub',
icon: <LayoutGridIcon size={16} className="mr-3 text-muted-foreground" />,
state: MainViewState.Hub,
},
{
name: 'Settings',
icon: <SettingsIcon size={16} className="mr-3 text-muted-foreground" />,
state: MainViewState.Settings,
shortcut: <ShortCut menu="," />,
},
]
useEffect(() => {
const down = (e: KeyboardEvent) => {
if (e.key === 'k' && (e.metaKey || e.ctrlKey)) {
e.preventDefault()
setOpen((open) => !open)
}
if (e.key === ',' && (e.metaKey || e.ctrlKey)) {
e.preventDefault()
setMainViewState(MainViewState.Settings)
}
}
document.addEventListener('keydown', down)
return () => document.removeEventListener('keydown', down)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
return (
<Fragment>
{/* Temporary disable view search input until we have proper UI placement, but we keep function cmd + K for showing list page */}
{/* <div className="relative">
<Button
themes="outline"
className="unset-drag h-8 w-[300px] justify-start text-left text-xs font-normal text-muted-foreground focus:ring-0"
onClick={() => setOpen((open) => !open)}
>
Search menus...
</Button>
<div className="absolute right-2 top-1/2 -translate-y-1/2">
<ShortCut menu="K" />
</div>
</div> */}
<CommandModal open={open} onOpenChange={setOpen}>
<CommandInput placeholder="Type a command or search..." />
<CommandList>
<CommandEmpty>No results found.</CommandEmpty>
<CommandGroup heading="Suggestions">
{menus.map((menu, i) => {
return (
<CommandItem
key={i}
value={menu.name}
onSelect={() => {
setMainViewState(menu.state)
setOpen(false)
}}
>
{menu.icon}
<span>{menu.name}</span>
{menu.shortcut && (
<CommandShortcut>{menu.shortcut}</CommandShortcut>
)}
</CommandItem>
)
})}
</CommandGroup>
</CommandList>
</CommandModal>
</Fragment>
)
}