Skip to content

Commit 1270293

Browse files
authored
Optimize SpacesDropdownMenuItem client side props (#2373)
1 parent 6ce57bc commit 1270293

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/components/Header/SpacesDropdown.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ export function SpacesDropdown(props: { space: Space; spaces: Space[] }) {
3333
{spaces.map((otherSpace, index) => (
3434
<SpacesDropdownMenuItem
3535
key={`${otherSpace.id}-${index}`}
36-
currentSpace={space}
37-
variantSpace={otherSpace}
36+
variantSpace={{
37+
id: otherSpace.id,
38+
title: otherSpace.title,
39+
url: otherSpace.urls.published ?? otherSpace.urls.app,
40+
}}
41+
active={otherSpace.id === space.id}
3842
/>
3943
))}
4044
</DropdownMenu>

src/components/Header/SpacesDropdownMenuItem.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,24 @@ import { useSelectedLayoutSegment } from 'next/navigation';
55

66
import { DropdownMenuItem } from './Dropdown';
77

8-
function useVariantSpaceHref(variantSpace: Space) {
8+
function useVariantSpaceHref(variantSpaceUrl: string) {
99
const currentPathname = useSelectedLayoutSegment() ?? '';
10-
const targetUrl = new URL(variantSpace.urls.published ?? variantSpace.urls.app);
10+
const targetUrl = new URL(variantSpaceUrl);
1111
targetUrl.pathname += `/${currentPathname}`;
1212
targetUrl.pathname = targetUrl.pathname.replace(/\/{2,}/g, '/').replace(/\/$/, '');
1313

1414
return targetUrl.toString();
1515
}
1616

17-
export function SpacesDropdownMenuItem(props: { variantSpace: Space; currentSpace: Space }) {
18-
const { variantSpace, currentSpace } = props;
19-
const variantHref = useVariantSpaceHref(variantSpace);
17+
export function SpacesDropdownMenuItem(props: {
18+
variantSpace: { id: Space['id']; title: Space['title']; url: string };
19+
active: boolean;
20+
}) {
21+
const { variantSpace, active } = props;
22+
const variantHref = useVariantSpaceHref(variantSpace.url);
2023

2124
return (
22-
<DropdownMenuItem
23-
key={variantSpace.id}
24-
href={variantHref}
25-
active={variantSpace.id === currentSpace.id}
26-
>
25+
<DropdownMenuItem key={variantSpace.id} href={variantHref} active={active}>
2726
{variantSpace.title}
2827
</DropdownMenuItem>
2928
);

0 commit comments

Comments
 (0)