File tree Expand file tree Collapse file tree 4 files changed +9
-12
lines changed
Expand file tree Collapse file tree 4 files changed +9
-12
lines changed Original file line number Diff line number Diff 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() {
7070function 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
7676function sectionIsDefined ( section ?: SiteSection ) : section is NonNullable < SiteSection > {
Original file line number Diff line number Diff line change @@ -2,12 +2,12 @@ import {
22 CustomizationSettings ,
33 Site ,
44 SiteCustomizationSettings ,
5- SiteSection ,
65 Space ,
76} from '@gitbook/api' ;
87import { CustomizationHeaderPreset } from '@gitbook/api' ;
98import { Suspense } from 'react' ;
109
10+ import type { SectionsList } from '@/app/(site)/fetch' ;
1111import { CONTAINER_STYLE , HEADER_HEIGHT_DESKTOP } from '@/components/layout' ;
1212import { t , getSpaceLanguage } from '@/intl/server' ;
1313import { 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 }
Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff line change @@ -6,11 +6,11 @@ import {
66 RevisionPageGroup ,
77 Site ,
88 SiteCustomizationSettings ,
9- SiteSection ,
109 Space ,
1110} from '@gitbook/api' ;
1211import React from 'react' ;
1312
13+ import { SectionsList } from '@/app/(site)/fetch' ;
1414import { Footer } from '@/components/Footer' ;
1515import { CompactHeader , Header } from '@/components/Header' ;
1616import { 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' ] ;
You can’t perform that action at this time.
0 commit comments