Skip to content

Commit

Permalink
Skip loading scheme data by a URL param
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Jun 6, 2024
1 parent a118079 commit acc0bab
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/lib/browse/LoadRemoteSchemeData.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<script lang="ts">
import { SecondaryButton } from "govuk-svelte";
import { fetchWithProgress, privateResourceBaseUrl } from "lib/common";
// means setProgress may get percentages over 100.
import { onMount } from "svelte";
export let loadFile: (text: string) => void;
let shouldLoad = !new URLSearchParams(window.location.search).has(
"disable_schemes",
);
let loading = true;
let progress = 0;
onMount(async () => {
async function loadData() {
let bytes = await fetchWithProgress(
`${privateResourceBaseUrl()}/v1/all_schemes_output.geojson.gz`,
(p) => {
Expand All @@ -19,10 +23,25 @@
let text = new TextDecoder().decode(bytes);
loadFile(text);
loading = false;
}
onMount(async () => {
if (shouldLoad) {
await loadData();
}
});
async function loadDataManually() {
shouldLoad = true;
await loadData();
}
</script>

{#if loading}
{#if !shouldLoad}
<SecondaryButton on:click={loadDataManually}>
Load latest scheme data
</SecondaryButton>
{:else if loading}
{#if progress <= 100}
<label>
Downloading scheme data
Expand Down

0 comments on commit acc0bab

Please sign in to comment.