Remember viewOptions (#2120)

Signed-off-by: Dvinyanin Alexandr <dvinyanin.alexandr@gmail.com>
This commit is contained in:
Alex
2022-06-22 12:56:56 +07:00
committed by GitHub
parent de99835dc3
commit 0cadc19331
13 changed files with 127 additions and 614 deletions
+3 -1
View File
@@ -82,7 +82,9 @@ export {
getObjectPresenter,
LoadingProps,
setActiveViewletId,
getActiveViewletId
getActiveViewletId,
setViewOptions,
getViewOptions
} from './utils'
export {
HTMLPresenter,
+21
View File
@@ -422,3 +422,24 @@ export function getActiveViewletId (): Ref<Viewlet> | null {
const key = makeViewletKey()
return localStorage.getItem(key) as Ref<Viewlet> | null
}
function makeViewOptionsKey (viewletId: Ref<Viewlet>): string {
const loc = getCurrentLocation()
loc.fragment = undefined
loc.query = undefined
return `viewOptions:${viewletId}:${locationToUrl(loc)}`
}
export function setViewOptions (viewletId: Ref<Viewlet>, options: string | null): void {
const key = makeViewOptionsKey(viewletId)
if (options !== null) {
localStorage.setItem(key, options)
} else {
localStorage.removeItem(key)
}
}
export function getViewOptions (viewletId: Ref<Viewlet>): string | null {
const key = makeViewOptionsKey(viewletId)
return localStorage.getItem(key)
}