Skip to content

Commit eb0c731

Browse files
committed
fix(tutorial): show Reset after loading a solved lesson URL
1 parent e25a29f commit eb0c731

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎src/routes/(_)tutorial/[[id]].tsx‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
Errored,
66
For,
77
Loading,
8+
onSettled,
89
Show,
910
untrack,
1011
} from "solid-js";
@@ -115,6 +116,12 @@ export default function Tutorial() {
115116
// Old solidjs.com lesson ids render their new lesson; the host redirects them.
116117
const id = () => canonicalTutorialId(params.id || firstTutorialId);
117118
const solved = () => new URLSearchParams(location.search).has("solved");
119+
// The page is prerendered without the query, so the button follows it only after hydration.
120+
const [hydrated, setHydrated] = createSignal(false);
121+
onSettled(() => {
122+
setHydrated(true);
123+
});
124+
const showSolved = () => hydrated() && solved();
118125
const index = () =>
119126
tutorialDirectory.findIndex((entry) => entry.internalName === id());
120127
const entryAt = (i: number) => {
@@ -186,9 +193,9 @@ export default function Tutorial() {
186193
>
187194
<a
188195
class="rounded-lg bg-blue-600 px-3 py-1.5 font-semibold text-white hover:bg-blue-700"
189-
href={`/tutorial/${id()}${solved() ? "" : "?solved"}`}
196+
href={`/tutorial/${id()}${showSolved() ? "" : "?solved"}`}
190197
>
191-
{solved() ? "Reset" : "Solve"}
198+
{showSolved() ? "Reset" : "Solve"}
192199
</a>
193200
<div class="flex gap-4">
194201
<Show when={previous()}>

0 commit comments

Comments
 (0)