jan/web/screens/Settings/Engines/DeleteEngineVariant.tsx
Faisal Amir a6a0cb325b
feat: local engine management (#4334)
* feat: local engine management

* chore: move remote engine into engine page instead extension page

* chore: set default engine from extension

* chore: update endpoint update engine

* chore: update event onEngineUpdate

* chore: filter out engine download

* chore: update version env

* chore: select default engine variant base on user device specs

* chore: symlink engine variants

* chore: rolldown.config in mjs format

* chore: binary codesign

* fix: download state in footer bar and variant status

* chore: update yarn.lock

* fix: rimraf failure

* fix: setup-node@v3 for built-in cache

* fix: cov pipeline

* fix: build syntax

* chore: fix build step

* fix: create engines folder on launch

* chore: update ui delete engine variant with modal confirmation

* chore: fix linter

* chore: add installing progress for Local Engine download

* chore: wording

---------

Co-authored-by: Louis <louis@jan.ai>
2024-12-30 17:27:51 +07:00

78 lines
2.0 KiB
TypeScript

import { memo, useState } from 'react'
import { EngineReleased, InferenceEngine } from '@janhq/core'
import { Button, Modal, ModalClose } from '@janhq/joi'
import { Trash2Icon } from 'lucide-react'
import {
uninstallEngine,
useGetDefaultEngineVariant,
useGetInstalledEngines,
} from '@/hooks/useEngineManagement'
const DeleteEngineVariant = ({
variant,
engine,
}: {
variant: EngineReleased
engine: InferenceEngine
}) => {
const [open, setOpen] = useState(false)
const { mutate: mutateInstalledEngines } = useGetInstalledEngines(engine)
const { defaultEngineVariant, mutate: mutateDefaultEngineVariant } =
useGetDefaultEngineVariant(engine)
return (
<Modal
title={<span>Delete {variant.name}</span>}
open={open}
onOpenChange={() => setOpen(!open)}
trigger={
<Button theme="icon" variant="outline" onClick={() => setOpen(!open)}>
<Trash2Icon
size={14}
className="text-[hsla(var(--text-secondary))]"
/>
</Button>
}
content={
<div>
<p className="text-[hsla(var(--text-secondary))]">
Are you sure you want to delete this variant?
</p>
<div className="mt-4 flex justify-end gap-x-2">
<ModalClose
asChild
onClick={(e) => {
setOpen(!open)
e.stopPropagation()
}}
>
<Button theme="ghost">No</Button>
</ModalClose>
<ModalClose asChild>
<Button
theme="destructive"
onClick={() => {
uninstallEngine(engine, {
variant: variant.name,
version: String(defaultEngineVariant?.version),
})
mutateInstalledEngines()
}}
autoFocus
>
Yes
</Button>
</ModalClose>
</div>
</div>
}
/>
)
}
export default memo(DeleteEngineVariant)