Skip to content

Commit a808053

Browse files
committed
Fikser typeerror i SectionNavigation
1 parent 5349766 commit a808053

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

src/components/layouts/section-with-header/section-navigation/SectionNavigation.tsx

+28-24
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,60 @@
1+
import React from 'react';
12
import { ComponentType } from 'types/component-props/_component-common';
23
import { RegionProps } from 'types/component-props/layouts';
34
import { PartType } from 'types/component-props/parts';
45
import { translator } from 'translations';
56
import { usePageConfig } from 'store/hooks/usePageConfig';
6-
7-
import styles from './SectionNavigation.module.scss';
87
import { LenkeBase } from 'components/_common/lenke/LenkeBase';
98
import { AnalyticsEvents } from 'utils/amplitude';
109

10+
import styles from './SectionNavigation.module.scss';
11+
1112
type SectionNavigationProps = {
12-
introRegion: RegionProps<'intro'>;
13-
contentRegion: RegionProps<'content'>;
13+
introRegion?: RegionProps<'intro'>;
14+
contentRegion?: RegionProps<'content'>;
1415
};
1516

1617
type Anchor = {
1718
anchorId: string;
1819
title: string;
1920
};
2021

21-
const getAnchorsFromComponents = (components: RegionProps['components']) => {
22-
return components
23-
.reduce((acc, component) => {
24-
if (
25-
component.type === ComponentType.Part &&
26-
component.descriptor === PartType.Header &&
27-
component.config?.titleTag === 'h3'
28-
) {
29-
acc.push({
30-
anchorId: component.config.anchorId as string,
31-
title: component.config.title as string,
32-
});
33-
}
34-
return acc;
35-
}, [] as Anchor[])
36-
.filter((anchor) => !!anchor.anchorId && !!anchor.title);
22+
const getAnchorsFromComponents = (region?: RegionProps) => {
23+
return region
24+
? region.components.reduce<Anchor[]>((acc, component) => {
25+
if (
26+
component.type === ComponentType.Part &&
27+
component.descriptor === PartType.Header &&
28+
component.config &&
29+
component.config.titleTag === 'h3' &&
30+
component.config.anchorId &&
31+
component.config.title
32+
) {
33+
acc.push({
34+
anchorId: component.config.anchorId as string,
35+
title: component.config.title as string,
36+
});
37+
}
38+
return acc;
39+
}, [])
40+
: [];
3741
};
3842

3943
export const SectionNavigation = ({
4044
introRegion,
4145
contentRegion,
4246
}: SectionNavigationProps) => {
4347
const { language } = usePageConfig();
44-
const introAnchors = getAnchorsFromComponents(introRegion.components);
45-
const contentAnchors = getAnchorsFromComponents(contentRegion.components);
48+
const introAnchors = getAnchorsFromComponents(introRegion);
49+
const contentAnchors = getAnchorsFromComponents(contentRegion);
4650
const allAnchors = [...introAnchors, ...contentAnchors];
4751

48-
const getLabels = translator('sectionNavigation', language);
49-
5052
if (allAnchors.length === 0) {
5153
return null;
5254
}
5355

56+
const getLabels = translator('sectionNavigation', language);
57+
5458
return (
5559
<ul
5660
aria-label={getLabels('navigationLabel')}

0 commit comments

Comments
 (0)