mirror of
https://github.com/Unleash/unleash.git
synced 2024-10-28 19:06:12 +01:00
parent
ed7f917df6
commit
ed9d0cccbc
@ -83,6 +83,12 @@ const StyledClose = styled(Close)(({ theme }) => ({
|
||||
fontSize: theme.typography.body1.fontSize,
|
||||
}));
|
||||
|
||||
interface IPageRouteInfo {
|
||||
path: string;
|
||||
route: string;
|
||||
title: string;
|
||||
}
|
||||
|
||||
export const CommandBar = () => {
|
||||
const searchInputRef = useRef<HTMLInputElement>(null);
|
||||
const searchContainerRef = useRef<HTMLInputElement>(null);
|
||||
@ -91,12 +97,12 @@ export const CommandBar = () => {
|
||||
const [searchedProjects, setSearchedProjects] = useState<
|
||||
CommandResultGroupItem[]
|
||||
>([]);
|
||||
const [searchedPages, setSearchedPages] = useState<
|
||||
CommandResultGroupItem[]
|
||||
>([]);
|
||||
const { lastVisited } = useRecentlyVisited();
|
||||
const { routes } = useRoutes();
|
||||
const allRoutes: Record<
|
||||
string,
|
||||
{ path: string; route: string; title: string }
|
||||
> = {};
|
||||
const allRoutes: Record<string, IPageRouteInfo> = {};
|
||||
for (const route of [
|
||||
...routes.mainNavRoutes,
|
||||
...routes.adminRoutes,
|
||||
@ -139,6 +145,15 @@ export const CommandBar = () => {
|
||||
}));
|
||||
|
||||
setSearchedProjects(mappedProjects);
|
||||
|
||||
const filteredPages = Object.values(allRoutes).filter((route) =>
|
||||
route.title.toLowerCase().includes(query.toLowerCase()),
|
||||
);
|
||||
const mappedPages = filteredPages.map((page) => ({
|
||||
name: page.title,
|
||||
link: page.path,
|
||||
}));
|
||||
setSearchedPages(mappedPages);
|
||||
}, 200);
|
||||
|
||||
const onSearchChange = (value: string) => {
|
||||
@ -235,6 +250,11 @@ export const CommandBar = () => {
|
||||
icon={'flag'}
|
||||
items={searchedProjects}
|
||||
/>
|
||||
<CommandResultGroup
|
||||
groupName={'Pages'}
|
||||
icon={'flag'}
|
||||
items={searchedPages}
|
||||
/>
|
||||
</CommandResultsPaper>
|
||||
}
|
||||
elseShow={
|
||||
|
Loading…
Reference in New Issue
Block a user