From d4b9353d29a7e0cdc6ac53d0257603d63a078a2c Mon Sep 17 00:00:00 2001 From: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> Date: Mon, 6 Jun 2022 21:49:00 +0600 Subject: [PATCH] Remember last page (#2014) igned-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> --- packages/ui/src/components/internal/Root.svelte | 15 ++++++++++----- packages/ui/src/location.ts | 1 + .../src/components/Workbench.svelte | 15 +++++++++++++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/packages/ui/src/components/internal/Root.svelte b/packages/ui/src/components/internal/Root.svelte index f3aa8e7202..23df7fd73d 100644 --- a/packages/ui/src/components/internal/Root.svelte +++ b/packages/ui/src/components/internal/Root.svelte @@ -27,11 +27,16 @@ } if (application === undefined) { - application = getMetadata(uiPlugin.metadata.DefaultApplication) - if (application !== undefined) { - const loc = getCurrentLocation() - loc.path = [application] - navigate(loc) + const last = localStorage.getItem('platform_last_loc') + if (last !== null) { + navigate(JSON.parse(last)) + } else { + application = getMetadata(uiPlugin.metadata.DefaultApplication) + if (application !== undefined) { + const loc = getCurrentLocation() + loc.path = [application] + navigate(loc) + } } } }) diff --git a/packages/ui/src/location.ts b/packages/ui/src/location.ts index 99b490c220..f702186c68 100644 --- a/packages/ui/src/location.ts +++ b/packages/ui/src/location.ts @@ -113,6 +113,7 @@ export function navigate (location: PlatformLocation): void { const url = locationToUrl(location) if (locationToUrl(getCurrentLocation()) !== url) { history.pushState(null, '', url) + localStorage.setItem('platform_last_loc', JSON.stringify(location)) locationWritable.set(location) } } diff --git a/plugins/workbench-resources/src/components/Workbench.svelte b/plugins/workbench-resources/src/components/Workbench.svelte index cd4cac9399..7f7982a3aa 100644 --- a/plugins/workbench-resources/src/components/Workbench.svelte +++ b/plugins/workbench-resources/src/components/Workbench.svelte @@ -130,12 +130,20 @@ async function syncLoc (loc: Location): Promise { const app = loc.path.length > 0 ? (loc.path[1] as Ref) : undefined - const space = loc.path.length > 1 ? (loc.path[2] as Ref) : undefined - const special = loc.path.length > 2 ? loc.path[3] : undefined + let space = loc.path.length > 1 ? (loc.path[2] as Ref) : undefined + let special = loc.path.length > 2 ? loc.path[3] : undefined if (currentApp !== app) { clear(1) currentApp = app + if (space === undefined) { + const last = localStorage.getItem(`platform_last_loc_${currentApp}`) + if (last !== null) { + const newLocation: Location = JSON.parse(last) + loc.path[2] = space = newLocation.path[2] as Ref + loc.path[3] = special = newLocation.path[3] + } + } currentApplication = await client.findOne(workbench.class.Application, { _id: currentApp }) navigatorModel = currentApplication?.navigatorModel } @@ -151,6 +159,9 @@ setSpaceSpecial(special) } } + if (app !== undefined) { + localStorage.setItem(`platform_last_loc_${currentApp}`, JSON.stringify(loc)) + } } function clear (level: number): void {