Skip to content

Commit

Permalink
fix: Ensure the 'Solve' button in the tutorial works (#1171)
Browse files Browse the repository at this point in the history
* fix: Ensure the 'Solve' button in the tutorial works

* refactor: Simpler query param
  • Loading branch information
rschristian authored Jul 24, 2024
1 parent 932e9ce commit 58a8669
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/components/controllers/tutorial/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
useMemo,
useCallback
} from 'preact/hooks';
import { useRoute } from 'preact-iso';
import { useLocation, useRoute } from 'preact-iso';
import { TutorialContext, SolutionContext } from './contexts';
import { ErrorOverlay } from '../repl/error-overlay';
import { parseStackTrace } from '../repl/errors';
Expand Down Expand Up @@ -45,7 +45,7 @@ let resultCleanups, realmCleanups;
* @param {{ html: string, meta: TutorialMeta }} props
*/
export function Tutorial({ html, meta }) {
const { path } = useRoute();
const { route, url } = useLocation();
const [editorCode, setEditorCode] = useState(meta.tutorial?.initial || '');
const [runnerCode, setRunnerCode] = useState(editorCode);
const [error, setError] = useState(null);
Expand Down Expand Up @@ -135,7 +135,12 @@ export function Tutorial({ html, meta }) {
});
};

const help = () => meta.tutorial?.final && setEditorCode(meta.tutorial?.final);
const help = () => {
if (meta.tutorial?.final) {
route(`${url}?solved`, true);
setEditorCode(meta.tutorial?.final);
}
};

return (
<TutorialContext.Provider value={this}>
Expand Down Expand Up @@ -188,7 +193,7 @@ export function Tutorial({ html, meta }) {
class={style.code}
value={editorCode}
error={error}
slug={path}
slug={url}
onInput={setEditorCode}
/>
</div>
Expand Down Expand Up @@ -217,7 +222,7 @@ export function Tutorial({ html, meta }) {
</Splitter>

<InjectPrerenderData
name={path}
name={url}
data={{ html, meta }}
/>
</div>
Expand Down

0 comments on commit 58a8669

Please sign in to comment.