From fe3ec5629e3a3a9aec2dff929bffdcfa5ebf74a8 Mon Sep 17 00:00:00 2001 From: Chris Jordan Date: Mon, 21 Oct 2024 23:45:19 -0400 Subject: [PATCH] added ability to upgrade state in UrlHashBinding.updateFromUrlHash for backwards compatibilty --- src/ui/default_viewer_setup.ts | 14 +++++++++++++- src/ui/url_hash_binding.ts | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/ui/default_viewer_setup.ts b/src/ui/default_viewer_setup.ts index 405113b63..41022f05b 100644 --- a/src/ui/default_viewer_setup.ts +++ b/src/ui/default_viewer_setup.ts @@ -161,7 +161,19 @@ export function setupDefaultViewer() { hashBinding.parseError; }), ); - hashBinding.updateFromUrlHash(); + hashBinding.updateFromUrlHash((state) => { + // convert graphene state timestamp to layer timestamp + if (state.layers) { + state.layers.map((layer: any) => { + if (layer.source?.state?.timestamp) { + layer.timestamp = layer.source.state.timestamp; + layer.source.state.timestamp = undefined; + } + }); + } + + return state; + }); viewer.registerDisposer(bindTitle(viewer.title)); bindDefaultCopyHandler(viewer); diff --git a/src/ui/url_hash_binding.ts b/src/ui/url_hash_binding.ts index 5c338cb5e..ef09b27c3 100644 --- a/src/ui/url_hash_binding.ts +++ b/src/ui/url_hash_binding.ts @@ -113,7 +113,7 @@ export class UrlHashBinding extends RefCounted { * Sets the current state to match the URL hash. If it is desired to initialize the state based * on the URL hash, then this should be called immediately after construction. */ - updateFromUrlHash() { + updateFromUrlHash(upgradeState: (a: any) => any = (x) => x) { try { let s = location.href.replace(/^[^#]+/, ""); if (s === "" || s === "#" || s === "#!") { @@ -160,7 +160,7 @@ export class UrlHashBinding extends RefCounted { this.root.reset(); const state = urlSafeParse(s); verifyObject(state); - this.root.restoreState(state); + this.root.restoreState(upgradeState(state)); } else { throw new Error( `URL hash is expected to be of the form "#!{...}" or "#!+{...}".`,