Skip to content

Commit c7264ea

Browse files
committed
refactor: layout changes
1 parent a92ad35 commit c7264ea

File tree

17 files changed

+232
-439
lines changed

17 files changed

+232
-439
lines changed

apps/site/components/Downloads/DownloadsTable/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ const DownloadsTable: FC<DownloadsTableProps> = ({ source }) => {
1919
<thead>
2020
<tr>
2121
<th>{t('components.downloadsTable.fileName')}</th>
22-
<th className="md:w-24">
22+
<th className="md:w-28">
2323
{t('components.downloadsTable.operatingSystem')}
2424
</th>
25-
<th className="md:w-24">
25+
<th className="md:w-28">
2626
{t('components.downloadsTable.architecture')}
2727
</th>
2828
</tr>

apps/site/components/Downloads/MinorReleasesTable/index.module.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,20 @@
66
items-center
77
gap-2;
88
}
9+
10+
.scrollable {
11+
@apply scrollbar-thin
12+
flex
13+
snap-x
14+
snap-mandatory
15+
overflow-x-auto;
16+
17+
> table {
18+
@apply shrink-0
19+
snap-start;
20+
21+
thead th {
22+
@apply last:md:w-56;
23+
}
24+
}
25+
}

apps/site/components/Downloads/MinorReleasesTable/index.tsx

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,50 +15,67 @@ type MinorReleasesTableProps = {
1515
releases: Array<MinorVersion>;
1616
};
1717

18+
const chunkedReleases = (releases: Array<MinorVersion>, size: number) => {
19+
const count = Math.ceil(releases.length / size);
20+
21+
return Array.from({ length: count }, (_, index) =>
22+
releases.slice(index * size, (index + 1) * size)
23+
);
24+
};
25+
1826
export const MinorReleasesTable: FC<MinorReleasesTableProps> = ({
1927
releases,
2028
}) => {
2129
const t = useTranslations('components.minorReleasesTable');
30+
const releaseGroups = chunkedReleases(releases, 8);
2231

2332
return (
24-
<table>
25-
<thead>
26-
<tr>
27-
<th>{t('version')}</th>
28-
<th>{t('links')}</th>
29-
</tr>
30-
</thead>
31-
<tbody>
32-
{releases.map(release => (
33-
<tr key={release.version}>
34-
<td>v{release.version}</td>
35-
<td>
36-
<div className={styles.links}>
37-
<Link
38-
kind="neutral"
39-
href={`https://nodejs.org/download/release/v${release.version}/`}
40-
>
41-
{t('actions.release')}
42-
</Link>
43-
<Separator orientation="vertical" />
44-
<Link
45-
kind="neutral"
46-
href={`${BASE_CHANGELOG_URL}${release.version}`}
47-
>
48-
{t('actions.changelog')}
49-
</Link>
50-
<Separator orientation="vertical" />
51-
<Link
52-
kind="neutral"
53-
href={getNodeApiLink(`v${release.version}`)}
54-
>
55-
{t('actions.docs')}
56-
</Link>
57-
</div>
58-
</td>
59-
</tr>
60-
))}
61-
</tbody>
62-
</table>
33+
<div className={styles.scrollable}>
34+
{releaseGroups.map(releases => (
35+
<table key={releases[0].version}>
36+
<thead>
37+
<tr>
38+
<th>{t('version')}</th>
39+
<th>{t('links')}</th>
40+
</tr>
41+
</thead>
42+
<tbody>
43+
{releases.map(release => (
44+
<tr key={release.version}>
45+
<td>
46+
<Link kind="neutral" href={`/download/v${release.version}`}>
47+
v{release.version}
48+
</Link>
49+
</td>
50+
<td>
51+
<div className={styles.links}>
52+
<Link
53+
kind="neutral"
54+
href={`https://nodejs.org/download/release/v${release.version}/`}
55+
>
56+
{t('actions.release')}
57+
</Link>
58+
<Separator orientation="vertical" />
59+
<Link
60+
kind="neutral"
61+
href={`${BASE_CHANGELOG_URL}${release.version}`}
62+
>
63+
{t('actions.changelog')}
64+
</Link>
65+
<Separator orientation="vertical" />
66+
<Link
67+
kind="neutral"
68+
href={getNodeApiLink(`v${release.version}`)}
69+
>
70+
{t('actions.docs')}
71+
</Link>
72+
</div>
73+
</td>
74+
</tr>
75+
))}
76+
</tbody>
77+
</table>
78+
))}
79+
</div>
6380
);
6481
};

