Load active viewlet (#2994)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov
2023-04-16 18:11:40 +07:00
committed by GitHub
parent 986f130dc2
commit 458ba29ccf
2 changed files with 21 additions and 3 deletions
@@ -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
}