import { useState, useCallback, useRef, useEffect } from 'react'; import { Card, Text, Title, Loader, Stack, Container } from '@mantine/core'; import { DownloadCard } from '@/components/DownloadCard'; import { getPlatformDisplayName } from '@/utils/platform'; import { formatDownloadSize } from '@/utils/format'; import { getAssetDescription } from '@/utils/assets'; import { useKoboldVersionsStore } from '@/stores/koboldVersions'; import type { DownloadItem } from '@/types/electron'; interface DownloadScreenProps { onDownloadComplete: () => void; } export const DownloadScreen = ({ onDownloadComplete }: DownloadScreenProps) => { const { platform, availableDownloads, loadingPlatform, loadingRemote, downloading, handleDownload: handleDownloadFromStore, } = useKoboldVersionsStore(); const [downloadingAsset, setDownloadingAsset] = useState(null); const downloadingItemRef = useRef(null); const loading = loadingPlatform || loadingRemote; const handleDownload = useCallback( async (download: DownloadItem) => { setDownloadingAsset(download.name); await handleDownloadFromStore({ item: download, isUpdate: false, wasCurrentBinary: false, }); onDownloadComplete(); setTimeout(() => { setDownloadingAsset(null); }, 200); }, [handleDownloadFromStore, onDownloadComplete] ); useEffect(() => { if (downloading && downloadingItemRef.current) { downloadingItemRef.current.scrollIntoView({ behavior: 'smooth', block: 'center', }); } }, [downloading]); return ( Available Binaries for Your Platform {loading ? ( Preparing download options... ) : ( <> {availableDownloads.length > 0 ? ( {availableDownloads.map((download) => { const isDownloading = Boolean(downloading) && downloadingAsset === download.name; return (
{ e.stopPropagation(); handleDownload(download); }} />
); })}
) : ( No downloads available Unable to fetch downloads for your platform ( {getPlatformDisplayName(platform)}). Please check your internet connection and try again. )} )}
); };