Skip to content

Commit 6ed0532

Browse files
committed
Resolve comments
1 parent 4bc4220 commit 6ed0532

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

packages/gitbook/src/app/(site)/fetch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface PageIdParams {
2121
pageId: string;
2222
}
2323

24-
type SectionsList = { list: SiteSection[]; section: SiteSection };
24+
export type SectionsList = { list: SiteSection[]; section: SiteSection; index: number; };
2525

2626
/**
2727
* Fetch all the data needed to render the content layout.
@@ -70,7 +70,7 @@ export async function fetchContentData() {
7070
function parseSiteSectionsList(siteSectionId: string, sections: SiteSection[]) {
7171
const section = sections.find((section) => section.id === siteSectionId);
7272
assert(sectionIsDefined(section), 'A section must be defined when there are multiple sections');
73-
return { list: sections, section } satisfies SectionsList;
73+
return { list: sections, section, index: sections.indexOf(section) } satisfies SectionsList;
7474
}
7575

7676
function sectionIsDefined(section?: SiteSection): section is NonNullable<SiteSection> {

packages/gitbook/src/components/Header/Header.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import {
22
CustomizationSettings,
33
Site,
44
SiteCustomizationSettings,
5-
SiteSection,
65
Space,
76
} from '@gitbook/api';
87
import { CustomizationHeaderPreset } from '@gitbook/api';
98
import { Suspense } from 'react';
109

10+
import type { SectionsList } from '@/app/(site)/fetch';
1111
import { CONTAINER_STYLE, HEADER_HEIGHT_DESKTOP } from '@/components/layout';
1212
import { t, getSpaceLanguage } from '@/intl/server';
1313
import { ContentRefContext } from '@/lib/references';
@@ -27,7 +27,7 @@ export function Header(props: {
2727
space: Space;
2828
site: Site | null;
2929
spaces: Space[];
30-
sections: { list: SiteSection[]; section: SiteSection } | null;
30+
sections: SectionsList | null;
3131
context: ContentRefContext;
3232
customization: CustomizationSettings | SiteCustomizationSettings;
3333
withTopHeader?: boolean;
@@ -153,7 +153,7 @@ export function Header(props: {
153153
)}
154154
>
155155
<div className={tcls(CONTAINER_STYLE)}>
156-
<SiteSectionTabs sections={sections.list} section={sections.section} />
156+
<SiteSectionTabs {...sections} />
157157
</div>
158158
</div>
159159
) : null}

packages/gitbook/src/components/SiteSectionTabs/SiteSectionTabs.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { Button, Link } from '../primitives';
1010
/**
1111
* A set of navigational tabs representing site sections for multi-section sites
1212
*/
13-
export function SiteSectionTabs(props: { sections: SiteSection[]; section: SiteSection }) {
14-
const { sections, section: currentSection } = props;
13+
export function SiteSectionTabs(props: { list: SiteSection[]; section: SiteSection; index: number; }) {
14+
const { list: sections, section: currentSection, index: currentIndex } = props;
1515

1616
const tabs = sections.map((section) => ({
1717
id: section.id,
@@ -22,9 +22,6 @@ export function SiteSectionTabs(props: { sections: SiteSection[]; section: SiteS
2222
const currentTabRef = React.useRef<HTMLAnchorElement>(null);
2323
const navRef = React.useRef<HTMLDivElement>(null);
2424

25-
// we don't set the current tab with a click event because the tab will navigate to a different section and trigger a page reload.
26-
const currentIndex = sections.findIndex((section) => section.id === currentSection?.id);
27-
2825
const [tabDimensions, setTabDimensions] = React.useState<{
2926
left: number;
3027
width: number;

packages/gitbook/src/components/SpaceLayout/SpaceLayout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import {
66
RevisionPageGroup,
77
Site,
88
SiteCustomizationSettings,
9-
SiteSection,
109
Space,
1110
} from '@gitbook/api';
1211
import React from 'react';
1312

13+
import { SectionsList } from '@/app/(site)/fetch';
1414
import { Footer } from '@/components/Footer';
1515
import { CompactHeader, Header } from '@/components/Header';
1616
import { CONTAINER_STYLE } from '@/components/layout';
@@ -31,7 +31,7 @@ export function SpaceLayout(props: {
3131
contentTarget: ContentTarget;
3232
space: Space;
3333
site: Site | null;
34-
sections: { list: SiteSection[]; section: SiteSection } | null;
34+
sections: SectionsList | null;
3535
spaces: Space[];
3636
customization: CustomizationSettings | SiteCustomizationSettings;
3737
pages: Revision['pages'];

0 commit comments

Comments
 (0)