Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
ui: update UI for download management
Faisal Amir4167e58c2f40
diff --git a/web-app/src/components/left-sidebar/index.tsx b/web-app/src/components/left-sidebar/index.tsxindex aad4ff256..0cdd44955 100644--- a/web-app/src/components/left-sidebar/index.tsx+++ b/web-app/src/components/left-sidebar/index.tsx@@ -2,11 +2,11 @@ import { DownloadManagement } from '@/containers/DownloadManegement'import { NavChats } from './NavChats'import { NavMain } from './NavMain'import { NavProjects } from './NavProjects'+import { useLeftPanel } from '@/hooks/useLeftPanel'import {Sidebar,SidebarContent,- SidebarFooter,SidebarTrigger,SidebarHeader,SidebarRail,@@ -14,13 +14,15 @@ import {import { cn } from '@/lib/utils'export function LeftSidebar() {+ const { open: isLeftPanelOpen } = useLeftPanel()return (<div className='relative z-50'><Sidebar variant="floating" collapsible="offcanvas"><SidebarHeader className="flex px-1"><div className={cn("flex items-center w-full justify-between", IS_MACOS && "justify-end")}>{!IS_MACOS && <span className="ml-2 font-medium font-studio">Jan</span>}- <SidebarTrigger className="text-muted-foreground rounded-full hover:bg-sidebar-foreground/8! -mt-0.5 relative z-50" />+ {isLeftPanelOpen && <DownloadManagement />}+ <SidebarTrigger className="text-muted-foreground rounded-full hover:bg-sidebar-foreground/8! -mt-0.5 relative z-50 ml-0.5" /></div><NavMain /></SidebarHeader>@@ -28,9 +30,6 @@ export function LeftSidebar() {<NavProjects /><NavChats /></SidebarContent>- <SidebarFooter>- <DownloadManagement />- </SidebarFooter><SidebarRail /></Sidebar></div>diff --git a/web-app/src/containers/DownloadManegement.tsx b/web-app/src/containers/DownloadManegement.tsxindex 7099429c5..f17daf0ef 100644--- a/web-app/src/containers/DownloadManegement.tsx+++ b/web-app/src/containers/DownloadManegement.tsx@@ -5,21 +5,21 @@ import {} from '@/components/ui/popover'import { Progress } from '@/components/ui/progress'import { useDownloadStore } from '@/hooks/useDownloadStore'-import { useLeftPanel } from '@/hooks/useLeftPanel'import { useAppUpdater } from '@/hooks/useAppUpdater'import { useServiceHub } from '@/hooks/useServiceHub'import { DownloadEvent, DownloadState, events, AppEvent } from '@janhq/core'-import { IconDownload, IconX } from '@tabler/icons-react'+import { IconX } from '@tabler/icons-react'import { useCallback, useEffect, useMemo, useState } from 'react'import { toast } from 'sonner'import { useTranslation } from '@/i18n/react-i18next-compat'import { useNavigate } from '@tanstack/react-router'import { route } from '@/constants/routes'+import { DownloadIcon } from 'lucide-react'+import { Button } from '@/components/ui/button'export function DownloadManagement() {const { t } = useTranslation()const navigate = useNavigate()- const { open: isLeftPanelOpen } = useLeftPanel()const [isPopoverOpen, setIsPopoverOpen] = useState(false)const serviceHub = useServiceHub()const {@@ -362,83 +362,81 @@ export function DownloadManagement() {{downloadCount > 0 && (<Popover open={isPopoverOpen} onOpenChange={setIsPopoverOpen}><PopoverTrigger asChild>- {isLeftPanelOpen ? (- <div className="p-2 rounded-md my-1 relative border cursor-pointer text-left">- <div className="font-studio font-medium flex gap-2 items-center justify-between">- <span className='text-sm'>{t('downloads')}</span>- <div className="bg-primary/50 font-bold size-4 rounded-full flex items-center justify-center text-xs">- <span>{downloadCount}</span>- </div>- </div>- <div className="mt-2 flex items-center justify-between space-x-2">- <Progress value={overallProgress * 100} />- <span className="text-xs font-medium text-left-panel-fg/80 shrink-0">- {Math.round(overallProgress * 100)}%- </span>- </div>- </div>- ) : (- <div className="fixed bottom-4 left-4 z-50 size-10 border-2 rounded-full shadow-md cursor-pointer flex items-center justify-center">- <div className="relative">- <IconDownload- className="text-muted-foreground -mt-1"- size={20}+ <Button variant="ghost" size="icon" className="text-muted-foreground rounded-full hover:bg-sidebar-foreground/8! -mt-0.5 size-7 relative">+ <DownloadIcon className='text-muted-foreground size-4' />+ {downloadCount > 0 && (+ <svg className="absolute inset-0 size-7 -rotate-90" viewBox="0 0 36 36">+ <path+ className="text-primary/30"+ stroke="currentColor"+ strokeWidth="2"+ fill="none"+ d="M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 -31.831"/>- <div className="bg-primary font-bold size-5 rounded-full absolute -top-4 -right-4 flex items-center justify-center text-xs">- <span>{downloadCount}</span>- </div>- </div>- </div>- )}+ <path+ className="text-primary"+ stroke="currentColor"+ strokeWidth="2"+ fill="none"+ strokeLinecap="round"+ strokeDasharray={`${overallProgress * 100}, 100`}+ d="M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 -31.831"+ />+ </svg>+ )}+ </Button></PopoverTrigger><PopoverContent- side="right"- align="end"- className="p-0 overflow-hidden text-sm select-none"+ side="bottom"+ align="start"+ className="p-0 overflow-hidden text-sm select-none rounded-2xl -ml-8"sideOffset={6}onFocusOutside={(e) => e.preventDefault}><div className="flex flex-col">- <div className="px-3 py-2 border-b">+ <div className="px-3 pt-2 flex items-center justify-between"><p>{t('downloading')}</p></div><div className="p-2 max-h-[300px] overflow-y-auto space-y-2">{appUpdateState.isDownloading && (- <div className="rounded-md p-2">+ <div className="rounded-lg p-2 bg-secondary"><div className="flex items-center justify-between"><p className="truncate">App Update</p></div>- <Progress- value={appUpdateState.downloadProgress * 100}- className="my-2"- />- <p className="text-muted-foreground text-xs">- {`${renderGB(appUpdateState.downloadedBytes)} / ${renderGB(appUpdateState.totalBytes)}`}{' '}- GB ({Math.round(appUpdateState.downloadProgress * 100)}- %)- </p>+ <div className="relative z-40">+ <Progress+ value={appUpdateState.downloadProgress * 100}+ className="my-2 h-6 bg-muted-foreground/10 relative rounded-md"+ />+ <div className="absolute w-full top-1/2 transform -translate-y-1/2 flex items-center justify-between px-2">+ <p className="text-xs">+ {Math.round(appUpdateState.downloadProgress * 100)}+ %+ </p>+ <p className="text-xs">+ {`${renderGB(appUpdateState.downloadedBytes)} / ${renderGB(appUpdateState.totalBytes)}`}{' '}+ GB+ </p>+ </div>+ </div></div>)}{downloadProcesses.map((download) => (<divkey={download.id}- className="rounded-md p-2"+ className="rounded-lg p-2 bg-secondary">- <div className="flex items-center justify-between">+ <div className="flex items-center justify-between gap-2"><p className="truncate">{download.name}</p><div className="shrink-0 flex items-center space-x-0.5">- <IconX- size={16}- className="text-muted-foreground cursor-pointer"- title="Cancel download"- onClick={() => {+ <Button variant="secondary" size="icon-xs" onClick={() => {// TODO: Consolidate cancellation logicif (download.id.startsWith('llamacpp') || download.id.startsWith('mlx')) {const downloadManager =@@ -466,19 +464,32 @@ export function DownloadManagement() {}})}- }}- />+ }} >+ <IconX+ size={16}+ className="text-muted-foreground cursor-pointer"+ title="Cancel download"+ />+ </Button>+ </div>+ </div>+ <div className="relative z-40">+ <Progress+ value={download.progress * 100}+ className="my-2 h-6 bg-muted-foreground/10 relative rounded-md"+ />+ <div className="absolute w-full top-1/2 transform -translate-y-1/2 flex items-center justify-between px-2">+ <p className="text-xs">+ {download.total > 0+ ? `${Math.round(download.progress * 100)}%`+ : 'Initializing download...'}+ </p>+ <p className="text-xs">+ {download.total > 0+ && `${renderGB(download.current)} / ${renderGB(download.total)} GB`}+ </p></div></div>- <Progress- value={download.progress * 100}- className="my-2"- />- <p className="text-muted-foreground text-xs">- {download.total > 0- ? `${renderGB(download.current)} / ${renderGB(download.total)} GB (${Math.round(download.progress * 100)}%)`- : 'Initializing download...'}- </p></div>))}</div>diff --git a/web-app/src/containers/HeaderPage.tsx b/web-app/src/containers/HeaderPage.tsxindex 534197659..b87edf744 100644--- a/web-app/src/containers/HeaderPage.tsx+++ b/web-app/src/containers/HeaderPage.tsx@@ -5,6 +5,7 @@ import {} from '@tabler/icons-react'import { ReactNode, memo } from 'react'import { Button } from "@/components/ui/button"+import { DownloadManagement } from '@/containers/DownloadManegement'type HeaderPageProps = {children?: ReactNode@@ -16,27 +17,30 @@ const HeaderPage = memo(function HeaderPage({ children }: HeaderPageProps) {<divclassName={cn('h-15 flex items-center shrink-0',- (IS_MACOS && !open) ? 'pl-22' : ' pl-4',+ (IS_MACOS && !open) ? 'pl-24' : ' pl-4',children === undefined && 'border-none')}><divclassName={cn(- 'flex items-center w-full gap-2',+ 'flex items-center w-full gap-1',)}>{!open && (- <Button- variant="ghost"- size="icon-sm"- className='rounded-full relative z-50'- onClick={() => setLeftPanel(!open)}- aria-label="Toggle sidebar"- >- <IconLayoutSidebar- className="text-muted-foreground relative size-4.5"- />- </Button>+ <>+ <DownloadManagement />+ <Button+ variant="ghost"+ size="icon-sm"+ className='rounded-full relative z-50'+ onClick={() => setLeftPanel(!open)}+ aria-label="Toggle sidebar"+ >+ <IconLayoutSidebar+ className="text-muted-foreground relative size-4.5"+ />+ </Button>+ </>)}<divclassName={cn(