Skip to content

Commit 33198a0

Browse files
m-hulbertclaude
andcommitted
refactor(nav): extract hasProductBar to layout context and simplify hooks
Extract the duplicated `product !== null && product !== 'platform'` check into `activePage.hasProductBar` computed once in the layout context, replacing three identical copies in Layout, LeftSidebar, and RightSidebar. Simplify useShowLanguageSelector double negation (!every(!includes)) to the equivalent some(includes). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 43e48d8 commit 33198a0

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

src/components/Layout/hooks/useShowLanguageSelector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export const useShowLanguageSelector = () => {
1010
() =>
1111
activePage.isDualLanguage ||
1212
(activePage.languages.length > 0 &&
13-
!activePage.languages.every(
14-
(language) => !Object.keys(languageData[activePage.product as ProductKey] ?? {}).includes(language),
13+
activePage.languages.some((language) =>
14+
Object.keys(languageData[activePage.product as ProductKey] ?? {}).includes(language),
1515
)),
1616
[activePage.languages, activePage.product, activePage.isDualLanguage],
1717
);

src/components/Layout/utils/nav.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type ActivePage = {
2020
clientLanguages?: LanguageKey[];
2121
agentLanguages?: LanguageKey[];
2222
isDualLanguage?: boolean;
23+
hasProductBar: boolean;
2324
};
2425

2526
/**

src/contexts/layout-context.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const LayoutContext = createContext<{
4040
clientLanguages: [],
4141
agentLanguages: [],
4242
isDualLanguage: false,
43+
hasProductBar: false,
4344
},
4445
});
4546

@@ -117,18 +118,21 @@ export const LayoutProvider: React.FC<PropsWithChildren<{ pageContext: PageConte
117118
const clientLanguage = isDualLanguage ? determineClientLanguage(location.search, clientLanguages) : undefined;
118119
const agentLanguage = isDualLanguage ? determineAgentLanguage(location.search, agentLanguages) : undefined;
119120

121+
const product = activePageData?.product ?? null;
122+
120123
return {
121124
tree: activePageData?.tree ?? [],
122125
page: activePageData?.page ?? { name: '', link: '' },
123126
languages,
124127
language: languages.includes(language) ? language : null,
125-
product: activePageData?.product ?? null,
128+
product,
126129
template: 'mdx' as PageTemplate,
127130
clientLanguage,
128131
agentLanguage,
129132
clientLanguages,
130133
agentLanguages,
131134
isDualLanguage,
135+
hasProductBar: product !== null && product !== 'platform',
132136
};
133137
}, [location.pathname, location.search, pageContext?.languages]);
134138

0 commit comments

Comments
 (0)