Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: resolve button state download engine variant #4444

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions web/screens/Settings/Engines/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
InferenceEngine,
} from '@janhq/core'
import { Button, ScrollArea, Badge, Select, Progress } from '@janhq/joi'
import { Trash2Icon } from 'lucide-react'

import { twMerge } from 'tailwind-merge'

import {
Expand All @@ -18,7 +18,6 @@ import {
setDefaultEngineVariant,
installEngine,
updateEngine,
uninstallEngine,
useGetReleasedEnginesByVersion,
} from '@/hooks/useEngineManagement'

Expand Down Expand Up @@ -109,21 +108,32 @@ const EngineSettings = ({ engine }: { engine: InferenceEngine }) => {
const variant: string | undefined = event.id.includes('.tar.gz')
? availableVariants?.find((e) => event.id.includes(`${e}.tar.gz`))
: availableVariants?.find((e) => event.id.includes(e))
if (!variant) return

if (!variant) {
console.error(
'Variant not found for event.id:',
event.id,
availableVariants
)
return
}

// Clone the existing Map to ensure immutability
setInstallingEngines((prev) => {
prev.set(variant, event.percent)
return prev
const updated = new Map(prev)
if (
event.type === DownloadEvent.onFileDownloadError ||
event.type === DownloadEvent.onFileDownloadStopped ||
event.type === DownloadEvent.onFileDownloadSuccess
) {
// Remove the variant from the Map if download stops/errors/succeeds
updated.delete(variant)
} else {
// Update the variant with the new percentage
updated.set(variant, event.percent)
}
return updated
})
if (
event.type === DownloadEvent.onFileDownloadError ||
event.type === DownloadEvent.onFileDownloadStopped ||
event.type === DownloadEvent.onFileDownloadSuccess
) {
setInstallingEngines((prev) => {
prev.delete(variant)
return prev
})
}
},
[
mutateDefaultEngineVariant,
Expand All @@ -147,6 +157,7 @@ const EngineSettings = ({ engine }: { engine: InferenceEngine }) => {
version: String(defaultEngineVariant?.version),
})
}

return (
<ScrollArea className="h-full w-full">
<div className="block w-full px-4">
Expand Down Expand Up @@ -296,8 +307,9 @@ const EngineSettings = ({ engine }: { engine: InferenceEngine }) => {
variant="soft"
onClick={() => {
setInstallingEngines((prev) => {
prev.set(item.name, 0)
return prev
const updated = new Map(prev)
updated.set(item.name, 0)
return updated
})
installEngine(engine, {
variant: item.name,
Expand Down
Loading