Skip to content

Commit 4e26063

Browse files
committed
Fix some bugs with area drawing state not getting cleared. #57
1 parent 52cf207 commit 4e26063

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

web/src/SetBoundaryMode.svelte

+8-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import { SplitComponent } from "svelte-utils/top_bar_layout";
88
import { autosave, app, mode, route_tool } from "./stores";
99
import type { AreaProps } from "route-snapper-ts";
10+
import { onDestroy } from "svelte";
1011
1112
export let name: string;
1213
export let existing: Feature<Polygon, AreaProps> | null;
@@ -17,7 +18,13 @@
1718
$route_tool!.startArea();
1819
}
1920
20-
// TODO When we click a link and nav away, clear state
21+
// The user can change the mode in many ways, like clicking a link.
22+
// When this component gets destroyed, always clean up state.
23+
onDestroy(() => {
24+
// If the user is choosing a new area, the tool will get unset
25+
$route_tool?.clearEventListeners();
26+
$route_tool?.stop();
27+
});
2128
2229
function onFailure() {
2330
if (existing) {
@@ -29,7 +36,6 @@
2936
mode: "network",
3037
};
3138
}
32-
$route_tool!.clearEventListeners();
3339
}
3440
3541
$route_tool!.addEventListenerSuccess((feature) => {
@@ -40,7 +46,6 @@
4046
$mode = {
4147
mode: "neighbourhood",
4248
};
43-
$route_tool!.clearEventListeners();
4449
} catch (err) {
4550
window.alert(
4651
"Known georust bug hit, sorry. You may need to just refresh the page now.",

0 commit comments

Comments
 (0)