|
107 | 107 | return destroy;
|
108 | 108 | });
|
109 | 109 |
|
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 | + }); |
111 | 141 |
|
112 | 142 | /**
|
113 | 143 | * Loads the adapter initially or resets it. This method can throw.
|
|
155 | 185 | }, 10000);
|
156 | 186 | });
|
157 | 187 |
|
158 |
| - if (reload_iframe || iframe.src !== adapter.base + data.exercise.path) { |
| 188 | + if (reload_iframe) { |
159 | 189 | await new Promise((fulfil) => setTimeout(fulfil, 200));
|
160 |
| - set_iframe_src(adapter.base + data.exercise.path); |
| 190 | + set_iframe_src(adapter.base + path); |
161 | 191 | }
|
162 | 192 |
|
163 | 193 | return adapter;
|
164 | 194 | }
|
165 | 195 |
|
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 |
| -
|
192 | 196 | /**
|
193 | 197 | * @param {CustomEvent<import('$lib/types').FileStub>} event
|
194 | 198 | */
|
|
418 | 422 | {/if}
|
419 | 423 |
|
420 | 424 | {#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} /> |
431 | 426 | {/if}
|
432 | 427 | </div>
|
433 | 428 | </section>
|
|
0 commit comments