From 28a50dd46e29721d2e6697917d7b05d99879cb6f Mon Sep 17 00:00:00 2001 From: vcoppe Date: Fri, 3 May 2024 16:19:11 +0200 Subject: [PATCH] fix typings --- website/src/lib/components/FileListItem.svelte | 3 ++- .../toolbar/tools/routing/RoutingControls.ts | 3 ++- website/src/lib/db.ts | 14 ++++++++------ website/src/lib/stores.ts | 3 ++- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/website/src/lib/components/FileListItem.svelte b/website/src/lib/components/FileListItem.svelte index cde4ecd2..63c7864c 100644 --- a/website/src/lib/components/FileListItem.svelte +++ b/website/src/lib/components/FileListItem.svelte @@ -10,8 +10,9 @@ import { _ } from 'svelte-i18n'; import type { GPXFile } from 'gpx'; + import type { FreezedObject } from 'structurajs'; - export let file: Readable; + export let file: Readable | undefined>; diff --git a/website/src/lib/components/toolbar/tools/routing/RoutingControls.ts b/website/src/lib/components/toolbar/tools/routing/RoutingControls.ts index ce764e4b..31834675 100644 --- a/website/src/lib/components/toolbar/tools/routing/RoutingControls.ts +++ b/website/src/lib/components/toolbar/tools/routing/RoutingControls.ts @@ -8,11 +8,12 @@ import { toast } from "svelte-sonner"; import { _ } from "svelte-i18n"; import { dbUtils } from "$lib/db"; +import type { FreezedObject } from "structurajs"; export class RoutingControls { map: mapboxgl.Map; fileId: string = ''; - file: Readable; + file: Readable | undefined>; anchors: AnchorWithMarker[] = []; shownAnchors: AnchorWithMarker[] = []; popup: mapboxgl.Popup; diff --git a/website/src/lib/db.ts b/website/src/lib/db.ts index 35365a30..bbbcf2a8 100644 --- a/website/src/lib/db.ts +++ b/website/src/lib/db.ts @@ -1,6 +1,6 @@ import Dexie, { liveQuery } from 'dexie'; import { GPXFile } from 'gpx'; -import { type FreezedObject, type Patch, produceWithPatches, applyPatches } from 'structurajs'; +import { type FreezedObject, type Patch, produceWithPatches, applyPatches, freeze } from 'structurajs'; import { writable, get, derived, type Readable, type Writable } from 'svelte/store'; import { fileOrder, selectedFiles } from './stores'; @@ -27,17 +27,19 @@ class Database extends Dexie { const db = new Database(); -function dexieFileStore(querier: () => FreezedObject | undefined | Promise | undefined>): Readable { - let store = writable(undefined); +function dexieFileStore(querier: () => FreezedObject | undefined | Promise | undefined>): Writable> { + let store = writable>(undefined); liveQuery(querier).subscribe(value => { if (value !== undefined) { - let gpx = new GPXFile(value); + let gpx = freeze(new GPXFile(value)); fileState.set(gpx._data.id, gpx); store.set(gpx); } }); return { subscribe: store.subscribe, + update: store.update, + set: store.set }; } @@ -83,8 +85,8 @@ function commitFileStateChange(newFileState: ReadonlyMap>> = writable(new Map()); -const fileState: Map = new Map(); // Used to generate patches +export const fileObservers: Writable | undefined>>> = writable(new Map()); +const fileState: Map> = new Map(); // Used to generate patches liveQuery(() => db.fileids.toArray()).subscribe(dbFileIds => { // Find new files to observe diff --git a/website/src/lib/stores.ts b/website/src/lib/stores.ts index ed7c4154..528c24fa 100644 --- a/website/src/lib/stores.ts +++ b/website/src/lib/stores.ts @@ -6,6 +6,7 @@ import { tick } from 'svelte'; import { _ } from 'svelte-i18n'; import type { GPXLayer } from '$lib/components/gpx-layer/GPXLayer'; import { dbUtils, fileObservers } from './db'; +import type { FreezedObject } from 'structurajs'; export const map = writable(null); @@ -192,7 +193,7 @@ export function exportAllFiles() { }); } -export function exportFile(file: GPXFile) { +export function exportFile(file: FreezedObject) { let blob = new Blob([buildGPX(file)], { type: 'application/gpx+xml' }); let url = URL.createObjectURL(blob); let a = document.createElement('a');