Skip to content

Commit

Permalink
fix: Fix page props filtering
Browse files Browse the repository at this point in the history
Props should not be overriden by undefined
  • Loading branch information
3y3 committed Nov 6, 2024
1 parent b44947c commit e03f71e
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions src/components/App/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,20 @@ export function RichNavPage({data, props, controls}: PageProps<WithNavigation>)
data={data}
headerHeight={fullScreen ? 0 : 64}
{...props}
{...filterControls(controls, navigation.withControls)}
{...(navigation.withControls
? filterControls(controls, [
'theme',
'onChangeTheme',
'textSize',
'onChangeTextSize',
'wideFormat',
'onChangeWideFormat',
'showMiniToc',
'onChangeShowMiniToc',
'langs',
'onChangeLang',
])
: controls)}
>
<ConstructorPage {...(data as DocContentPageData).data} />
</Page>
Expand Down Expand Up @@ -105,22 +118,15 @@ export function RichNavPage({data, props, controls}: PageProps<WithNavigation>)
);
}

function filterControls(controls: HeaderControlsProps, skipNavigationControls: boolean) {
if (!skipNavigationControls) {
return controls;
}

return {
...controls,
theme: undefined,
onChangeTheme: undefined,
textSize: undefined,
onChangeTextSize: undefined,
wideFormat: undefined,
onChangeWideFormat: undefined,
showMiniToc: undefined,
onChangeShowMiniToc: undefined,
langs: undefined,
onChangeLang: undefined,
};
function filterControls(controls: HeaderControlsProps, omitProps: string[]) {
return Object.keys(controls).reduce(
(acc, key) => {
if (!omitProps.includes(key)) {
acc[key] = controls[key as keyof HeaderControlsProps];
}

return acc;
},
{} as Record<string, unknown>,
) as Partial<HeaderControlsProps>;
}

0 comments on commit e03f71e

Please sign in to comment.