import { useRef, useState, useEffect } from 'react'; import { RefreshCw } from 'lucide-react'; import { useSetRecoilState } from 'recoil'; import * as Tabs from '@radix-ui/react-tabs'; import { SandpackPreviewRef } from '@codesandbox/sandpack-react'; import useArtifacts from '~/hooks/Artifacts/useArtifacts'; import { CodeMarkdown, CopyCodeButton } from './Code'; import { getFileExtension } from '~/utils/artifacts'; import { ArtifactPreview } from './ArtifactPreview'; import { cn } from '~/utils'; import store from '~/store'; export default function Artifacts() { const previewRef = useRef(); const [isRefreshing, setIsRefreshing] = useState(false); const [isVisible, setIsVisible] = useState(false); const setArtifactsVisible = useSetRecoilState(store.artifactsVisible); useEffect(() => { setIsVisible(true); }, []); const { activeTab, isMermaid, isSubmitting, setActiveTab, currentIndex, cycleArtifact, currentArtifact, orderedArtifactIds, } = useArtifacts(); if (currentArtifact === null || currentArtifact === undefined) { return null; } const handleRefresh = () => { setIsRefreshing(true); const client = previewRef.current?.getClient(); if (client != null) { client.dispatch({ type: 'refresh' }); } setTimeout(() => setIsRefreshing(false), 750); }; return ( {/* Main Parent */}
{/* Main Container */}
{/* Header */}

{currentArtifact.title}

{/* Refresh button */} {activeTab === 'preview' && ( )} Preview Code
{/* Content */} } /> {/* Footer */}
{`${currentIndex + 1} / ${ orderedArtifactIds.length }`}
{/* Download Button */} {/* */} {/* Publish button */} {/* */}
); }