Skip to content

Commit f820d68

Browse files
authored
refactor(components): reorganised the structure of the components keeping things cleaner (nodejs#2921)
1 parent cfad20c commit f820d68

File tree

210 files changed

+443
-376
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

210 files changed

+443
-376
lines changed

gatsby-browser.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import ReactIntlProvider from './src/containers/ReactIntl';
2+
import ReactIntlProvider from './src/providers/ReactIntl';
33
import { defaultLanguage, defaultMessages } from './locales';
44
import type { WrapPageElementBrowser } from './src/types';
55

gatsby-ssr.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import ReactIntlProvider from './src/containers/ReactIntl';
2+
import ReactIntlProvider from './src/providers/ReactIntl';
33
import { defaultLanguage, defaultMessages } from './locales';
44
import type { WrapPageElementSSR } from './src/types';
55

src/components/Author/__tests__/__snapshots__/index.test.tsx.snap renamed to src/components/ArticleComponents/AuthorList/Author/__tests__/__snapshots__/index.test.tsx.snap

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Author component does not render without a username 1`] = `<div />`;
3+
exports[`Author component does not render without a username 1`] = `
4+
<div>
5+
<li>
6+
<a
7+
aria-label=" Github - opens in new tab"
8+
class="link"
9+
href="https://github.com/"
10+
rel="noopener noreferrer"
11+
style="margin-left: 0px;"
12+
target="_blank"
13+
>
14+
<img
15+
alt=""
16+
src="https://github.com/.png?size="
17+
/>
18+
</a>
19+
</li>
20+
</div>
21+
`;
422

523
exports[`Author component renders correctly 1`] = `
624
<div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React from 'react';
2+
import { injectIntl, WrappedComponentProps } from 'react-intl';
3+
import styles from './index.module.scss';
4+
5+
interface Props {
6+
index: number;
7+
username: string;
8+
size: string;
9+
}
10+
11+
const Author = ({
12+
index,
13+
username,
14+
size = '64',
15+
intl,
16+
}: Props & WrappedComponentProps) => {
17+
// Clean up username and build links.
18+
const githubUserName = username.trim();
19+
const githubLink = `https://github.com/${githubUserName}`;
20+
const githubImgLink = `https://github.com/${githubUserName}.png?size=${size}`;
21+
22+
// If it's the first author then no margin left.
23+
const mleft = index === 0 ? { marginLeft: 0 } : {};
24+
25+
const translation = intl.formatMessage(
26+
{ id: 'components.author.githubLinkLabel' },
27+
{ username }
28+
);
29+
30+
return (
31+
<li>
32+
<a
33+
className={styles.link}
34+
href={githubLink}
35+
aria-label={translation}
36+
key={username}
37+
target="_blank"
38+
rel="noopener noreferrer"
39+
style={mleft}
40+
>
41+
<img src={githubImgLink} alt="" />
42+
</a>
43+
</li>
44+
);
45+
};
46+
47+
export default injectIntl(Author);

src/containers/AuthorList/index.tsx renamed to src/components/ArticleComponents/AuthorList/index.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { FormattedMessage } from 'react-intl';
3-
import Author from '../../components/Author';
3+
import Author from './Author';
44
import styles from './index.module.scss';
55

66
interface Props {
@@ -14,10 +14,9 @@ const AuthorList = ({ authors }: Props): JSX.Element => {
1414
<FormattedMessage id="containers.authorList.title" />
1515
<ul>
1616
{authors.map(
17-
(author, i): string | JSX.Element =>
18-
author && (
19-
<Author index={i} username={author} key={author} size="60" />
20-
)
17+
(author, i): JSX.Element => (
18+
<Author index={i} username={author} key={author} size="60" />
19+
)
2120
)}
2221
</ul>
2322
</div>

src/components/Codebox/index.tsx renamed to src/components/ArticleComponents/Codebox/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react';
22
import { highlight, languages } from 'prismjs';
33
import { sanitize } from 'isomorphic-dompurify';
44
import classnames from 'classnames';
5-
import { copyTextToClipboard } from '../../util/copyTextToClipboard';
5+
import { copyTextToClipboard } from '../../../util/copyTextToClipboard';
66
import styles from './index.module.scss';
77

88
interface Props {

src/components/Pagination/__tests__/index.test.tsx renamed to src/components/ArticleComponents/Pagination/__tests__/index.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { render } from '@testing-library/react';
33
import Pagination from '..';
4-
import { createPaginationInfo } from '../../../__fixtures__/page';
4+
import { createPaginationInfo } from '../../../../__fixtures__/page';
55

66
describe('Pagination component', () => {
77
it('renders links to the next and previous page', () => {

src/components/Pagination/index.tsx renamed to src/components/ArticleComponents/Pagination/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { FormattedMessage } from 'react-intl';
33
import { LocalizedLink as Link } from 'gatsby-theme-i18n';
44
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
55
import { faAnglesRight, faAnglesLeft } from '@fortawesome/free-solid-svg-icons';
6-
import { PaginationInfo } from '../../types';
6+
import { PaginationInfo } from '../../../types';
77
import styles from './index.module.scss';
88

99
interface Props {

src/components/RecentPosts/__tests__/index.test.tsx renamed to src/components/ArticleComponents/RecentPosts/__tests__/index.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { render } from '@testing-library/react';
33
import RecentPosts from '..';
4-
import { createBlogPageContext } from '../../../__fixtures__/page';
4+
import { createBlogPageContext } from '../../../../__fixtures__/page';
55

66
describe('RecentPosts component', (): void => {
77
it('should render correctly', (): void => {

src/components/RecentPosts/index.tsx renamed to src/components/ArticleComponents/RecentPosts/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { LocalizedLink as Link } from 'gatsby-theme-i18n';
33
import { FormattedMessage } from 'react-intl';
4-
import { BlogPost } from '../../types';
4+
import { BlogPost } from '../../../types';
55
import styles from './index.module.scss';
66

77
interface Props {

src/components/TableOfContents/__tests__/toc.test.tsx renamed to src/components/ArticleComponents/TableOfContents/__tests__/toc.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { render } from '@testing-library/react';
33
import TableOfContents from '..';
4-
import { mockTableOfContents } from '../../../__fixtures__/page';
4+
import { mockTableOfContents } from '../../../../__fixtures__/page';
55

66
describe('TOC component', () => {
77
it('renders correctly', () => {

src/components/TableOfContents/index.tsx renamed to src/components/ArticleComponents/TableOfContents/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { FormattedMessage } from 'react-intl';
33
import { Link } from 'gatsby';
4-
import { TableOfContentsItem } from '../../types';
4+
import { TableOfContentsItem } from '../../../types';
55
import styles from './index.module.scss';
66

77
interface Props {
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export { default as Alert } from './Alert';
2+
export { default as BlockQuote } from './BlockQuote';
3+
export { default as AuthorList } from './AuthorList';
4+
export { default as Codebox } from './Codebox';
5+
export { default as InlineCode } from './Codebox/InlineCode';
6+
export { default as DataTag } from './DataTag';
7+
export { default as EditLink } from './EditLink';
8+
export { default as Pagination } from './Pagination';
9+
export { default as RecentPosts } from './RecentPosts';
10+
export { default as Table } from './Table';
11+
export { default as TableOfContents } from './TableOfContents';

src/components/Author/index.tsx

-52
This file was deleted.

src/components/BlogAuthorsList/__tests__/index.test.tsx renamed to src/components/BlogComponents/BlogAuthorsList/__tests__/index.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { render } from '@testing-library/react';
33
import BlogAuthor from '..';
4-
import { BlogPostAuthor } from '../../../types';
4+
import { BlogPostAuthor } from '../../../../types';
55

66
describe('Blog Author component', () => {
77
it('renders correctly', () => {

src/components/BlogAuthorsList/index.tsx renamed to src/components/BlogComponents/BlogAuthorsList/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
2-
import { BlogPostAuthor } from '../../types';
3-
import { getTerminatingString } from '../../util/getTerminatingString';
2+
import { getTerminatingString } from '../../../util/getTerminatingString';
3+
import { BlogPostAuthor } from '../../../types';
44
import styles from './index.module.scss';
55

66
interface Props {

src/components/BlogCard/__tests__/index.test.tsx renamed to src/components/BlogComponents/BlogCard/__tests__/index.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { render } from '@testing-library/react';
3-
import { BlogPost } from '../../../types';
3+
import { BlogPost } from '../../../../types';
44
import BlogCard from '..';
55

66
describe('Blog Card component', () => {

src/components/BlogCard/index.tsx renamed to src/components/BlogComponents/BlogCard/index.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import { LocalizedLink as Link } from 'gatsby-theme-i18n';
21
import React, { Fragment } from 'react';
32
import { injectIntl, WrappedComponentProps } from 'react-intl';
4-
import { BlogPost } from '../../types';
5-
import { getTerminatingString } from '../../util/getTerminatingString';
6-
import { blogPath } from '../../../pathPrefixes';
3+
import { LocalizedLink as Link } from 'gatsby-theme-i18n';
4+
import { getTerminatingString } from '../../../util/getTerminatingString';
5+
import { blogPath } from '../../../../pathPrefixes';
6+
import { BlogPost } from '../../../types';
77
import styles from './index.module.scss';
88

9-
interface Props {
10-
data: BlogPost;
11-
}
12-
139
const getBlogCategoryUrl = (category: string): string =>
1410
`${blogPath}${category}/`;
1511

1612
const getBlogPostUrl = (slug: string) =>
1713
slug.endsWith('/') ? slug : `${slug}/`;
1814

15+
interface Props {
16+
data: BlogPost;
17+
}
18+
1919
const BlogCard = ({
2020
data: {
2121
node: {
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { default as BlogAuthorsList } from './BlogAuthorsList';
2+
export { default as BlogCard } from './BlogCard';

src/components/Banner/__tests__/index.test.tsx renamed to src/components/CommonComponents/Banner/__tests__/index.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { render, screen } from '@testing-library/react';
33
import Banner from '..';
4-
import { BannersIndex } from '../../../types';
4+
import { BannersIndex } from '../../../../types';
55

66
const bannersIndex: BannersIndex = {
77
endDate: '',

src/components/Banner/index.tsx renamed to src/components/CommonComponents/Banner/index.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, { useMemo } from 'react';
22
import { sanitize } from 'isomorphic-dompurify';
3-
import { dateIsBetween } from '../../util/dateIsBetween';
4-
import config from '../../config.json';
5-
import { BannersIndex } from '../../types';
6-
import { isAbsoluteUrl } from '../../util/isAbsoluteUrl';
3+
import { dateIsBetween } from '../../../util/dateIsBetween';
4+
import { isAbsoluteUrl } from '../../../util/isAbsoluteUrl';
5+
import { BannersIndex } from '../../../types';
6+
import config from '../../../config.json';
77
import styles from './index.module.scss';
88

99
export interface BannerProps {

src/components/DarkModeToggle/index.tsx renamed to src/components/CommonComponents/DarkModeToggle/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import ModeNightIcon from '@mui/icons-material/ModeNight';
33
import BrightnessMediumIcon from '@mui/icons-material/BrightnessMedium';
4-
import { useTheme } from '../../hooks/useTheme';
4+
import { useTheme } from '../../../hooks/useTheme';
55
import styles from './index.module.scss';
66

77
const DarkModeToggle = () => {

src/components/Dropdown/computeDropdownStyles.ts renamed to src/components/CommonComponents/Dropdown/computeDropdownStyles.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ElementPositionAndSize } from '../../hooks/useElementPositionAndSize';
1+
import type { ElementPositionAndSize } from '../../../hooks/useElementPositionAndSize';
22

33
export const exptraLeftValue = 10;
44
export const exptraTopValue = 15;

src/components/Dropdown/index.tsx renamed to src/components/CommonComponents/Dropdown/index.tsx

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
import React, { useRef } from 'react';
2-
import { useElementPositionAndSize } from '../../hooks/useElementPositionAndSize';
2+
import { useElementPositionAndSize } from '../../../hooks/useElementPositionAndSize';
33
import { computeDropdownStyles } from './computeDropdownStyles';
4+
import { DropdownItem } from '../../../types';
45
import styles from './index.module.scss';
56

6-
export interface DropdownItem {
7-
title: string;
8-
label: string;
9-
onClick: () => void;
10-
active?: boolean;
11-
}
12-
137
interface Props<T> {
148
items: Array<DropdownItem>;
159
shouldShow: boolean;

src/components/Hero/__tests__/index.test.tsx renamed to src/components/CommonComponents/Hero/__tests__/index.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { render } from '@testing-library/react';
3-
import { createNodeReleasesData } from '../../../__fixtures__/page';
3+
import { createNodeReleasesData } from '../../../../__fixtures__/page';
44

55
import Hero from '..';
66

src/components/Hero/index.module.scss renamed to src/components/CommonComponents/Hero/index.module.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@use '../../styles/typography.scss';
1+
@use '../../../styles/typography.scss';
22

33
.hero {
44
align-items: center;

src/components/Hero/index.tsx renamed to src/components/CommonComponents/Hero/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react';
22
import { FormattedMessage } from 'react-intl';
33
import { LocalizedLink as Link } from 'gatsby-theme-i18n';
4-
import { useDetectOs } from '../../hooks/useDetectOs';
5-
import type { NodeReleaseData } from '../../types';
4+
import { useDetectOs } from '../../../hooks/useDetectOs';
5+
import type { NodeReleaseData } from '../../../types';
66
import styles from './index.module.scss';
77

88
interface Props {

src/components/LanguageSelector/index.tsx renamed to src/components/CommonComponents/LanguageSelector/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useRef } from 'react';
22
import TranslateIcon from '@mui/icons-material/Translate';
3-
import { useAutoClosableDropdown } from '../../hooks/useAutoClosableDropdown';
4-
import { useLocaleAsDropdown } from '../../hooks/useLocaleAsDropdown';
3+
import { useAutoClosableDropdown } from '../../../hooks/useAutoClosableDropdown';
4+
import { useLocaleAsDropdown } from '../../../hooks/useLocaleAsDropdown';
55
import styles from './index.module.scss';
66

77
const LanguageSelector = () => {

0 commit comments

Comments
 (0)