|
3 | 3 | import { Loading } from "svelte-utils";
|
4 | 4 | import { SplitComponent } from "svelte-utils/top_bar_layout";
|
5 | 5 | import CntChooseArea from "../CntChooseArea.svelte";
|
6 |
| - import { Link, stripPrefix, stripSuffix } from "../common"; |
| 6 | + import { Link } from "../common"; |
7 | 7 | import { routeTool } from "../common/draw_area/stores";
|
8 | 8 | import { appFocus, backend, currentProjectKey, map, mode } from "../stores";
|
9 | 9 | import { loadFromLocalStorage } from "./loader";
|
| 10 | + import LoadSavedProject from "./LoadSavedProject.svelte"; |
10 | 11 |
|
11 | 12 | export let wasmReady: boolean;
|
12 | 13 | export let firstLoad: boolean;
|
|
68 | 69 | return out;
|
69 | 70 | }
|
70 | 71 |
|
71 |
| - let fileInput: HTMLInputElement; |
72 |
| - async function loadFile(e: Event) { |
73 |
| - let filename = fileInput.files![0].name; |
74 |
| - loading = `Loading from file ${filename}`; |
75 |
| -
|
76 |
| - let contents = await fileInput.files![0].text(); |
77 |
| - let gj = JSON.parse(contents); |
78 |
| - // Is this a CNT project or a regular one? |
79 |
| - let key = ""; |
80 |
| - if (gj.study_area_name && gj.study_area_name.startsWith("LAD_")) { |
81 |
| - let kind = "ltn_cnt"; |
82 |
| - // Parse the project name from the filename, best effort. The user may |
83 |
| - // have renamed the file. |
84 |
| - let projectName = stripSuffix( |
85 |
| - stripPrefix(filename, `${kind}_${gj.study_area_name}_`), |
86 |
| - ".geojson", |
87 |
| - ); |
88 |
| - key = `${kind}/${gj.study_area_name}/${projectName}`; |
89 |
| - } else { |
90 |
| - let projectName = stripSuffix(stripPrefix(filename, "ltn_"), ".geojson"); |
91 |
| - key = `ltn_${projectName}`; |
92 |
| - } |
93 |
| - // TODO Be careful with overwriting files |
94 |
| - window.localStorage.setItem(key, contents); |
95 |
| - projectList = getProjectList(); |
96 |
| - await loadFromLocalStorage(key); |
97 |
| - loading = ""; |
98 |
| - } |
99 |
| -
|
100 | 72 | function deleteProject(key: string) {
|
101 | 73 | if (window.confirm(`Really delete project ${key}? You can't undo this.`)) {
|
102 | 74 | window.localStorage.removeItem(key);
|
|
177 | 149 | {/each}
|
178 | 150 | </ul>
|
179 | 151 |
|
180 |
| - <label> |
181 |
| - Load a project from a file |
182 |
| - <input bind:this={fileInput} on:change={loadFile} type="file" /> |
183 |
| - </label> |
| 152 | + <LoadSavedProject bind:loading /> |
184 | 153 | {:else if $appFocus == "cnt"}
|
185 | 154 | <CntChooseArea {loadProject} bind:activityIndicatorText={loading} />
|
186 | 155 | {/if}
|
|
0 commit comments