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

fix: download now change state immediately #475

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 9 additions & 9 deletions web/app/_components/ExploreModelItemHeader/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import SimpleTag from '../SimpleTag'
import PrimaryButton from '../PrimaryButton'
import { formatDownloadPercentage, toGigabytes } from '@utils/converter'
import SecondaryButton from '../SecondaryButton'
import { useCallback, useEffect, useMemo } from 'react'
import useGetPerformanceTag from '@hooks/useGetPerformanceTag'
import useDownloadModel from '@hooks/useDownloadModel'
Expand Down Expand Up @@ -58,7 +56,6 @@ const ExploreModelItemHeader: React.FC<Props> = ({
if (isDownloaded) {
downloadButton = (
<Button
size="sm"
themes="accent"
onClick={() => {
setMainViewState(MainViewState.MyModel)
Expand All @@ -72,17 +69,20 @@ const ExploreModelItemHeader: React.FC<Props> = ({
if (downloadState != null) {
// downloading
downloadButton = (
<SecondaryButton
<Button
disabled
title={`Downloading (${formatDownloadPercentage(
downloadState.percent
)})`}
/>
themes="accent"
onClick={() => {
setMainViewState(MainViewState.MyModel)
}}
>
Downloading {formatDownloadPercentage(downloadState.percent)}
</Button>
)
}

return (
<div className="border-border bg-background/50 flex items-center justify-between rounded-t-md border-b px-4 py-2">
<div className="flex items-center justify-between rounded-t-md border-b border-border bg-background/50 px-4 py-2">
<div className="flex items-center gap-2">
<span>{exploreModel.name}</span>
{performanceTag && (
Expand Down
7 changes: 4 additions & 3 deletions web/app/_components/HistoryItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ const HistoryItem: React.FC<Props> = ({
startModel(model._id)
} else if (activeModel._id !== model._id) {
// display confirmation modal
setConfirmationModalProps({
replacingModel: model,
})
// TODO: temporarily disabled
// setConfirmationModalProps({
// replacingModel: model,
// })
}
}

Expand Down
6 changes: 3 additions & 3 deletions web/app/_components/SwitchingModelConfirmationModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ const SwitchingModelConfirmationModal: React.FC = () => {
<p className="text-sm text-gray-500">
Selected conversation is using model{' '}
<span className="font-semibold text-black">
{props?.replacingModel._id}
{props?.replacingModel.name}
</span>
, but the active model is using{' '}
<span className="font-semibold text-black">
{activeModel?._id}
{activeModel?.name}
</span>
.
</p>
Expand All @@ -95,7 +95,7 @@ const SwitchingModelConfirmationModal: React.FC = () => {
Switch to
<span className="font-semibold text-black">
{' '}
{props?.replacingModel._id}?
{props?.replacingModel.name}?
</span>
</p>
</div>
Expand Down
22 changes: 21 additions & 1 deletion web/hooks/useDownloadModel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { executeSerial } from '@services/pluginService'
import { DataService, ModelManagementService } from '@janhq/core'
import { ModelManagementService } from '@janhq/core'
import { useSetAtom } from 'jotai'
import { setDownloadStateAtom } from '@helpers/atoms/DownloadState.atom'

export default function useDownloadModel() {
const setDownloadState = useSetAtom(setDownloadStateAtom)

const assistanModel = (
model: Product,
modelVersion: ModelVersion
Expand Down Expand Up @@ -37,6 +41,22 @@ export default function useDownloadModel() {
}

const downloadModel = async (model: Product, modelVersion: ModelVersion) => {
// set an initial download state
setDownloadState({
modelId: modelVersion._id,
time: {
elapsed: 0,
remaining: 0,
},
speed: 0,
percent: 0,
size: {
total: 0,
transferred: 0,
},
fileName: modelVersion._id,
})

modelVersion.startDownloadAt = Date.now()
const assistantModel = assistanModel(model, modelVersion)
await executeSerial(ModelManagementService.StoreModel, assistantModel)
Expand Down
Loading