Skip to content

Commit ca0b912

Browse files
authored
preserve URL when resetting (sveltejs#138)
* dont reset path - closes sveltejs#118 * oops
1 parent 1ce6546 commit ca0b912

File tree

1 file changed

+34
-39
lines changed

1 file changed

+34
-39
lines changed

src/routes/tutorial/[slug]/+page.svelte

+34-39
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,37 @@
107107
return destroy;
108108
});
109109
110-
afterNavigate(load_exercise);
110+
afterNavigate(async () => {
111+
try {
112+
$files = Object.values(data.exercise.a);
113+
$scope = data.exercise.scope;
114+
115+
selected.set(
116+
/** @type {import('$lib/types').FileStub} */ (
117+
$files.find((stub) => stub.name === data.exercise.focus)
118+
)
119+
);
120+
121+
clearTimeout(timeout);
122+
loading = true;
123+
124+
reset_complete_states();
125+
126+
await reset_adapter($files);
127+
128+
if (adapter && path !== data.exercise.path) {
129+
path = data.exercise.path;
130+
set_iframe_src(adapter.base + path);
131+
}
132+
133+
loading = false;
134+
initial = false;
135+
} catch (e) {
136+
loading = false;
137+
error = /** @type {Error} */ (e);
138+
console.error(e);
139+
}
140+
});
111141
112142
/**
113143
* Loads the adapter initially or resets it. This method can throw.
@@ -155,40 +185,14 @@
155185
}, 10000);
156186
});
157187
158-
if (reload_iframe || iframe.src !== adapter.base + data.exercise.path) {
188+
if (reload_iframe) {
159189
await new Promise((fulfil) => setTimeout(fulfil, 200));
160-
set_iframe_src(adapter.base + data.exercise.path);
190+
set_iframe_src(adapter.base + path);
161191
}
162192
163193
return adapter;
164194
}
165195
166-
async function load_exercise() {
167-
try {
168-
$files = Object.values(data.exercise.a);
169-
$scope = data.exercise.scope;
170-
selected.set(
171-
/** @type {import('$lib/types').FileStub} */ (
172-
$files.find((stub) => stub.name === data.exercise.focus)
173-
)
174-
);
175-
176-
clearTimeout(timeout);
177-
loading = true;
178-
179-
reset_complete_states();
180-
181-
await reset_adapter($files);
182-
183-
loading = false;
184-
initial = false;
185-
} catch (e) {
186-
loading = false;
187-
error = /** @type {Error} */ (e);
188-
console.error(e);
189-
}
190-
}
191-
192196
/**
193197
* @param {CustomEvent<import('$lib/types').FileStub>} event
194198
*/
@@ -418,16 +422,7 @@
418422
{/if}
419423
420424
{#if loading || error}
421-
<Loading
422-
{initial}
423-
{error}
424-
{progress}
425-
{status}
426-
on:reload={async () => {
427-
error = null;
428-
load_exercise();
429-
}}
430-
/>
425+
<Loading {initial} {error} {progress} {status} />
431426
{/if}
432427
</div>
433428
</section>

0 commit comments

Comments
 (0)