From c71dad6c371e5b507a3aeec066ab30747fe6c633 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Mon, 15 Apr 2024 18:58:51 +0200 Subject: [PATCH] dumb spotlight down --- src/frontend/src/components/nav/Layout.tsx | 23 +++++++++++++++++++-- src/frontend/src/pages/Index/Playground.tsx | 7 ++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/frontend/src/components/nav/Layout.tsx b/src/frontend/src/components/nav/Layout.tsx index 96827dcf14..bdff94470f 100644 --- a/src/frontend/src/components/nav/Layout.tsx +++ b/src/frontend/src/components/nav/Layout.tsx @@ -2,6 +2,7 @@ import { t } from '@lingui/macro'; import { Container, Flex, Space } from '@mantine/core'; import { Spotlight, createSpotlight } from '@mantine/spotlight'; import { IconSearch } from '@tabler/icons-react'; +import { useEffect, useState } from 'react'; import { Navigate, Outlet, useLocation, useNavigate } from 'react-router-dom'; import { getActions } from '../../defaults/actions'; @@ -28,7 +29,26 @@ export const [firstStore, firstSpotlight] = createSpotlight(); export default function LayoutComponent() { const navigate = useNavigate(); + const location = useLocation(); + const defaultactions = getActions(navigate); + const [actions, setActions] = useState(defaultactions); + const [customActions, setCustomActions] = useState(false); + + function actionsAreChanging(change: any) { + if (change.registeredActions.length > defaultactions.length) + setCustomActions(true); + setActions(change); + } + // firstStore.subscribe(actionsAreChanging); + + // clear additional actions on location change + useEffect(() => { + if (customActions) { + setActions(defaultactions); + setCustomActions(false); + } + }, [location]); return ( @@ -40,9 +60,8 @@ export default function LayoutComponent() {