Remember last page (#2014)

igned-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com>
This commit is contained in:
Denis Bykhov 2022-06-06 21:49:00 +06:00 committed by GitHub
parent 6137f0df2e
commit d4b9353d29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 7 deletions

View File

@ -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)
}
}
}
})

View File

@ -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)
}
}

View File

@ -130,12 +130,20 @@
async function syncLoc (loc: Location): Promise<void> {
const app = loc.path.length > 0 ? (loc.path[1] as Ref<Application>) : undefined
const space = loc.path.length > 1 ? (loc.path[2] as Ref<Space>) : undefined
const special = loc.path.length > 2 ? loc.path[3] : undefined
let space = loc.path.length > 1 ? (loc.path[2] as Ref<Space>) : 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<Space>
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 {