Skip to content

preserve URL when resetting #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 34 additions & 39 deletions src/routes/tutorial/[slug]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,37 @@
return destroy;
});

afterNavigate(load_exercise);
afterNavigate(async () => {
try {
$files = Object.values(data.exercise.a);
$scope = data.exercise.scope;

selected.set(
/** @type {import('$lib/types').FileStub} */ (
$files.find((stub) => stub.name === data.exercise.focus)
)
);

clearTimeout(timeout);
loading = true;

reset_complete_states();

await reset_adapter($files);

if (adapter && path !== data.exercise.path) {
path = data.exercise.path;
set_iframe_src(adapter.base + path);
}

loading = false;
initial = false;
} catch (e) {
loading = false;
error = /** @type {Error} */ (e);
console.error(e);
}
});

/**
* Loads the adapter initially or resets it. This method can throw.
Expand Down Expand Up @@ -155,40 +185,14 @@
}, 10000);
});

if (reload_iframe || iframe.src !== adapter.base + data.exercise.path) {
if (reload_iframe) {
await new Promise((fulfil) => setTimeout(fulfil, 200));
set_iframe_src(adapter.base + data.exercise.path);
set_iframe_src(adapter.base + path);
}

return adapter;
}

async function load_exercise() {
try {
$files = Object.values(data.exercise.a);
$scope = data.exercise.scope;
selected.set(
/** @type {import('$lib/types').FileStub} */ (
$files.find((stub) => stub.name === data.exercise.focus)
)
);

clearTimeout(timeout);
loading = true;

reset_complete_states();

await reset_adapter($files);

loading = false;
initial = false;
} catch (e) {
loading = false;
error = /** @type {Error} */ (e);
console.error(e);
}
}

/**
* @param {CustomEvent<import('$lib/types').FileStub>} event
*/
Expand Down Expand Up @@ -418,16 +422,7 @@
{/if}

{#if loading || error}
<Loading
{initial}
{error}
{progress}
{status}
on:reload={async () => {
error = null;
load_exercise();
}}
/>
<Loading {initial} {error} {progress} {status} />
{/if}
</div>
</section>
Expand Down