Skip to content

Commit bb65ace

Browse files
authored
Fix #6487 specify which Sandpack files go into a src directory (#6496)
* specify which sandbox files go in src directory * fix some stragglers
1 parent e3c25d1 commit bb65ace

File tree

73 files changed

+862
-868
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+862
-868
lines changed

src/components/MDX/Sandpack/createFileMap.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44

55
import type {SandpackFile} from '@codesandbox/sandpack-react/unstyled';
66

7-
/**
8-
* Ideally, we should update all markdown files and all the sandboxes
9-
* to use the same folder structure to include `src`. However, we can
10-
* do the same by prepending the root folder on this function.
11-
*/
12-
const rootFolder = '/src/';
137
export const AppJSPath = `/src/App.js`;
148
export const StylesCSSPath = `/src/styles.css`;
159
export const SUPPORTED_FILES = [AppJSPath, StylesCSSPath];
@@ -27,7 +21,7 @@ export const createFileMap = (codeSnippets: any) => {
2721

2822
if (props.meta) {
2923
const [name, ...params] = props.meta.split(' ');
30-
filePath = rootFolder + name;
24+
filePath = '/' + name;
3125
if (params.includes('hidden')) {
3226
fileHidden = true;
3327
}

src/content/blog/2023/03/16/introducing-react-dev.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ If you like to learn by doing, we recommend checking out the [Tic-Tac-Toe Tutori
5757

5858
<Sandpack>
5959

60-
```js App.js
60+
```js src/App.js
6161
import { useState } from 'react';
6262

6363
function Square({ value, onSquareClick }) {
@@ -175,7 +175,7 @@ function calculateWinner(squares) {
175175
}
176176
```
177177

178-
```css styles.css
178+
```css src/styles.css
179179
* {
180180
box-sizing: border-box;
181181
}

src/content/learn/add-react-to-an-existing-project.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Then add these lines of code at the top of your main JavaScript file (it might b
6767
</html>
6868
```
6969

70-
```js index.js active
70+
```js src/index.js active
7171
import { createRoot } from 'react-dom/client';
7272

7373
// Clear the existing HTML content
@@ -131,7 +131,7 @@ This lets you find that HTML element with [`document.getElementById`](https://de
131131
</html>
132132
```
133133

134-
```js index.js active
134+
```js src/index.js active
135135
import { createRoot } from 'react-dom/client';
136136

137137
function NavigationBar() {

src/content/learn/adding-interactivity.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export default function Gallery() {
134134
}
135135
```
136136

137-
```js data.js
137+
```js src/data.js
138138
export const sculptureList = [{
139139
name: 'Homenaje a la Neurocirugía',
140140
artist: 'Marta Colvin Andrade',

src/content/learn/choosing-the-state-structure.md

+31-31
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ export default function TravelPlan() {
612612
}
613613
```
614614

615-
```js places.js active
615+
```js src/places.js active
616616
export const initialTravelPlan = {
617617
id: 0,
618618
title: '(Root)',
@@ -868,7 +868,7 @@ export default function TravelPlan() {
868868
}
869869
```
870870

871-
```js places.js active
871+
```js src/places.js active
872872
export const initialTravelPlan = {
873873
0: {
874874
id: 0,
@@ -1204,7 +1204,7 @@ function PlaceTree({ id, parentId, placesById, onComplete }) {
12041204
}
12051205
```
12061206

1207-
```js places.js
1207+
```js src/places.js
12081208
export const initialTravelPlan = {
12091209
0: {
12101210
id: 0,
@@ -1543,7 +1543,7 @@ function PlaceTree({ id, parentId, placesById, onComplete }) {
15431543
}
15441544
```
15451545
1546-
```js places.js
1546+
```js src/places.js
15471547
export const initialTravelPlan = {
15481548
0: {
15491549
id: 0,
@@ -1841,7 +1841,7 @@ This `Clock` component receives two props: `color` and `time`. When you select a
18411841
18421842
<Sandpack>
18431843
1844-
```js Clock.js active
1844+
```js src/Clock.js active
18451845
import { useState } from 'react';
18461846

18471847
export default function Clock(props) {
@@ -1854,7 +1854,7 @@ export default function Clock(props) {
18541854
}
18551855
```
18561856
1857-
```js App.js hidden
1857+
```js src/App.js hidden
18581858
import { useState, useEffect } from 'react';
18591859
import Clock from './Clock.js';
18601860

@@ -1896,7 +1896,7 @@ The issue is that this component has `color` state initialized with the initial
18961896
18971897
<Sandpack>
18981898
1899-
```js Clock.js active
1899+
```js src/Clock.js active
19001900
import { useState } from 'react';
19011901

19021902
export default function Clock(props) {
@@ -1908,7 +1908,7 @@ export default function Clock(props) {
19081908
}
19091909
```
19101910
1911-
```js App.js hidden
1911+
```js src/App.js hidden
19121912
import { useState, useEffect } from 'react';
19131913
import Clock from './Clock.js';
19141914

@@ -1948,7 +1948,7 @@ Or, using the destructuring syntax:
19481948
19491949
<Sandpack>
19501950
1951-
```js Clock.js active
1951+
```js src/Clock.js active
19521952
import { useState } from 'react';
19531953

19541954
export default function Clock({ color, time }) {
@@ -1960,7 +1960,7 @@ export default function Clock({ color, time }) {
19601960
}
19611961
```
19621962
1963-
```js App.js hidden
1963+
```js src/App.js hidden
19641964
import { useState, useEffect } from 'react';
19651965
import Clock from './Clock.js';
19661966

@@ -2010,7 +2010,7 @@ Is any state in this example redundant?
20102010
20112011
<Sandpack>
20122012
2013-
```js App.js
2013+
```js src/App.js
20142014
import { useState } from 'react';
20152015
import AddItem from './AddItem.js';
20162016
import PackingList from './PackingList.js';
@@ -2078,7 +2078,7 @@ export default function TravelPlan() {
20782078
}
20792079
```
20802080
2081-
```js AddItem.js hidden
2081+
```js src/AddItem.js hidden
20822082
import { useState } from 'react';
20832083

20842084
export default function AddItem({ onAddItem }) {
@@ -2099,7 +2099,7 @@ export default function AddItem({ onAddItem }) {
20992099
}
21002100
```
21012101
2102-
```js PackingList.js hidden
2102+
```js src/PackingList.js hidden
21032103
import { useState } from 'react';
21042104

21052105
export default function PackingList({
@@ -2149,7 +2149,7 @@ Although you could carefully change each event handler to update the `total` and
21492149
21502150
<Sandpack>
21512151
2152-
```js App.js
2152+
```js src/App.js
21532153
import { useState } from 'react';
21542154
import AddItem from './AddItem.js';
21552155
import PackingList from './PackingList.js';
@@ -2213,7 +2213,7 @@ export default function TravelPlan() {
22132213
}
22142214
```
22152215
2216-
```js AddItem.js hidden
2216+
```js src/AddItem.js hidden
22172217
import { useState } from 'react';
22182218

22192219
export default function AddItem({ onAddItem }) {
@@ -2234,7 +2234,7 @@ export default function AddItem({ onAddItem }) {
22342234
}
22352235
```
22362236
2237-
```js PackingList.js hidden
2237+
```js src/PackingList.js hidden
22382238
import { useState } from 'react';
22392239

22402240
export default function PackingList({
@@ -2290,7 +2290,7 @@ This code works, but there is a minor UI glitch. When you press "Star" or "Unsta
22902290
22912291
<Sandpack>
22922292
2293-
```js App.js
2293+
```js src/App.js
22942294
import { useState } from 'react';
22952295
import { initialLetters } from './data.js';
22962296
import Letter from './Letter.js';
@@ -2337,7 +2337,7 @@ export default function MailClient() {
23372337
}
23382338
```
23392339
2340-
```js Letter.js
2340+
```js src/Letter.js
23412341
export default function Letter({
23422342
letter,
23432343
isHighlighted,
@@ -2367,7 +2367,7 @@ export default function Letter({
23672367
}
23682368
```
23692369
2370-
```js data.js
2370+
```js src/data.js
23712371
export const initialLetters = [{
23722372
id: 0,
23732373
subject: 'Ready for adventure?',
@@ -2399,7 +2399,7 @@ To fix the issue, remove the duplication from state. Instead of storing *the let
23992399
24002400
<Sandpack>
24012401
2402-
```js App.js
2402+
```js src/App.js
24032403
import { useState } from 'react';
24042404
import { initialLetters } from './data.js';
24052405
import Letter from './Letter.js';
@@ -2446,7 +2446,7 @@ export default function MailClient() {
24462446
}
24472447
```
24482448
2449-
```js Letter.js
2449+
```js src/Letter.js
24502450
export default function Letter({
24512451
letter,
24522452
isHighlighted,
@@ -2476,7 +2476,7 @@ export default function Letter({
24762476
}
24772477
```
24782478
2479-
```js data.js
2479+
```js src/data.js
24802480
export const initialLetters = [{
24812481
id: 0,
24822482
subject: 'Ready for adventure?',
@@ -2516,7 +2516,7 @@ Instead of a single selected ID, you might want to hold an array or a [Set](http
25162516
25172517
<Sandpack>
25182518
2519-
```js App.js
2519+
```js src/App.js
25202520
import { useState } from 'react';
25212521
import { letters } from './data.js';
25222522
import Letter from './Letter.js';
@@ -2559,7 +2559,7 @@ export default function MailClient() {
25592559
}
25602560
```
25612561
2562-
```js Letter.js
2562+
```js src/Letter.js
25632563
export default function Letter({
25642564
letter,
25652565
onToggle,
@@ -2584,7 +2584,7 @@ export default function Letter({
25842584
}
25852585
```
25862586
2587-
```js data.js
2587+
```js src/data.js
25882588
export const letters = [{
25892589
id: 0,
25902590
subject: 'Ready for adventure?',
@@ -2615,7 +2615,7 @@ Instead of a single `selectedId`, keep a `selectedIds` *array* in state. For exa
26152615
26162616
<Sandpack>
26172617
2618-
```js App.js
2618+
```js src/App.js
26192619
import { useState } from 'react';
26202620
import { letters } from './data.js';
26212621
import Letter from './Letter.js';
@@ -2667,7 +2667,7 @@ export default function MailClient() {
26672667
}
26682668
```
26692669
2670-
```js Letter.js
2670+
```js src/Letter.js
26712671
export default function Letter({
26722672
letter,
26732673
onToggle,
@@ -2692,7 +2692,7 @@ export default function Letter({
26922692
}
26932693
```
26942694
2695-
```js data.js
2695+
```js src/data.js
26962696
export const letters = [{
26972697
id: 0,
26982698
subject: 'Ready for adventure?',
@@ -2723,7 +2723,7 @@ To fix this, you can hold a [Set](https://developer.mozilla.org/en-US/docs/Web/J
27232723
27242724
<Sandpack>
27252725
2726-
```js App.js
2726+
```js src/App.js
27272727
import { useState } from 'react';
27282728
import { letters } from './data.js';
27292729
import Letter from './Letter.js';
@@ -2772,7 +2772,7 @@ export default function MailClient() {
27722772
}
27732773
```
27742774
2775-
```js Letter.js
2775+
```js src/Letter.js
27762776
export default function Letter({
27772777
letter,
27782778
onToggle,
@@ -2797,7 +2797,7 @@ export default function Letter({
27972797
}
27982798
```
27992799
2800-
```js data.js
2800+
```js src/data.js
28012801
export const letters = [{
28022802
id: 0,
28032803
subject: 'Ready for adventure?',

0 commit comments

Comments
 (0)