apps/site/components/MDX/Details/index.module.css

Lines changed: 0 additions & 41 deletions
This file was deleted.

apps/site/components/MDX/Details/index.tsx

Lines changed: 0 additions & 21 deletions
This file was deleted.

apps/site/components/withMarkdownContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const WithMarkdownContent: FC<WithMarkdownContentProps> = async ({ file }) => {
2929
const locale = await getLocale();
3030
const content = await getMarkdownContent(locale, file);
3131

32-
return content || null;
32+
return content;
3333
};
3434

3535
export default WithMarkdownContent;

apps/site/components/withMetaBar.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import MetaBar from '@node-core/ui-components/Containers/MetaBar';
44
import GitHubIcon from '@node-core/ui-components/Icons/Social/GitHub';
55
import { useFormatter, useLocale, useTranslations } from 'next-intl';
6-
import type { ComponentProps, FC } from 'react';
6+
import type { FC } from 'react';
77

88
import Link from '#site/components/Link';
99
import WithAvatarGroup from '#site/components/withAvatarGroup';
@@ -14,11 +14,7 @@ import { TRANSLATION_URL } from '#site/next.constants.mjs';
1414
import { defaultLocale } from '#site/next.locales.mjs';
1515
import { getGitHubBlobUrl } from '#site/util/gitHubUtils';
1616

