diff --git a/client/src/components/Artifacts/Artifacts.tsx b/client/src/components/Artifacts/Artifacts.tsx
index ef5633965d..79cc6d9001 100644
--- a/client/src/components/Artifacts/Artifacts.tsx
+++ b/client/src/components/Artifacts/Artifacts.tsx
@@ -3,17 +3,18 @@ import { useRecoilValue } from 'recoil';
import * as Tabs from '@radix-ui/react-tabs';
import { Sandpack } from '@codesandbox/sandpack-react';
import { SandpackPreview, SandpackProvider } from '@codesandbox/sandpack-react/unstyled';
-import { mapCodeFiles, sharedOptions, sharedFiles, sharedProps } from '~/utils/artifacts';
+import { sharedOptions, sharedFiles, sharedProps } from '~/utils/artifacts';
import store from '~/store';
-export function CodeViewer({ showEditor = false }: { showEditor?: boolean }) {
- const artifactIds = useRecoilValue(store.artifactIdsState);
- const artifacts = useRecoilValue(store.artifactsState);
+export function CodeViewer({
+ showEditor = false,
+ content,
+}: {
+ showEditor?: boolean;
+ content: string;
+}) {
+ const files = { '/App.js': content };
- // const files = useMemo(() => mapCodeFiles(artifactIds, artifacts), [artifactIds, artifacts]);
-
- // console.log('CODE FILES & blocks', files, artifacts);
- const files = {};
if (Object.keys(files).length === 0) {
return null;
}
@@ -38,15 +39,10 @@ export function CodeViewer({ showEditor = false }: { showEditor?: boolean }) {
...files,
...sharedFiles,
}}
- className="flex h-full w-full justify-center"
options={{ ...sharedOptions }}
{...sharedProps}
>
-
+
);
}
@@ -56,38 +52,156 @@ export default function Artifacts() {
const artifactIds = useRecoilValue(store.artifactIdsState);
const artifacts = useRecoilValue(store.artifactsState);
- // const files = useMemo(() => mapCodeFiles(artifactIds, artifacts), [artifactIds, artifacts]);
- // const firstFileContent = Object.values(files)[0] || '';
+ const [currentArtifactIndex, setCurrentArtifactIndex] = useState(artifactIds.length - 1);
- const firstFileContent = '';
+ const currentArtifact = useMemo(() => {
+ if (artifactIds.length === 0) {
+ return null;
+ }
+ const currentId = artifactIds[currentArtifactIndex];
+ return artifacts[currentId];
+ }, [artifacts, artifactIds, currentArtifactIndex]);
+
+ const cycleArtifact = (direction: 'next' | 'prev') => {
+ setCurrentArtifactIndex((prevIndex) => {
+ if (direction === 'next') {
+ return (prevIndex + 1) % artifactIds.length;
+ } else {
+ return (prevIndex - 1 + artifactIds.length) % artifactIds.length;
+ }
+ });
+ };
+
+ if (!currentArtifact) {
+ return
No artifacts available.
;
+ }
return (
-
-
-
-
-
+
+ {/* Header */}
+
+
+
+
+ {currentArtifact.title}
+
+
+
+
- Code
-
-
- Preview
-
-
-
-
- {firstFileContent}
+
+
+
+
+
+
+
+ {/* Content */}
+
+ {activeTab === 'code' ? (
+
+ {currentArtifact.content}
-
-
-
-
-
+ ) : (
+
+ )}
+
+
+ {/* Footer */}
+
+
+
+
Last edited 7 hours ago
+
+
+
+
+
+
+
+
);
diff --git a/client/src/components/SidePanel/SidePanel.tsx b/client/src/components/SidePanel/SidePanel.tsx
index b9c5921d0f..ce052309ba 100644
--- a/client/src/components/SidePanel/SidePanel.tsx
+++ b/client/src/components/SidePanel/SidePanel.tsx
@@ -150,7 +150,7 @@ const SidePanel = ({
{artifacts != null && (
<>
-
+
{artifacts}