Skip to content

Commit

Permalink
chore: disabled option when engine isn't ready
Browse files Browse the repository at this point in the history
  • Loading branch information
urmauur committed Aug 7, 2024
1 parent 5ec9419 commit 380264c
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions web/containers/ModelDropdown/ModelSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { Button } from '@janhq/joi'
import { useSetAtom } from 'jotai'
import { SettingsIcon } from 'lucide-react'

import { twMerge } from 'tailwind-merge'

import useEngineQuery from '@/hooks/useEngineQuery'
import useGetModelsByEngine from '@/hooks/useGetModelsByEngine'

import { getTitleByCategory } from '@/utils/model-engine'
Expand All @@ -30,6 +33,7 @@ const ModelSection: React.FC<Props> = ({
const [models, setModels] = useState<Model[]>([])
const { getModelsByEngine } = useGetModelsByEngine()
const setUpRemoteModelStage = useSetAtom(setUpRemoteModelStageAtom)
const { data: engineData } = useEngineQuery()

const engineLogo: string | undefined = models.find(
(entry) => entry?.metadata?.logo != null
Expand Down Expand Up @@ -79,18 +83,32 @@ const ModelSection: React.FC<Props> = ({
</Button>
</div>
<ul className="pb-2">
{models.map((model) => (
<li
key={model.model}
className="flex cursor-pointer items-center gap-2 px-3 py-2 hover:bg-[hsla(var(--dropdown-menu-hover-bg))]"
onClick={() => onModelSelected(model)}
>
<div className="flex w-full items-center justify-between">
<p className="line-clamp-1">{model.name ?? model.model}</p>
</div>
<ModelLabel metadata={model.metadata} compact />
</li>
))}
{models.map((model) => {
const isEngineReady =
engineData?.find((e) => e.name === model.engine)?.status === 'ready'

return (
<li
key={model.model}
className={twMerge(
'flex cursor-pointer items-center gap-2 px-3 py-2 hover:bg-[hsla(var(--dropdown-menu-hover-bg))]',
isEngineReady
? 'text-[hsla(var(--text-primary))]'
: 'cursor-not-allowed text-[hsla(var(--text-tertiary))]'
)}
onClick={() => {
if (isEngineReady) {
onModelSelected(model)
}
}}
>
<div className="flex w-full items-center justify-between">
<p className="line-clamp-1">{model.name ?? model.model}</p>
</div>
<ModelLabel metadata={model.metadata} compact />
</li>
)
})}
</ul>
</div>
)
Expand Down

0 comments on commit 380264c

Please sign in to comment.