import { useRef, useState, useEffect } from 'react'; import { useSetRecoilState } from 'recoil'; import * as Tabs from '@radix-ui/react-tabs'; import { ArrowLeft, ChevronLeft, ChevronRight, RefreshCw, X } from 'lucide-react'; import type { SandpackPreviewRef, CodeEditorRef } from '@codesandbox/sandpack-react'; import useArtifacts from '~/hooks/Artifacts/useArtifacts'; import DownloadArtifact from './DownloadArtifact'; import { useEditorContext } from '~/Providers'; import ArtifactTabs from './ArtifactTabs'; import { CopyCodeButton } from './Code'; import { useLocalize } from '~/hooks'; import store from '~/store'; export default function Artifacts() { const localize = useLocalize(); const { isMutating } = useEditorContext(); const editorRef = useRef(); const previewRef = useRef(); const [isVisible, setIsVisible] = useState(false); const [isRefreshing, setIsRefreshing] = useState(false); const setArtifactsVisible = useSetRecoilState(store.artifactsVisibility); useEffect(() => { setIsVisible(true); }, []); const { activeTab, isMermaid, 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); }; const closeArtifacts = () => { setIsVisible(false); setTimeout(() => setArtifactsVisible(false), 300); }; return ( {/* Main Parent */}
{/* Main Container */}
{/* Header */}

{currentArtifact.title}

{/* Refresh button */} {activeTab === 'preview' && ( )} {activeTab !== 'preview' && isMutating && ( )} {/* Tabs */} {localize('com_ui_preview')} {localize('com_ui_code')}
{/* Content */} } previewRef={previewRef as React.MutableRefObject} /> {/* Footer */}
{`${currentIndex + 1} / ${ orderedArtifactIds.length }`}
{/* Download Button */} {/* Publish button */} {/* */}
); }