Skip to content

Commit

Permalink
Added Client-side processing of JSON Config Files (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowmouse authored Apr 29, 2023
1 parent 87a06a9 commit 4676200
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/components/LoadShip.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
let modalLoadJSON: string;
let modalDelShip: string;
let shipJSON: string;
let fileInput;
const loadJSON = () => {
// strip leading whitespace
Expand All @@ -57,6 +58,14 @@
}
}
const readConfigJson = (e) => {
let file = e.target.files[0];
let reader = new FileReader();
reader.readAsText(file);
reader.onload = (e) => { shipJSON = reader.result.toString(); }
reader.onerror = (e) => { toast.push("Error loading provided file. (Not JSON?)", {}); }
}
let shipID: string;
const loadLocal = () => {
Expand Down Expand Up @@ -166,6 +175,10 @@
<div class="control">
<textarea class="textarea" id="guessTxt" placeholder="Paste JSON or shareable code here" bind:value="{shipJSON}"></textarea>
</div>
<p> Select JSON File </p>
<div class="control">
<input type="file" accept="application/json" class="input" placeholder="Select JSON Ship Config File" bind:this={fileInput} on:change={readConfigJson} on:click={() => { fileInput.value = null; }}/>
</div>
</div>
</section>
<footer class="modal-card-foot">
Expand Down

0 comments on commit 4676200

Please sign in to comment.