Clean up collectLeaves
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
81cb3d60e4
commit
4204d2ea93
|
@ -288,31 +288,37 @@ function NavItem(props: NavItemProps) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
type Leaves = {
|
interface Leaf {
|
||||||
name: string;
|
name: string;
|
||||||
route: string;
|
route: string;
|
||||||
exact?: boolean;
|
exact?: boolean;
|
||||||
ancestors: { name: string; route: string }[];
|
ancestors: { name: string; route: string }[];
|
||||||
}[];
|
|
||||||
|
|
||||||
function collectLeaves(
|
|
||||||
entry: { name: string; route: string; exact?: boolean; submenu?: Menu },
|
|
||||||
ancestors: { name: string; route: string }[]
|
|
||||||
): Leaves {
|
|
||||||
if (entry.submenu == null) {
|
|
||||||
return [{ ...entry, ancestors }];
|
|
||||||
}
|
|
||||||
const ret = [] as Leaves;
|
|
||||||
for (const subEntry of entry.submenu) {
|
|
||||||
ret.push(...collectLeaves(subEntry, [...ancestors, entry]));
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const leaves: Leaves = menu.reduce((prev, cur) => {
|
function collectLeaves(
|
||||||
prev.push(...collectLeaves(cur, []));
|
accumulator: Leaf[],
|
||||||
return prev;
|
entry: {
|
||||||
}, [] as Leaves);
|
name: string;
|
||||||
|
route: string;
|
||||||
|
exact?: boolean;
|
||||||
|
submenu?: Menu;
|
||||||
|
}
|
||||||
|
): Leaf[] {
|
||||||
|
if (entry.submenu == null) {
|
||||||
|
return [...accumulator, { ...entry, ancestors: [] }];
|
||||||
|
}
|
||||||
|
|
||||||
|
const subleaves = entry.submenu.reduce(collectLeaves, [] as Leaf[]);
|
||||||
|
return [
|
||||||
|
...accumulator,
|
||||||
|
...subleaves.map((leaf) => ({
|
||||||
|
...leaf,
|
||||||
|
ancestors: [...leaf.ancestors, { name: entry.name, route: entry.route }],
|
||||||
|
})),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
const leaves: Leaf[] = menu.reduce(collectLeaves, [] as Leaf[]);
|
||||||
|
|
||||||
function shouldHighlight(
|
function shouldHighlight(
|
||||||
pathname: string,
|
pathname: string,
|
||||||
|
|
|
@ -45,7 +45,11 @@ export function ShapesBackground({ getConfig }: Props) {
|
||||||
}, [getConfig, width, height, prevWidth, prevRoute, router.asPath]);
|
}, [getConfig, width, height, prevWidth, prevRoute, router.asPath]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.shapesContainer} ref={shapesContainerRef}>
|
<div
|
||||||
|
className={styles.shapesContainer}
|
||||||
|
ref={shapesContainerRef}
|
||||||
|
aria-hidden
|
||||||
|
>
|
||||||
{Object.entries(config).map(([type, instances]) =>
|
{Object.entries(config).map(([type, instances]) =>
|
||||||
instances.map((attributes, idx) => (
|
instances.map((attributes, idx) => (
|
||||||
<Shape
|
<Shape
|
||||||
|
|
Loading…
Reference in New Issue