'use client'; import { useState } from 'react'; import { api } from '~/trpc/react'; import { ScriptCard } from './ScriptCard'; import { ScriptDetailModal } from './ScriptDetailModal'; import type { ScriptCard as ScriptCardType, Script } from '~/types/script'; export function ScriptsGrid() { const [selectedSlug, setSelectedSlug] = useState(null); const [isModalOpen, setIsModalOpen] = useState(false); const { data: scriptCardsData, isLoading, error, refetch } = api.scripts.getScriptCards.useQuery(); const { data: scriptData } = api.scripts.getScriptBySlug.useQuery( { slug: selectedSlug ?? '' }, { enabled: !!selectedSlug } ); const handleCardClick = (scriptCard: ScriptCardType) => { setSelectedSlug(scriptCard.slug); setIsModalOpen(true); }; const handleCloseModal = () => { setIsModalOpen(false); setSelectedSlug(null); }; if (isLoading) { return (
Loading scripts...
); } if (error || !scriptCardsData?.success) { return (

Failed to load scripts

{scriptCardsData?.error || 'Unknown error occurred'}

No JSON files found in scripts/json directory.

Use the "Resync Scripts" button to download from GitHub.

); } const scripts = scriptCardsData.cards || []; if (scripts.length === 0) { return (

No scripts found

No script files were found in the repository.

); } return ( <>
{scripts.map((script) => ( ))}
); }