From cf8f401daba8d822dfdd0c9a83059ef0ecabdded Mon Sep 17 00:00:00 2001 From: Faisal Amir Date: Tue, 11 Jun 2024 18:46:12 +0700 Subject: [PATCH] feat: update icon alert warning and copies tooltip model dropdown (#3021) * feat: update icon alert warning and copies tooltip model dropdown * chore: update loader when user click download model dropdown --- web/containers/Loader/ProgressCircle.tsx | 50 ++++++++++++++++ web/containers/ModelDropdown/index.tsx | 44 +++++++++++++- .../ModelLabel/NotEnoughMemoryLabel.tsx | 57 ++++++++++++------- .../ModelLabel/SlowOnYourDeviceLabel.tsx | 57 ++++++++++++------- 4 files changed, 165 insertions(+), 43 deletions(-) create mode 100644 web/containers/Loader/ProgressCircle.tsx diff --git a/web/containers/Loader/ProgressCircle.tsx b/web/containers/Loader/ProgressCircle.tsx new file mode 100644 index 000000000..e10434113 --- /dev/null +++ b/web/containers/Loader/ProgressCircle.tsx @@ -0,0 +1,50 @@ +import React from 'react' + +interface ProgressCircleProps { + percentage: number + size?: number + strokeWidth?: number +} + +const ProgressCircle: React.FC = ({ + percentage, + size = 100, + strokeWidth = 14, +}) => { + const radius = (size - strokeWidth) / 2 + const circumference = 2 * Math.PI * radius + const offset = circumference - (percentage / 100) * circumference + + return ( + + + + + ) +} + +export default ProgressCircle diff --git a/web/containers/ModelDropdown/index.tsx b/web/containers/ModelDropdown/index.tsx index a57525698..1f33f3ceb 100644 --- a/web/containers/ModelDropdown/index.tsx +++ b/web/containers/ModelDropdown/index.tsx @@ -8,16 +8,19 @@ import { useAtom, useAtomValue, useSetAtom } from 'jotai' import { ChevronDownIcon, DownloadCloudIcon, XIcon } from 'lucide-react' import { twMerge } from 'tailwind-merge' +import ProgressCircle from '@/containers/Loader/ProgressCircle' + import ModelLabel from '@/containers/ModelLabel' import SetupRemoteModel from '@/containers/SetupRemoteModel' import useDownloadModel from '@/hooks/useDownloadModel' +import { modelDownloadStateAtom } from '@/hooks/useDownloadState' import useRecommendedModel from '@/hooks/useRecommendedModel' import useUpdateModelParameters from '@/hooks/useUpdateModelParameters' -import { toGibibytes } from '@/utils/converter' +import { formatDownloadPercentage, toGibibytes } from '@/utils/converter' import { extensionManager } from '@/extension' @@ -64,6 +67,7 @@ const ModelDropdown = ({ const [dropdownOptions, setDropdownOptions] = useState( null ) + const downloadStates = useAtomValue(modelDownloadStateAtom) const setThreadModelParams = useSetAtom(setThreadModelParamsAtom) const { updateModelParameter } = useUpdateModelParameters() @@ -351,12 +355,29 @@ const ModelDropdown = ({ {toGibibytes(model.metadata.size)} - {!isDownloading && ( + {!isDownloading ? ( downloadModel(model)} /> + ) : ( + Object.values(downloadStates) + .filter((x) => x.modelId === model.id) + .map((item) => ( + + )) )} @@ -397,12 +418,29 @@ const ModelDropdown = ({ {toGibibytes(model.metadata.size)} - {!isDownloading && ( + {!isDownloading ? ( downloadModel(model)} /> + ) : ( + Object.values(downloadStates) + .filter((x) => x.modelId === model.id) + .map((item) => ( + + )) )} diff --git a/web/containers/ModelLabel/NotEnoughMemoryLabel.tsx b/web/containers/ModelLabel/NotEnoughMemoryLabel.tsx index fb2b7bde5..287193183 100644 --- a/web/containers/ModelLabel/NotEnoughMemoryLabel.tsx +++ b/web/containers/ModelLabel/NotEnoughMemoryLabel.tsx @@ -1,32 +1,49 @@ -import { memo } from 'react' +import { Fragment, memo } from 'react' import { Badge, Tooltip } from '@janhq/joi' -import { InfoIcon } from 'lucide-react' -import { twMerge } from 'tailwind-merge' +import { AlertTriangleIcon, InfoIcon } from 'lucide-react' type Props = { compact?: boolean unit: string } +const tooltipContent = `Your device doesn't have enough RAM to run this model. Consider upgrading your RAM or using a device with more memory capacity.` + const NotEnoughMemoryLabel = ({ unit, compact }: Props) => ( - - {!compact && Not enough {unit}} - - ) : ( - - ) - } - content="This tag signals insufficient RAM for optimal model performance. It's dynamic and may change with your system's RAM availability." - /> - + <> + {compact ? ( +
+ + } + content={ + + Not enough RAM: {tooltipContent} + + } + /> +
+ ) : ( + + Not enough {unit} + + } + content={ + + Not enough RAM: {tooltipContent} + + } + /> + + )} + ) export default memo(NotEnoughMemoryLabel) diff --git a/web/containers/ModelLabel/SlowOnYourDeviceLabel.tsx b/web/containers/ModelLabel/SlowOnYourDeviceLabel.tsx index d89fd2505..e8e9bcb4d 100644 --- a/web/containers/ModelLabel/SlowOnYourDeviceLabel.tsx +++ b/web/containers/ModelLabel/SlowOnYourDeviceLabel.tsx @@ -1,32 +1,49 @@ -import { memo } from 'react' +import { Fragment, memo } from 'react' import { Badge, Tooltip } from '@janhq/joi' -import { InfoIcon } from 'lucide-react' -import { twMerge } from 'tailwind-merge' +import { AlertTriangleIcon, InfoIcon } from 'lucide-react' type Props = { compact?: boolean } +const tooltipContent = `Your device may be running low on available RAM, which can affect the speed of this model. Try closing any unnecessary applications to free up system memory.` + const SlowOnYourDeviceLabel = ({ compact }: Props) => ( - - {!compact && Slow on your device} - - ) : ( - - ) - } - content="This tag indicates that your current RAM performance may affect model speed. It can change based on other active apps. To improve, consider closing unnecessary applications to free up RAM." - /> - + <> + {compact ? ( +
+ + } + content={ + + Slow on your device: {tooltipContent} + + } + /> +
+ ) : ( + + Slow on your device + + } + content={ + + Slow on your device: {tooltipContent} + + } + /> + + )} + ) export default memo(SlowOnYourDeviceLabel)