Skip to content

Commit

Permalink
feat: finished new UI thread setting pannel
Browse files Browse the repository at this point in the history
  • Loading branch information
urmauur committed Jan 4, 2024
1 parent 2332c4e commit 590fa67
Show file tree
Hide file tree
Showing 10 changed files with 216 additions and 105 deletions.
3 changes: 3 additions & 0 deletions uikit/src/tooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const TooltipProvider = TooltipPrimitive.Provider

const Tooltip = TooltipPrimitive.Root

const TooltipPortal = TooltipPrimitive.Portal

const TooltipTrigger = TooltipPrimitive.Trigger

const TooltipContent = React.forwardRef<
Expand Down Expand Up @@ -37,4 +39,5 @@ export {
TooltipContent,
TooltipProvider,
TooltipArrow,
TooltipPortal,
}
93 changes: 68 additions & 25 deletions web/containers/CardSidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ import { useClickOutside } from '@/hooks/useClickOutside'
interface Props {
children: ReactNode
title: string
onRevealInFinderClick: (type: string) => void
onViewJsonClick: (type: string) => void
onRevealInFinderClick?: (type: string) => void
onViewJsonClick?: (type: string) => void
asChild?: boolean
}
export default function CardSidebar({
children,
title,
onRevealInFinderClick,
onViewJsonClick,
asChild,
}: Props) {
const [show, setShow] = useState(true)
const [more, setMore] = useState(false)
Expand All @@ -39,7 +41,8 @@ export default function CardSidebar({
return (
<div
className={twMerge(
'flex w-full flex-col overflow-hidden border-t border-border bg-zinc-200 dark:bg-zinc-600/10'
'flex w-full flex-col border-t border-border bg-zinc-100 dark:bg-zinc-600/10',
asChild ? 'rounded-lg border' : 'border-t'
)}
>
<div
Expand All @@ -50,16 +53,18 @@ export default function CardSidebar({
>
<span className="font-bold">{title}</span>
<div className="flex">
<div
ref={setToggle}
className="cursor-pointer rounded-md bg-zinc-200 p-2 pr-0 dark:bg-zinc-600/10"
onClick={() => setMore(!more)}
>
<MoreVerticalIcon className="h-5 w-5" />
</div>
{!asChild && (
<div
ref={setToggle}
className="cursor-pointer rounded-lg bg-zinc-100 p-2 pr-0 dark:bg-zinc-600/10"
onClick={() => setMore(!more)}
>
<MoreVerticalIcon className="h-5 w-5" />
</div>
)}
<button
onClick={() => setShow(!show)}
className="flex w-full flex-1 items-center space-x-2 bg-zinc-200 px-3 py-2 dark:bg-zinc-600/10"
className="flex w-full flex-1 items-center space-x-2 rounded-lg bg-zinc-100 px-3 py-2 dark:bg-zinc-600/10"
>
<ChevronDownIcon
className={twMerge(
Expand All @@ -72,38 +77,76 @@ export default function CardSidebar({

{more && (
<div
className="absolute right-0 top-8 z-20 w-52 overflow-hidden rounded-lg border border-border bg-background shadow-lg"
className="absolute right-4 top-8 z-20 w-64 rounded-lg border border-border bg-background shadow-lg"
ref={setMenu}
>
<div
className="flex cursor-pointer items-center space-x-2 px-4 py-2 hover:bg-secondary"
className={twMerge(
'flex cursor-pointer space-x-2 px-4 py-2 hover:bg-secondary',
title === 'Model' ? 'items-start' : 'items-center'
)}
onClick={() => {
onRevealInFinderClick(title)
onRevealInFinderClick && onRevealInFinderClick(title)
setMore(false)
}}
>
<FolderOpenIcon size={16} className="text-muted-foreground" />
<span className="text-bold text-black dark:text-muted-foreground">
{openFolderTitle}
</span>
<FolderOpenIcon
size={16}
className={twMerge(
'flex-shrink-0 text-muted-foreground',
title === 'Model' && 'mt-1'
)}
/>
<>
{title === 'Model' ? (
<div className="flex flex-col">
<span className="font-medium text-black dark:text-muted-foreground">
{openFolderTitle}
</span>
<span className="mt-1 text-muted-foreground">
Opens thread.json. Changes affect this thread only.
</span>
</div>
) : (
<span className="text-bold text-black dark:text-muted-foreground">
{openFolderTitle}
</span>
)}
</>
</div>
<div
className="flex cursor-pointer items-center space-x-2 px-4 py-2 hover:bg-secondary"
className="flex cursor-pointer items-start space-x-2 px-4 py-2 hover:bg-secondary"
onClick={() => {
onViewJsonClick(title)
onViewJsonClick && onViewJsonClick(title)
setMore(false)
}}
>
<Code2Icon size={16} className="text-muted-foreground" />
<span className="text-bold text-black dark:text-muted-foreground">
View as JSON
</span>
<Code2Icon
size={16}
className="mt-0.5 flex-shrink-0 text-muted-foreground"
/>
<>
<div className="flex flex-col">
<span className="font-medium text-black dark:text-muted-foreground">
View as JSON
</span>
<span className="mt-1 text-muted-foreground">
Opens <span className="lowercase">{title}.json.</span>&nbsp;
Changes affect all new threads.
</span>
</div>
</>
</div>
</div>
)}
</div>
{show && (
<div className="flex flex-col gap-2 bg-white p-2 dark:bg-background">
<div
className={twMerge(
'flex flex-col gap-2 bg-white p-2 dark:bg-background',
asChild && 'rounded-b-lg'
)}
>
{children}
</div>
)}
Expand Down
30 changes: 27 additions & 3 deletions web/containers/Checkbox/index.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
import React from 'react'

import { Switch } from '@janhq/uikit'
import {
Switch,
Tooltip,
TooltipArrow,
TooltipContent,
TooltipPortal,
TooltipTrigger,
} from '@janhq/uikit'

import { useAtomValue } from 'jotai'

import { InfoIcon } from 'lucide-react'

import useUpdateModelParameters from '@/hooks/useUpdateModelParameters'

import { getActiveThreadIdAtom } from '@/helpers/atoms/Thread.atom'

type Props = {
name: string
title: string
description: string
checked: boolean
}

const Checkbox: React.FC<Props> = ({ name, title, checked }) => {
const Checkbox: React.FC<Props> = ({ name, title, checked, description }) => {
const { updateModelParameter } = useUpdateModelParameters()
const threadId = useAtomValue(getActiveThreadIdAtom)

Expand All @@ -26,7 +36,21 @@ const Checkbox: React.FC<Props> = ({ name, title, checked }) => {

return (
<div className="flex justify-between">
<p className="mb-2 text-sm font-semibold text-gray-600">{title}</p>
<div className="mb-1 flex items-center gap-x-2">
<p className="text-sm font-semibold text-gray-600">{title}</p>
<Tooltip>
<TooltipTrigger asChild>
<InfoIcon size={16} className="flex-shrink-0" />
</TooltipTrigger>
<TooltipPortal>
<TooltipContent side="top" className="max-w-[240px]">
<span>{description}</span>
<TooltipArrow />
</TooltipContent>
</TooltipPortal>
</Tooltip>
</div>

<Switch checked={checked} onCheckedChange={onCheckedChange} />
</div>
)
Expand Down
2 changes: 1 addition & 1 deletion web/containers/Layout/TopBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const TopBar = () => {
>
<Code2Icon
size={16}
className="mt-1 flex-shrink-0 text-muted-foreground"
className="mt-0.5 flex-shrink-0 text-muted-foreground"
/>
<div className="flex flex-col">
<span className="font-medium text-black dark:text-muted-foreground">
Expand Down
28 changes: 26 additions & 2 deletions web/containers/ModelConfigInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import { Textarea } from '@janhq/uikit'
import {
Textarea,
Tooltip,
TooltipPortal,
TooltipArrow,
TooltipContent,
TooltipTrigger,
} from '@janhq/uikit'

import { useAtomValue } from 'jotai'

import { InfoIcon } from 'lucide-react'

import useUpdateModelParameters from '@/hooks/useUpdateModelParameters'

import { getActiveThreadIdAtom } from '@/helpers/atoms/Thread.atom'

type Props = {
title: string
name: string
description: string
placeholder: string
value: string
}
Expand All @@ -17,6 +27,7 @@ const ModelConfigInput: React.FC<Props> = ({
title,
name,
value,
description,
placeholder,
}) => {
const { updateModelParameter } = useUpdateModelParameters()
Expand All @@ -30,7 +41,20 @@ const ModelConfigInput: React.FC<Props> = ({

return (
<div className="flex flex-col">
<p className="mb-2 text-sm font-semibold text-gray-600">{title}</p>
<div className="mb-4 flex items-center gap-x-2">
<p className="text-sm font-semibold text-gray-600">{title}</p>
<Tooltip>
<TooltipTrigger asChild>
<InfoIcon size={16} className="flex-shrink-0" />
</TooltipTrigger>
<TooltipPortal>
<TooltipContent side="top" className="max-w-[240px]">
<span>{description}</span>
<TooltipArrow />
</TooltipContent>
</TooltipPortal>
</Tooltip>
</div>
<Textarea
placeholder={placeholder}
onChange={onValueChanged}
Expand Down
27 changes: 24 additions & 3 deletions web/containers/Slider/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import React from 'react'

import { Slider, Input } from '@janhq/uikit'
import { Slider, Input, TooltipPortal } from '@janhq/uikit'
import {
Tooltip,
TooltipContent,
TooltipTrigger,
TooltipArrow,
} from '@janhq/uikit'
import { useAtomValue } from 'jotai'
import { InfoIcon } from 'lucide-react'

import useUpdateModelParameters from '@/hooks/useUpdateModelParameters'

import { getActiveThreadIdAtom } from '@/helpers/atoms/Thread.atom'

type Props = {
name: string
description: string
title: string
min: number
max: number
Expand All @@ -21,6 +29,7 @@ const SliderRightPanel: React.FC<Props> = ({
title,
min,
max,
description,
step,
value,
}) => {
Expand All @@ -29,13 +38,25 @@ const SliderRightPanel: React.FC<Props> = ({

const onValueChanged = (e: number[]) => {
if (!threadId) return

updateModelParameter(threadId, name, e[0])
}

return (
<div className="flex flex-col">
<p className="mb-2 text-sm font-semibold text-gray-600">{title}</p>
<div className="mb-4 flex items-center gap-x-2">
<p className="text-sm font-semibold text-gray-600">{title}</p>
<Tooltip>
<TooltipTrigger asChild>
<InfoIcon size={16} className="flex-shrink-0" />
</TooltipTrigger>
<TooltipPortal>
<TooltipContent side="top" className="max-w-[240px]">
<span>{description}</span>
<TooltipArrow />
</TooltipContent>
</TooltipPortal>
</Tooltip>
</div>
<div className="flex items-center gap-x-4">
<div className="relative w-full">
<Slider
Expand Down
Loading

0 comments on commit 590fa67

Please sign in to comment.