Skip to content

Commit

Permalink
Add error messages elsewhere, npm format
Browse files Browse the repository at this point in the history
  • Loading branch information
Pete-Y-CS committed Jul 14, 2023
1 parent 23a7adb commit a25717a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/lib/sidebar/EntireScheme.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
import type { Schema, Scheme } from "../../types";
import ConfirmationModal from "../common/ConfirmationModal.svelte";
import FileInput from "../common/FileInput.svelte";
import ErrorMessage from "../govuk/ErrorMessage.svelte";
export let authorityName: string;
export let schema: Schema;
let errorMessage = "";
let baseFilename = authorityName;
if (schema != "v1") {
Expand Down Expand Up @@ -123,7 +125,7 @@
// TODO Should we prompt before deleting the current scheme?
gjScheme.set(backfill(JSON.parse(text)));
} catch (err) {
window.alert(`Couldn't load scheme from a file: ${err}`);
errorMessage = `Couldn't load scheme from a file: ${err}`;
}
}
Expand Down Expand Up @@ -163,6 +165,9 @@
<br />

<div>
{#if errorMessage}
<ErrorMessage {errorMessage} />
{/if}
<FileInput
label="Load from GeoJSON"
id="load-geojson"
Expand Down
2 changes: 1 addition & 1 deletion src/pages/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
geojson.features = geojson.features.filter(
(feature) => feature.properties?.name == authorityName
);
if(geojson.features.length === 0) {
if (geojson.features.length === 0) {
window.location.href = `/?error=Authority name not found: ${authorityName}`;
}
return geojson;
Expand Down
7 changes: 6 additions & 1 deletion src/pages/BrowseSchemes.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import Layout from "../lib/common/Layout.svelte";
import MapTooltips from "../lib/common/MapTooltips.svelte";
import InterventionLayer from "../lib/draw/InterventionLayer.svelte";
import ErrorMessage from "../lib/govuk/ErrorMessage.svelte";
import FormElement from "../lib/govuk/FormElement.svelte";
import SecondaryButton from "../lib/govuk/SecondaryButton.svelte";
import Legend from "../lib/Legend.svelte";
Expand All @@ -29,6 +30,7 @@
const params = new URLSearchParams(window.location.search);
let style: string = params.get("style") || "streets";
const schema = "v1";
let errorMessage = "";
interface Scheme {
scheme_reference: string;
Expand Down Expand Up @@ -108,7 +110,7 @@
$map?.fitBounds(bbox(gj), { padding: 20, animate: false });
} catch (err) {
window.alert(`Couldn't load schemes from a file: ${err}`);
errorMessage = `Couldn't load schemes from a file: ${err}`;
}
}
Expand Down Expand Up @@ -180,6 +182,9 @@
<h1>Browse schemes</h1>
<ZoomOutMap boundaryGeojson={$gjScheme} />
</div>
{#if errorMessage}
<ErrorMessage {errorMessage} />
{/if}
<FileInput label="Load from GeoJSON" id="load-geojson" {loadFile} />

<br />
Expand Down
4 changes: 2 additions & 2 deletions src/pages/ChooseArea.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import { initAll } from "govuk-frontend";
import { Map } from "maplibre-gl";
import { onMount } from "svelte";
import ErrorMessage from "../lib/govuk/ErrorMessage.svelte";
import DefaultButton from "../lib/govuk/DefaultButton.svelte";
import ErrorMessage from "../lib/govuk/ErrorMessage.svelte";
import FormElement from "../lib/govuk/FormElement.svelte";
import Radio from "../lib/govuk/Radio.svelte";
import SecondaryButton from "../lib/govuk/SecondaryButton.svelte";
Expand Down Expand Up @@ -131,7 +131,7 @@
window.localStorage.setItem(filename, JSON.stringify(gj));
window.location.href = `scheme.html?authority=${gj.authority}&schema=${schema}`;
} catch (err) {
window.alert(`Couldn't load scheme from a file: ${err}`);
errorMessage = `Couldn't load scheme from a file: ${err}`;
}
}
Expand Down

0 comments on commit a25717a

Please sign in to comment.