Skip to content

Commit 70fa3e2

Browse files
authored
fix(astro): work-around for dev-mode's ReferenceError: __WC_CONFIG__ is not defined errors (#293)
1 parent 4eb5bce commit 70fa3e2

File tree

4 files changed

+40
-44
lines changed

4 files changed

+40
-44
lines changed

packages/astro/src/default/components/OpenInStackblitzLink.astro

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import StackBlitzSDK from '@stackblitz/sdk';
2+
import { tutorialStore } from './webcontainer.js';
3+
4+
export function OpenInStackblitzLink() {
5+
return (
6+
<button
7+
title="Open in StackBlitz"
8+
className="flex items-center font-size-3.5 text-tk-elements-topBar-iconButton-iconColor hover:text-tk-elements-topBar-iconButton-iconColorHover transition-theme bg-tk-elements-topBar-iconButton-backgroundColor hover:bg-tk-elements-topBar-iconButton-backgroundColorHover p-1 rounded-md"
9+
onClick={onClick}
10+
>
11+
<svg viewBox="0 0 28 28" aria-hidden="true" height="24" width="24">
12+
<path
13+
fill="currentColor"
14+
d="M12.747 16.273h-7.46L18.925 1.5l-3.671 10.227h7.46L9.075 26.5l3.671-10.227z"
15+
></path>
16+
</svg>
17+
</button>
18+
);
19+
}
20+
21+
function onClick() {
22+
const lesson = tutorialStore.lesson;
23+
24+
if (!lesson) {
25+
throw new Error('Missing lesson');
26+
}
27+
28+
const snapshot = tutorialStore.takeSnapshot();
29+
const options = typeof lesson.data.openInStackBlitz === 'object' ? lesson.data.openInStackBlitz : {};
30+
31+
StackBlitzSDK.openProject({
32+
title: options.projectTitle || 'Project generated by TutorialKit',
33+
description: options.projectDescription,
34+
template: options.projectTemplate || 'node',
35+
files: snapshot.files,
36+
});
37+
}

packages/astro/src/default/components/TopBarWrapper.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { TopBar } from 'tutorialkit:override-components';
33
import type { Lesson } from '@tutorialkit/types';
44
import { ThemeSwitch } from './ThemeSwitch';
55
import { LoginButton } from './LoginButton';
6-
import OpenInStackblitzLink from './OpenInStackblitzLink.astro';
6+
import { OpenInStackblitzLink } from './OpenInStackblitzLink';
77
import Logo from './Logo.astro';
88
import { useAuth } from './setup';
99
@@ -18,7 +18,7 @@ const { logoLink, openInStackBlitz } = Astro.props;
1818
<TopBar>
1919
<Logo slot="logo" logoLink={logoLink ?? '/'} />
2020

21-
{openInStackBlitz && <OpenInStackblitzLink slot="open-in-stackblitz-link" />}
21+
{openInStackBlitz && <OpenInStackblitzLink client:load transition:persist slot="open-in-stackblitz-link" />}
2222

2323
<ThemeSwitch client:load transition:persist slot="theme-switch" />
2424

packages/cli/tests/__snapshots__/create-tutorial.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ exports[`create and eject a project 1`] = `
209209
"src/components/MobileContentToggle.astro",
210210
"src/components/NavCard.astro",
211211
"src/components/NavWrapper.tsx",
212-
"src/components/OpenInStackblitzLink.astro",
212+
"src/components/OpenInStackblitzLink.tsx",
213213
"src/components/PageLoadingIndicator.astro",
214214
"src/components/ResizablePanel.astro",
215215
"src/components/ThemeSwitch.tsx",

0 commit comments

Comments
 (0)