create new file

This commit is contained in:
vcoppe
2024-04-27 12:18:40 +02:00
parent 0eb9c7b57e
commit ccc26f79e7
7 changed files with 67 additions and 20 deletions

View File

@@ -2,6 +2,8 @@ import { writable, get, type Writable } from 'svelte/store';
import mapboxgl from 'mapbox-gl';
import { GPXFile, buildGPX, parseGPX, type AnyGPXTreeElement } from 'gpx';
import { tick } from 'svelte';
import { _ } from 'svelte-i18n';
export const map = writable<mapboxgl.Map | null>(null);
export const files = writable<Writable<GPXFile>[]>([]);
@@ -72,6 +74,15 @@ export function addFile(file: GPXFile): Writable<GPXFile> {
return fileStore;
}
export function createFile(): Writable<GPXFile> {
let file = new GPXFile();
file.metadata.name = get(_)("menu.new_filename");
let fileStore = addFile(file);
tick().then(() => get(selectFiles).select(file));
currentTool.set(Tool.ROUTING);
return fileStore;
}
export function triggerFileInput() {
const input = document.createElement('input');
input.type = 'file';