diff --git a/src/app/page.tsx b/src/app/page.tsx index 9d66c4f..6fdf431 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -12,12 +12,41 @@ import { SettingsButton } from './_components/SettingsButton'; import { VersionDisplay } from './_components/VersionDisplay'; import { Button } from './_components/ui/button'; import { Rocket, Package, HardDrive, FolderOpen } from 'lucide-react'; +import { api } from '~/trpc/react'; export default function Home() { const [runningScript, setRunningScript] = useState<{ path: string; name: string; mode?: 'local' | 'ssh'; server?: any } | null>(null); const [activeTab, setActiveTab] = useState<'scripts' | 'downloaded' | 'installed'>('scripts'); const terminalRef = useRef(null); + // Fetch data for script counts + const { data: scriptCardsData } = api.scripts.getScriptCardsWithCategories.useQuery(); + const { data: localScriptsData } = api.scripts.getCtScripts.useQuery(); + const { data: installedScriptsData } = api.installedScripts.getAllInstalledScripts.useQuery(); + + // Calculate script counts + const scriptCounts = { + available: scriptCardsData?.success ? scriptCardsData.cards?.length ?? 0 : 0, + downloaded: (() => { + if (!scriptCardsData?.success || !localScriptsData?.scripts) return 0; + + // Count scripts that are both in GitHub data and have local versions + const githubScripts = scriptCardsData.cards ?? []; + const localScripts = localScriptsData.scripts ?? []; + + return githubScripts.filter(script => { + if (!script?.name) return false; + return localScripts.some(local => { + if (!local?.name) return false; + const localName = local.name.replace(/\.sh$/, ''); + return localName.toLowerCase() === script.name.toLowerCase() || + localName.toLowerCase() === (script.slug ?? '').toLowerCase(); + }); + }).length; + })(), + installed: installedScriptsData?.scripts?.length ?? 0 + }; + const scrollToTerminal = () => { if (terminalRef.current) { // Get the element's position and scroll with a small offset for better mobile experience @@ -83,6 +112,9 @@ export default function Home() { Available Scripts Available + + {scriptCounts.available} +