import { config } from "@/config"; import { Link, useLocation } from "react-router-dom"; import { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupContent, SidebarHeader, SidebarMenu, SidebarMenuButton, SidebarMenuItem, useSidebar } from "@/components/ui/sidebar"; import { CircleArrowUp, Download, Puzzle, Settings, SquarePlay, } from "lucide-react"; import { isActive as isActiveSidebarItem } from "@/utils"; import { RoutesObj } from "@/types/route"; import { useDownloadStatesStore, useSettingsPageStatesStore } from "@/services/store"; import { Badge } from "@/components/ui/badge"; import { useEffect, useState } from "react"; import { NeoDlpLogo } from "@/components/icons/neodlp"; import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { AlertDialog, AlertDialogContent, AlertDialogDescription, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from "@/components/ui/alert-dialog"; import { Progress } from "@/components/ui/progress"; import useAppUpdater from "@/helpers/use-app-updater"; export function AppSidebar() { const downloadStates = useDownloadStatesStore(state => state.downloadStates); const ongoingDownloads = downloadStates.filter(state => ['starting', 'downloading', 'queued'].includes(state.download_status) ); const appVersion = useSettingsPageStatesStore(state => state.appVersion); const isFetchingAppVersion = useSettingsPageStatesStore(state => state.isFetchingAppVersion); const appUpdate = useSettingsPageStatesStore(state => state.appUpdate); const isUpdatingApp = useSettingsPageStatesStore(state => state.isUpdatingApp); const appUpdateDownloadProgress = useSettingsPageStatesStore(state => state.appUpdateDownloadProgress); const location = useLocation(); const { open } = useSidebar(); const { downloadAndInstallAppUpdate } = useAppUpdater(); const [showBadge, setShowBadge] = useState(false); const topItems: Array = [ { title: "Downloader", url: "/", icon: Download, }, { title: "Library", url: "/library", icon: SquarePlay, }, { title: "Extension", url: "/extension", icon: Puzzle, } ]; const bottomItems: Array = [ { title: "Settings", url: "/settings", icon: Settings, } ]; useEffect(() => { let timeout: NodeJS.Timeout; if (open) { timeout = setTimeout(() => { setShowBadge(true); }, 300); } else { setShowBadge(false); } return () => { clearTimeout(timeout); }; }, [open]); return (
Neo Downloader Plus {isFetchingAppVersion ? 'Loading...' : `v${appVersion}`}
{/* */} {/* Tools */} {topItems.map((item) => ( {!open ? ( {item.title} {item.title === "Library" && ongoingDownloads.length > 0 && showBadge && ( {ongoingDownloads.length} )}

{item.title}

) : ( {item.title} {item.title === "Library" && ongoingDownloads.length > 0 && showBadge && ( {ongoingDownloads.length} )} )}
))}
{appUpdate && !open && (

Update Available

(Expand sidebar to view update)

)} {appUpdate && open && ( Update Available (v{appUpdate.version}) A new version of {config.appName} is available. Please update to the latest version for the best experience. Updating {config.appName} Updating {config.appName} to v{appUpdate.version}, Please be patience! Do not quit the app untill the update finishes. The app will auto re-launch to complete the update, Please allow all system prompts from {config.appName} if asked. Downloading update... {appUpdateDownloadProgress}% )} {bottomItems.map((item) => ( {!open ? ( {item.title}

{item.title}

) : ( {item.title} )}
))}
) }