Skip to content

Commit

Permalink
Clear state when switching areas in the web apps
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Mar 29, 2024
1 parent 14e7c70 commit 37ce811
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
3 changes: 3 additions & 0 deletions web/src/common/import/ImportControls.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
boundaryGj as boundaryGjStore,
map,
network as networkStore,
importCounter,
} from "../store";
import { bbox, downloadGeneratedFile } from "../utils";
import Osm2streetsSettings from "./Osm2streetsSettings.svelte";
Expand Down Expand Up @@ -79,6 +80,7 @@
network,
};
$importCounter++;
networkStore.set(imported.network);
boundaryGjStore.set(imported.boundaryGj);
} catch (err: any) {
Expand Down Expand Up @@ -117,6 +119,7 @@
function resetToNone(e: CustomEvent<void>) {
imported = { kind: "nothing" };
$importCounter++;
networkStore.set(null);
boundaryGjStore.set(null);
}
Expand Down
6 changes: 5 additions & 1 deletion web/src/common/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import type { FeatureWithProps } from "./utils";

// These are all global singleton values, available anywhere in the code. When
// they're non-null, then they're loaded and ready to use.

export const map: Writable<Map | null> = writable(null);
export const network: Writable<JsStreetNetwork | null> = writable(null);

// A way for different components to know when a new area has been imported.
// Modifying the current network doesn't count.
export let importCounter: Writable<number> = writable(1);

export const boundaryGj: Writable<Feature<Polygon> | null> = writable(null);

export const hoveredLane: Writable<FeatureWithProps<Polygon> | null> =
Expand Down
20 changes: 11 additions & 9 deletions web/src/lane-editor/AllEdits.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<script lang="ts">
import { network } from "../common";
import { network, importCounter } from "../common";
import { downloadGeneratedFile } from "../common/utils";
let editedWays: Set<bigint> = new Set();
// Drop edits when changing areas
$: if ($importCounter > 0) {
editedWays = new Set();
}
export function handleEditedWay(e: CustomEvent<bigint>) {
editedWays.add(e.detail);
editedWays = editedWays;
Expand All @@ -14,13 +19,8 @@
contents += `<create/>\n`;
contents += `<modify>\n`;
for (let id of editedWays) {
try {
contents += $network!.wayToXml(id);
contents += "\n";
} catch (err) {
// TODO Not sure why this happens, but just skip this edit
console.error(err);
}
contents += $network!.wayToXml(id);
contents += "\n";
}
contents += `</modify>\n`;
contents += `</osmChange>`;
Expand All @@ -30,4 +30,6 @@
</script>

<div>{editedWays.size} ways edited</div>
<button type="button" on:click={downloadOsc}>Download .osc</button>
<button type="button" on:click={downloadOsc} disabled={editedWays.size == 0}
>Download .osc</button
>
7 changes: 7 additions & 0 deletions web/src/street-explorer/stores.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import type { FeatureCollection } from "geojson";
import { writable, type Writable } from "svelte/store";
import { emptyGeojson } from "../common/utils";
import { network } from "../common";

export const blockGj: Writable<FeatureCollection> = writable(emptyGeojson());

// TODO Need to unsubscribe
// Unset when the network changes
network.subscribe((value) => {
blockGj.set(emptyGeojson());
});

0 comments on commit 37ce811

Please sign in to comment.