Skip to content

Commit

Permalink
Put the project name in the URL and auto-load from that when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Dec 27, 2024
1 parent 748ab79 commit bfb608b
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 14 deletions.
2 changes: 1 addition & 1 deletion web/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
<Geocoder {map} apiKey={maptilerApiKey} />
<div bind:this={mapDiv} />
{#if $mode.mode == "title"}
<TitleMode {wasmReady} />
<TitleMode {wasmReady} firstLoad={$mode.firstLoad} />
{:else if $mode.mode == "new-project"}
<NewProjectMode />
{/if}
Expand Down
2 changes: 1 addition & 1 deletion web/src/AutoBoundariesMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<nav aria-label="breadcrumb">
<ul>
<li>
<Link on:click={() => ($mode = { mode: "title" })}>
<Link on:click={() => ($mode = { mode: "title", firstLoad: false })}>
Choose project
</Link>
</li>
Expand Down
2 changes: 1 addition & 1 deletion web/src/DebugMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<nav aria-label="breadcrumb">
<ul>
<li>
<Link on:click={() => ($mode = { mode: "title" })}>
<Link on:click={() => ($mode = { mode: "title", firstLoad: false })}>
Choose project
</Link>
</li>
Expand Down
2 changes: 1 addition & 1 deletion web/src/ImpactOneDestinationMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<nav aria-label="breadcrumb">
<ul>
<li>
<Link on:click={() => ($mode = { mode: "title" })}>
<Link on:click={() => ($mode = { mode: "title", firstLoad: false })}>
Choose project
</Link>
</li>
Expand Down
2 changes: 1 addition & 1 deletion web/src/NetworkMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<nav aria-label="breadcrumb">
<ul>
<li>
<Link on:click={() => ($mode = { mode: "title" })}>
<Link on:click={() => ($mode = { mode: "title", firstLoad: false })}>
Choose project
</Link>
</li>
Expand Down
2 changes: 1 addition & 1 deletion web/src/RouteMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<nav aria-label="breadcrumb">
<ul>
<li>
<Link on:click={() => ($mode = { mode: "title" })}>
<Link on:click={() => ($mode = { mode: "title", firstLoad: false })}>
Choose project
</Link>
</li>
Expand Down
2 changes: 1 addition & 1 deletion web/src/SetBoundaryMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<nav aria-label="breadcrumb">
<ul>
<li>
<Link on:click={() => ($mode = { mode: "title" })}>
<Link on:click={() => ($mode = { mode: "title", firstLoad: false })}>
Choose project
</Link>
</li>
Expand Down
2 changes: 1 addition & 1 deletion web/src/ViewShortcutsMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<nav aria-label="breadcrumb">
<ul>
<li>
<Link on:click={() => ($mode = { mode: "title" })}>
<Link on:click={() => ($mode = { mode: "title", firstLoad: false })}>
Choose project
</Link>
</li>
Expand Down
2 changes: 1 addition & 1 deletion web/src/edit/NeighbourhoodMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
<nav aria-label="breadcrumb">
<ul>
<li>
<Link on:click={() => ($mode = { mode: "title" })}>
<Link on:click={() => ($mode = { mode: "title", firstLoad: false })}>
Choose project
</Link>
</li>
Expand Down
3 changes: 2 additions & 1 deletion web/src/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const maptilerApiKey = "MZEJTanw3WpxRvt7qDfo";
export type Mode =
| {
mode: "title";
firstLoad: boolean;
}
| {
mode: "new-project";
Expand Down Expand Up @@ -57,7 +58,7 @@ export let mainRoadPenalty: Writable<number> = writable(1.0);
// A way for different components to know when internal app state has changed
// and they might need to rerender
export let mutationCounter: Writable<number> = writable(1);
export let mode: Writable<Mode> = writable({ mode: "title" });
export let mode: Writable<Mode> = writable({ mode: "title", firstLoad: true });
export let filterType: Writable<string> = writable("walk_cycle_only");
export let animateShortcuts = writable(false);
export let editPerimeterRoads = writable(false);
Expand Down
2 changes: 1 addition & 1 deletion web/src/title/NewProjectMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<nav aria-label="breadcrumb">
<ul>
<li>
<Link on:click={() => ($mode = { mode: "title" })}>
<Link on:click={() => ($mode = { mode: "title", firstLoad: false })}>
Choose project
</Link>
</li>
Expand Down
22 changes: 19 additions & 3 deletions web/src/title/TitleMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,29 @@
import { loadFromLocalStorage } from "./loader";
export let wasmReady: boolean;
export let firstLoad: boolean;
let loading = "";
// When other modes reset here, they can't clear state without a race condition
$app = null;
$routeTool = null;
$projectName = "";
{
$app = null;
$routeTool = null;
$projectName = "";
if (firstLoad) {
let params = new URLSearchParams(window.location.search);
let loadProject = params.get("project");
if (loadProject) {
loadFromLocalStorage(loadProject);
}
} else {
// Update the URL
let url = new URL(window.location.href);
url.searchParams.delete("project");
window.history.replaceState(null, "", url.toString());
}
}
let projectList = getProjectList();
Expand Down
5 changes: 5 additions & 0 deletions web/src/title/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ export function afterProjectLoaded() {
route_pt_a.set(randomPoint());
route_pt_b.set(randomPoint());
one_destination.set(randomPoint());

// Update the URL
let url = new URL(window.location.href);
url.searchParams.set("project", get(projectName));
window.history.replaceState(null, "", url.toString());
}

function randomPoint(): LngLat {
Expand Down

0 comments on commit bfb608b

Please sign in to comment.