Skip to content

Commit

Permalink
Fix #6487 specify which Sandpack files go into a src directory (#…
Browse files Browse the repository at this point in the history
…6496)

* specify which sandbox files go in src directory

* fix some stragglers
  • Loading branch information
geeseyj authored Dec 15, 2023
1 parent e3c25d1 commit bb65ace
Show file tree
Hide file tree
Showing 73 changed files with 862 additions and 868 deletions.
8 changes: 1 addition & 7 deletions src/components/MDX/Sandpack/createFileMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@

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

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

if (props.meta) {
const [name, ...params] = props.meta.split(' ');
filePath = rootFolder + name;
filePath = '/' + name;
if (params.includes('hidden')) {
fileHidden = true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/content/blog/2023/03/16/introducing-react-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ If you like to learn by doing, we recommend checking out the [Tic-Tac-Toe Tutori

<Sandpack>

```js App.js
```js src/App.js
import { useState } from 'react';

function Square({ value, onSquareClick }) {
Expand Down Expand Up @@ -175,7 +175,7 @@ function calculateWinner(squares) {
}
```

```css styles.css
```css src/styles.css
* {
box-sizing: border-box;
}
Expand Down
4 changes: 2 additions & 2 deletions src/content/learn/add-react-to-an-existing-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Then add these lines of code at the top of your main JavaScript file (it might b
</html>
```

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

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

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

function NavigationBar() {
Expand Down
2 changes: 1 addition & 1 deletion src/content/learn/adding-interactivity.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export default function Gallery() {
}
```

```js data.js
```js src/data.js
export const sculptureList = [{
name: 'Homenaje a la Neurocirugía',
artist: 'Marta Colvin Andrade',
Expand Down
62 changes: 31 additions & 31 deletions src/content/learn/choosing-the-state-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ export default function TravelPlan() {
}
```

```js places.js active
```js src/places.js active
export const initialTravelPlan = {
id: 0,
title: '(Root)',
Expand Down Expand Up @@ -868,7 +868,7 @@ export default function TravelPlan() {
}
```

```js places.js active
```js src/places.js active
export const initialTravelPlan = {
0: {
id: 0,
Expand Down Expand Up @@ -1204,7 +1204,7 @@ function PlaceTree({ id, parentId, placesById, onComplete }) {
}
```

```js places.js
```js src/places.js
export const initialTravelPlan = {
0: {
id: 0,
Expand Down Expand Up @@ -1543,7 +1543,7 @@ function PlaceTree({ id, parentId, placesById, onComplete }) {
}
```
```js places.js
```js src/places.js
export const initialTravelPlan = {
0: {
id: 0,
Expand Down Expand Up @@ -1841,7 +1841,7 @@ This `Clock` component receives two props: `color` and `time`. When you select a
<Sandpack>
```js Clock.js active
```js src/Clock.js active
import { useState } from 'react';

export default function Clock(props) {
Expand All @@ -1854,7 +1854,7 @@ export default function Clock(props) {
}
```
```js App.js hidden
```js src/App.js hidden
import { useState, useEffect } from 'react';
import Clock from './Clock.js';

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

export default function Clock(props) {
Expand All @@ -1908,7 +1908,7 @@ export default function Clock(props) {
}
```
```js App.js hidden
```js src/App.js hidden
import { useState, useEffect } from 'react';
import Clock from './Clock.js';

Expand Down Expand Up @@ -1948,7 +1948,7 @@ Or, using the destructuring syntax:
<Sandpack>
```js Clock.js active
```js src/Clock.js active
import { useState } from 'react';

export default function Clock({ color, time }) {
Expand All @@ -1960,7 +1960,7 @@ export default function Clock({ color, time }) {
}
```
```js App.js hidden
```js src/App.js hidden
import { useState, useEffect } from 'react';
import Clock from './Clock.js';

Expand Down Expand Up @@ -2010,7 +2010,7 @@ Is any state in this example redundant?
<Sandpack>
```js App.js
```js src/App.js
import { useState } from 'react';
import AddItem from './AddItem.js';
import PackingList from './PackingList.js';
Expand Down Expand Up @@ -2078,7 +2078,7 @@ export default function TravelPlan() {
}
```
```js AddItem.js hidden
```js src/AddItem.js hidden
import { useState } from 'react';

export default function AddItem({ onAddItem }) {
Expand All @@ -2099,7 +2099,7 @@ export default function AddItem({ onAddItem }) {
}
```
```js PackingList.js hidden
```js src/PackingList.js hidden
import { useState } from 'react';

export default function PackingList({
Expand Down Expand Up @@ -2149,7 +2149,7 @@ Although you could carefully change each event handler to update the `total` and
<Sandpack>
```js App.js
```js src/App.js
import { useState } from 'react';
import AddItem from './AddItem.js';
import PackingList from './PackingList.js';
Expand Down Expand Up @@ -2213,7 +2213,7 @@ export default function TravelPlan() {
}
```
```js AddItem.js hidden
```js src/AddItem.js hidden
import { useState } from 'react';

export default function AddItem({ onAddItem }) {
Expand All @@ -2234,7 +2234,7 @@ export default function AddItem({ onAddItem }) {
}
```
```js PackingList.js hidden
```js src/PackingList.js hidden
import { useState } from 'react';

export default function PackingList({
Expand Down Expand Up @@ -2290,7 +2290,7 @@ This code works, but there is a minor UI glitch. When you press "Star" or "Unsta
<Sandpack>
```js App.js
```js src/App.js
import { useState } from 'react';
import { initialLetters } from './data.js';
import Letter from './Letter.js';
Expand Down Expand Up @@ -2337,7 +2337,7 @@ export default function MailClient() {
}
```
```js Letter.js
```js src/Letter.js
export default function Letter({
letter,
isHighlighted,
Expand Down Expand Up @@ -2367,7 +2367,7 @@ export default function Letter({
}
```
```js data.js
```js src/data.js
export const initialLetters = [{
id: 0,
subject: 'Ready for adventure?',
Expand Down Expand Up @@ -2399,7 +2399,7 @@ To fix the issue, remove the duplication from state. Instead of storing *the let
<Sandpack>
```js App.js
```js src/App.js
import { useState } from 'react';
import { initialLetters } from './data.js';
import Letter from './Letter.js';
Expand Down Expand Up @@ -2446,7 +2446,7 @@ export default function MailClient() {
}
```
```js Letter.js
```js src/Letter.js
export default function Letter({
letter,
isHighlighted,
Expand Down Expand Up @@ -2476,7 +2476,7 @@ export default function Letter({
}
```
```js data.js
```js src/data.js
export const initialLetters = [{
id: 0,
subject: 'Ready for adventure?',
Expand Down Expand Up @@ -2516,7 +2516,7 @@ Instead of a single selected ID, you might want to hold an array or a [Set](http
<Sandpack>
```js App.js
```js src/App.js
import { useState } from 'react';
import { letters } from './data.js';
import Letter from './Letter.js';
Expand Down Expand Up @@ -2559,7 +2559,7 @@ export default function MailClient() {
}
```
```js Letter.js
```js src/Letter.js
export default function Letter({
letter,
onToggle,
Expand All @@ -2584,7 +2584,7 @@ export default function Letter({
}
```
```js data.js
```js src/data.js
export const letters = [{
id: 0,
subject: 'Ready for adventure?',
Expand Down Expand Up @@ -2615,7 +2615,7 @@ Instead of a single `selectedId`, keep a `selectedIds` *array* in state. For exa
<Sandpack>
```js App.js
```js src/App.js
import { useState } from 'react';
import { letters } from './data.js';
import Letter from './Letter.js';
Expand Down Expand Up @@ -2667,7 +2667,7 @@ export default function MailClient() {
}
```
```js Letter.js
```js src/Letter.js
export default function Letter({
letter,
onToggle,
Expand All @@ -2692,7 +2692,7 @@ export default function Letter({
}
```
```js data.js
```js src/data.js
export const letters = [{
id: 0,
subject: 'Ready for adventure?',
Expand Down Expand Up @@ -2723,7 +2723,7 @@ To fix this, you can hold a [Set](https://developer.mozilla.org/en-US/docs/Web/J
<Sandpack>
```js App.js
```js src/App.js
import { useState } from 'react';
import { letters } from './data.js';
import Letter from './Letter.js';
Expand Down Expand Up @@ -2772,7 +2772,7 @@ export default function MailClient() {
}
```
```js Letter.js
```js src/Letter.js
export default function Letter({
letter,
onToggle,
Expand All @@ -2797,7 +2797,7 @@ export default function Letter({
}
```
```js data.js
```js src/data.js
export const letters = [{
id: 0,
subject: 'Ready for adventure?',
Expand Down
Loading

0 comments on commit bb65ace

Please sign in to comment.