Skip to content

Commit

Permalink
fix(export): normalize files and pass template (#1145)
Browse files Browse the repository at this point in the history
  • Loading branch information
danilowoz authored Jun 6, 2024
1 parent b0e0761 commit c3bc09d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 0 additions & 2 deletions sandpack-react/src/PrivatePackage.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export default function App() {
return <Button>Hello World</Button>
}`,
}}
// options={{ bundlerURL: `http://localhost:3000` }}
// options={{ bundlerURL: `https://2-1-0-sandpack.codesandbox.stream/` }}
teamId="642af90c-4717-4730-bad3-e4c1e37ca5e2"
template="react"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,16 @@ export const ExportToWorkspaceButton: React.FC<
throw new Error("Missing `apiToken` property");
}

const normalizedFiles = Object.keys(state.files).reduce((prev, next) => {
const fileName = next.replace("/", "");
return { ...prev, [fileName]: state.files[next] };
}, {});

const response = await fetch("https://api.codesandbox.io/sandbox", {
method: "POST",
body: JSON.stringify({
files: state.files,
template: state.environment,
files: normalizedFiles,
privacy: state.exportOptions.privacy === "public" ? 0 : 2,
}),
headers: {
Expand All @@ -79,7 +85,7 @@ export const ExportToWorkspaceButton: React.FC<
const data: { data: { alias: string } } = await response.json();

window.open(
`https://codesandbox.io/p/sandbox/${data.data.alias}?file=/src/App.js&utm-source=storybook-addon`,
`https://codesandbox.io/p/sandbox/${data.data.alias}?file=/${state.activeFile}&utm-source=storybook-addon`,
"_blank"
);
};
Expand Down

0 comments on commit c3bc09d

Please sign in to comment.