From d800ff5540724140d094126c9d3bb0594b0b1b36 Mon Sep 17 00:00:00 2001 From: vcoppe Date: Thu, 18 Apr 2024 10:55:55 +0200 Subject: [PATCH] restructure --- website/src/lib/components/Menu.svelte | 20 ++++++++-- website/src/lib/components/tools/Load.svelte | 10 ----- website/src/lib/components/tools/tools.ts | 38 ------------------- website/src/lib/stores.ts | 39 +++++++++++++++++++- website/src/routes/+page.svelte | 2 +- 5 files changed, 55 insertions(+), 54 deletions(-) delete mode 100644 website/src/lib/components/tools/Load.svelte delete mode 100644 website/src/lib/components/tools/tools.ts diff --git a/website/src/lib/components/Menu.svelte b/website/src/lib/components/Menu.svelte index 101a207a..48efda4a 100644 --- a/website/src/lib/components/Menu.svelte +++ b/website/src/lib/components/Menu.svelte @@ -2,10 +2,20 @@ import * as Menubar from '$lib/components/ui/menubar/index.js'; import { Button } from '$lib/components/ui/button'; import Logo from './Logo.svelte'; - import { Plus, Copy, Download, Undo2, Redo2, Trash2, HeartHandshake } from 'lucide-svelte'; + import { + Plus, + Copy, + Download, + Undo2, + Redo2, + Trash2, + HeartHandshake, + Upload + } from 'lucide-svelte'; import Fa from 'svelte-fa'; import { faGoogleDrive } from '@fortawesome/free-brands-svg-icons'; - import Load from '$lib/components/tools/Load.svelte'; + + import { triggerFileInput } from '$lib/stores'; let distanceUnits = 'metric'; let velocityUnits = 'speed'; @@ -25,7 +35,11 @@ New ⌘N - + + Load from desktop... ⌘O + Load from Google Drive... - import * as Menubar from '$lib/components/ui/menubar/index.js'; - import { Upload } from 'lucide-svelte'; - - import { triggerFileInput } from '$lib/components/tools/tools'; - - - - Load from desktop... ⌘O - diff --git a/website/src/lib/components/tools/tools.ts b/website/src/lib/components/tools/tools.ts deleted file mode 100644 index c9917223..00000000 --- a/website/src/lib/components/tools/tools.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { files } from '$lib/stores'; - -import { parseGPX } from 'gpx'; - -export function triggerFileInput() { - const input = document.createElement('input'); - input.type = 'file'; - input.accept = '.gpx'; - input.multiple = true; - input.className = 'hidden'; - input.onchange = () => { - if (input.files) { - loadFiles(input.files); - } - }; - input.click(); -} - -export function loadFiles(files: FileList) { - for (let i = 0; i < files.length; i++) { - loadFile(files[i]); - } -} - -export function loadFile(file: File) { - const reader = new FileReader(); - reader.onload = () => { - let data = reader.result?.toString() ?? null; - if (data) { - let gpx = parseGPX(data); - if (gpx.metadata.name === undefined) { - gpx.metadata['name'] = file.name.split('.').slice(0, -1).join('.'); - } - files.update($files => [...$files, gpx]); - } - }; - reader.readAsText(file); -} \ No newline at end of file diff --git a/website/src/lib/stores.ts b/website/src/lib/stores.ts index 6ac32010..1c67b93d 100644 --- a/website/src/lib/stores.ts +++ b/website/src/lib/stores.ts @@ -1,7 +1,42 @@ import { writable } from 'svelte/store'; import mapboxgl from 'mapbox-gl'; -import { GPXFile } from 'gpx'; +import { GPXFile, parseGPX } from 'gpx'; export const map = writable(null); -export const files = writable([]); \ No newline at end of file +export const files = writable([]); + +export function triggerFileInput() { + const input = document.createElement('input'); + input.type = 'file'; + input.accept = '.gpx'; + input.multiple = true; + input.className = 'hidden'; + input.onchange = () => { + if (input.files) { + loadFiles(input.files); + } + }; + input.click(); +} + +export function loadFiles(files: FileList) { + for (let i = 0; i < files.length; i++) { + loadFile(files[i]); + } +} + +export function loadFile(file: File) { + const reader = new FileReader(); + reader.onload = () => { + let data = reader.result?.toString() ?? null; + if (data) { + let gpx = parseGPX(data); + if (gpx.metadata.name === undefined) { + gpx.metadata['name'] = file.name.split('.').slice(0, -1).join('.'); + } + files.update($files => [...$files, gpx]); + } + }; + reader.readAsText(file); +} \ No newline at end of file diff --git a/website/src/routes/+page.svelte b/website/src/routes/+page.svelte index bf61aef1..d25d0713 100644 --- a/website/src/routes/+page.svelte +++ b/website/src/routes/+page.svelte @@ -6,7 +6,7 @@ import Toolbar from '$lib/components/Toolbar.svelte'; import LayerControl from '$lib/components/layer-control/LayerControl.svelte'; - import { triggerFileInput } from '$lib/components/tools/tools'; + import { triggerFileInput } from '$lib/stores';