17-
type WithMetaBarProps = {
18-
items?: ComponentProps<typeof MetaBar>['items'];
19-
};
20-
21-
const WithMetaBar: FC<WithMetaBarProps> = ({ items }) => {
17+
const WithMetaBar: FC = () => {
2218
const { headings, readingTime, frontmatter, filename } = useClientContext();
2319
const formatter = useFormatter();
2420
const lastUpdated = frontmatter.date
@@ -49,11 +45,8 @@ const WithMetaBar: FC<WithMetaBarProps> = ({ items }) => {
4945
heading={t('components.metabar.tableOfContents')}
5046
as={Link}
5147
items={{
52-
...items,
5348
[t('components.metabar.lastUpdated')]: lastUpdated,
54-
...(readingTime.minutes >= 1 && {
55-
[t('components.metabar.readingTime')]: readingTimeText,
56-
}),
49+
[t('components.metabar.readingTime')]: readingTimeText,
5750
...(usernames.length && {
5851
[t(
5952
`components.metabar.${usernames.length > 1 ? 'authors' : 'author'}`

apps/site/components/withProgressionSidebar.tsx

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,39 @@ import ProgressionSidebar from '@node-core/ui-components/Common/ProgressionSideb
44
import { usePathname } from 'next/navigation';
55
import { useLocale, useTranslations } from 'next-intl';
66
import type { RichTranslationValues } from 'next-intl';
7-
import type { ComponentProps, FC } from 'react';
7+
import type { FC } from 'react';
88

99
import Link from '#site/components/Link';
1010
import { useSiteNavigation } from '#site/hooks/server';
1111
import { useRouter } from '#site/navigation.mjs';
1212
import type { NavigationKeys } from '#site/types';
1313

14-
type Group = ComponentProps<typeof ProgressionSidebar>['groups'][number];
15-
16-
type WithProgressionSidebarProps =
17-
| {
18-
navKey: NavigationKeys;
19-
context?: Record<string, RichTranslationValues>;
20-
groups?: never;
21-
}
22-
| {
23-
groups: Array<Group>;
24-
navKey?: never;
25-
context?: never;
26-
};
14+
type WithProgressionSidebarProps = {
15+
navKey: NavigationKeys;
16+
context?: Record<string, RichTranslationValues>;
17+
};
2718

28-
const WithProgressionSidebar: FC<WithProgressionSidebarProps> = props => {
19+
const WithProgressionSidebar: FC<WithProgressionSidebarProps> = ({
20+
navKey,
21+
context,
22+
}) => {
2923
const { getSideNavigation } = useSiteNavigation();
3024
const pathname = usePathname();
3125
const locale = useLocale();
3226
const t = useTranslations();
3327
const { push } = useRouter();
28+
const [[, sidebarNavigation]] = getSideNavigation([navKey], context);
3429

35-
let groups: Array<Group> = [];
36-
37-
if ('navKey' in props && props.navKey) {
38-
const [[, sidebarNavigation]] = getSideNavigation(
39-
[props.navKey],
40-
props.context
41-
);
42-
43-
groups = sidebarNavigation.items.map(([, { label, items }]) => ({
30+
const mappedProgressionSidebarItems = sidebarNavigation.items.map(
31+
([, { label, items }]) => ({
4432
groupName: label,
4533
items: items.map(([, item]) => item),
46-
}));
47-
} else if ('groups' in props) {
48-
groups = props.groups;
49-
}
34+
})
35+
);
5036

5137
return (
5238
<ProgressionSidebar
53-
groups={groups}
39+
groups={mappedProgressionSidebarItems}
5440
pathname={pathname?.replace(`/${locale}`, '')}
5541
title={t('components.common.sidebar.title')}
5642
onSelect={push}
Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
import type MetaBar from '@node-core/ui-components/Containers/MetaBar';
2-
import { getTranslations } from 'next-intl/server';
3-
import type { ComponentProps, FC } from 'react';
1+
import type { FC } from 'react';
42

53
import { getClientContext } from '#site/client-context';
64
import getReleaseData from '#site/next-data/releaseData';
75
import {
8-
buildMetaBarItems,
96
buildReleaseArtifacts,
107
extractVersionFromPath,
11-
groupReleasesByStatus,
128
} from '#site/util/downloadUtils/simple';
139

14-
type SimplifiedDownload = ReturnType<typeof buildReleaseArtifacts> & {
15-
sidebarItems: ReturnType<typeof groupReleasesByStatus>;
16-
metabarItems: ComponentProps<typeof MetaBar>['items'];
17-
};
10+
type SimplifiedDownload = ReturnType<typeof buildReleaseArtifacts>;
1811

1912
type WithSimplifiedDownloadProps = {
2013
children: FC<SimplifiedDownload>;
@@ -27,45 +20,34 @@ const WithSimplifiedDownload: FC<WithSimplifiedDownloadProps> = async ({
2720
children: Component,
2821
}) => {
2922
const { pathname } = getClientContext();
30-
const [releaseData, t] = await Promise.all([
31-
getReleaseData(),
32-
getTranslations(),
33-
]);
23+
const releaseData = await getReleaseData();
3424

3525
// Extract version from pathname
36-
const version = extractVersionFromPath(pathname);
26+
const { version, major } = extractVersionFromPath(pathname) || {};
3727

3828
if (!version) {
3929
return null;
4030
}
4131

4232
// Find the matching release
4333
const release = releaseData.find(
44-
({ major, isLts }) =>
45-
major === Number(version) || (isLts === true && version === 'simplified')
34+
release =>
35+
release.major === major ||
36+
(release.isLts === true && version === 'simplified')
4637
);
4738

4839
if (!release) {
4940
return null;
5041
}
5142

52-
const releaseArtifacts = buildReleaseArtifacts(release);
53-
const metabarItems = buildMetaBarItems(release, t);
54-
55-
// Group and localize sidebar items
56-
const mappedSidebarItems = groupReleasesByStatus(releaseData, pathname);
57-
const localizedSidebarItems = mappedSidebarItems.map(item => ({
58-
...item,
59-
groupName: t(`layouts.simpleDownload.statusNames.${item.groupName}`),
60-
}));
61-
62-
return (
63-
<Component
64-
{...releaseArtifacts}
65-
sidebarItems={localizedSidebarItems}
66-
metabarItems={metabarItems}
67-
/>
43+
const majorVersions = releaseData.map(release => release.versionWithPrefix);
44+
const releaseArtifacts = buildReleaseArtifacts(
45+
release,
46+
version,
47+
majorVersions
6848
);
49+
50+
return <Component {...releaseArtifacts} />;
6951
};
7052

7153
export default WithSimplifiedDownload;

0 commit comments

Comments
 (0)