1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-17 13:46:47 +02:00
unleash.unleash/frontend/src/component/commandBar/RecentlyVisitedRecorder.tsx
Jaanus Sellin 3f76882465
fix: recently visit should only use main paths (#7655)
Recently visited should only be main paths, so look like this
**/segments** **/projects** and not have multiple slashes inside.
2024-07-24 15:04:33 +03:00

35 lines
1.2 KiB
TypeScript

import { useRecentlyVisited } from 'hooks/useRecentlyVisited';
import { useLocation, useMatch } from 'react-router-dom';
import { routes } from 'component/menu/routes';
import { useEffect } from 'react';
export const RecentlyVisitedRecorder = () => {
const { setLastVisited } = useRecentlyVisited();
const featureMatch = useMatch('/projects/:projectId/features/:featureId');
const projectMatch = useMatch('/projects/:projectId');
const location = useLocation();
useEffect(() => {
if (!location.pathname) return;
const path = routes.find(
(r) =>
r.path === location.pathname && r.path.indexOf('/', 1) === -1,
);
if (path) {
setLastVisited({ pathName: path.path });
} else if (featureMatch?.params.featureId) {
setLastVisited({
featureId: featureMatch?.params.featureId,
projectId: featureMatch?.params.projectId,
});
} else if (projectMatch?.params.projectId) {
setLastVisited({
projectId: projectMatch?.params.projectId,
});
}
}, [location, featureMatch, projectMatch]);
return <></>;
};