mirror of
https://github.com/hcengineering/platform.git
synced 2025-01-08 21:27:45 +03:00
Load active viewlet (#2994)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
986f130dc2
commit
458ba29ccf
@ -481,7 +481,18 @@ export function makeViewletKey (loc?: Location): string {
|
||||
return 'viewlet' + locationToUrl(loc)
|
||||
}
|
||||
|
||||
export const activeViewlet = writable<Record<string, Ref<Viewlet> | null>>({})
|
||||
function getSavedViewlets (): Record<string, Ref<Viewlet> | null> {
|
||||
const res: Record<string, Ref<Viewlet> | null> = {}
|
||||
const keys = Object.keys(localStorage)
|
||||
for (const key of keys) {
|
||||
if (!key.startsWith('viewlet')) continue
|
||||
const item = localStorage.getItem(key) as Ref<Viewlet> | null
|
||||
res[key] = item
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
export const activeViewlet = writable<Record<string, Ref<Viewlet> | null>>(getSavedViewlets())
|
||||
|
||||
export function setActiveViewletId (viewletId: Ref<Viewlet> | null, loc?: Location): void {
|
||||
const key = makeViewletKey(loc)
|
||||
|
@ -88,8 +88,15 @@
|
||||
})
|
||||
)
|
||||
|
||||
$: {
|
||||
const newViewlet = viewlets.find((viewlet) => viewlet?._id === $activeViewlet[key]) ?? viewlets[0]
|
||||
$: getActiveViewlet(viewlets, $activeViewlet, key)
|
||||
|
||||
function getActiveViewlet (
|
||||
viewlets: WithLookup<Viewlet>[],
|
||||
activeViewlet: Record<string, Ref<Viewlet> | null>,
|
||||
key: string
|
||||
) {
|
||||
if (viewlets.length === 0) return
|
||||
const newViewlet = viewlets.find((viewlet) => viewlet?._id === activeViewlet[key]) ?? viewlets[0]
|
||||
if (viewlet?._id !== newViewlet?._id) {
|
||||
preference = undefined
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user