The Node.js® Website
at main 2.0 kB view raw
1import { getTranslations } from 'next-intl/server'; 2import type { FC, PropsWithChildren } from 'react'; 3 4import { useClientContext } from '@/hooks/react-server'; 5import getReleaseData from '@/next-data/releaseData'; 6import { ReleaseProvider } from '@/providers/releaseProvider'; 7import type { NodeReleaseStatus } from '@/types'; 8import { getDownloadCategory, mapCategoriesToTabs } from '@/util/downloadUtils'; 9 10import LinkTabs from './Common/LinkTabs'; 11import WithNodeRelease from './withNodeRelease'; 12 13const WithDownloadCategories: FC<PropsWithChildren> = async ({ children }) => { 14 const t = await getTranslations(); 15 const releases = await getReleaseData(); 16 17 const { pathname } = useClientContext(); 18 const { page, category, subCategory } = getDownloadCategory(pathname); 19 20 const initialRelease: Array<NodeReleaseStatus> = pathname.includes('current') 21 ? ['Current'] 22 : ['Active LTS', 'Maintenance LTS']; 23 24 return ( 25 <LinkTabs 26 activeTab={category} 27 label={t('layouts.download.selectCategory')} 28 tabs={mapCategoriesToTabs({ 29 page: page, 30 categories: [ 31 { 32 category: 'download', 33 label: t('layouts.download.categories.download'), 34 }, 35 { 36 category: 'prebuilt-binaries', 37 label: t('layouts.download.categories.prebuilt-binaries'), 38 }, 39 { 40 category: 'package-manager', 41 label: t('layouts.download.categories.package-manager'), 42 }, 43 { 44 category: 'source-code', 45 label: t('layouts.download.categories.source-code'), 46 }, 47 ], 48 subCategory: subCategory, 49 })} 50 > 51 <WithNodeRelease status={initialRelease}> 52 {({ release }) => ( 53 <ReleaseProvider initialRelease={release} releases={releases}> 54 {children} 55 </ReleaseProvider> 56 )} 57 </WithNodeRelease> 58 </LinkTabs> 59 ); 60}; 61 62export default WithDownloadCategories;