Skip to content

Commit 5ed9b97

Browse files
authored
Merge pull request #3702 from clairep94/pr05_finals_clientModuleAbout
Pr05 Typescript Migration #18: Migrate `client/modules/About` & `client/modules/Legal`
2 parents 998e79d + 18db7e5 commit 5ed9b97

File tree

11 files changed

+95
-66
lines changed

11 files changed

+95
-66
lines changed
File renamed without changes.

client/modules/About/pages/About.jsx renamed to client/modules/About/pages/About.tsx

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react';
2-
import PropTypes from 'prop-types';
32
import { useSelector } from 'react-redux';
43
import { Helmet } from 'react-helmet';
54
import { useTranslation } from 'react-i18next';
65
import { Link } from 'react-router-dom';
76

7+
import type { TFunction } from 'react-i18next';
88
import {
99
AboutPageContent,
1010
Intro,
@@ -27,8 +27,34 @@ import packageData from '../../../../package.json';
2727
import HeartIcon from '../../../images/heart.svg';
2828
import AsteriskIcon from '../../../images/p5-asterisk.svg';
2929
import LogoIcon from '../../../images/p5js-square-logo.svg';
30+
import { RootState } from '../../../reducers';
3031

31-
const AboutSection = ({ section, t }) => (
32+
export interface AboutSectionInfoItem {
33+
url: string;
34+
title: string;
35+
description: string;
36+
}
37+
export interface AboutSectionInfoSection {
38+
header: string;
39+
items: AboutSectionInfoItem[];
40+
}
41+
export interface ContactSectionLink {
42+
label: string;
43+
href: string;
44+
}
45+
46+
export interface AboutSectionProps {
47+
section: AboutSectionInfoSection;
48+
t: TFunction<'translation'>;
49+
}
50+
51+
const AboutSection = ({
52+
section,
53+
t
54+
}: {
55+
section: AboutSectionInfoSection;
56+
t: TFunction<'translation'>;
57+
}) => (
3258
<Section>
3359
<h2>{t(section.header)}</h2>
3460
<SectionContainer>
@@ -47,11 +73,15 @@ const AboutSection = ({ section, t }) => (
4773
</Section>
4874
);
4975

50-
const About = () => {
76+
export const About = () => {
5177
const { t } = useTranslation();
5278

53-
const p5version = useSelector((state) => {
54-
const index = state.files.find((file) => file.name === 'index.html');
79+
const p5version = useSelector((state: RootState) => {
80+
const index = state.files.find(
81+
(file: {
82+
name: string /** TODO: update once files types are defined in server */;
83+
}) => file.name === 'index.html'
84+
);
5585
return index?.content.match(/\/p5@([\d.]+)\//)?.[1];
5686
});
5787

@@ -91,7 +121,11 @@ const About = () => {
91121
</Intro>
92122

93123
{AboutSectionInfo.map((section) => (
94-
<AboutSection key={t(section.header)} section={section} t={t} />
124+
<AboutSection
125+
key={t(section.header) as string}
126+
section={section}
127+
t={t}
128+
/>
95129
))}
96130

97131
<Contact>
@@ -152,19 +186,3 @@ const About = () => {
152186
</RootPage>
153187
);
154188
};
155-
156-
AboutSection.propTypes = {
157-
section: PropTypes.shape({
158-
header: PropTypes.string.isRequired,
159-
items: PropTypes.arrayOf(
160-
PropTypes.shape({
161-
url: PropTypes.string.isRequired,
162-
title: PropTypes.string.isRequired,
163-
description: PropTypes.string.isRequired
164-
})
165-
).isRequired
166-
}).isRequired,
167-
t: PropTypes.func.isRequired
168-
};
169-
170-
export default About;

client/modules/About/statics/aboutData.js renamed to client/modules/About/statics/aboutData.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
export const ContactSectionLinks = [
1+
import type {
2+
ContactSectionLink,
3+
AboutSectionInfoSection
4+
} from '../pages/About';
5+
6+
export const ContactSectionLinks: ContactSectionLink[] = [
27
{
38
label: 'About.Github',
49
href: 'https://github.com/processing/p5.js-web-editor'
@@ -22,7 +27,7 @@ export const ContactSectionLinks = [
2227
}
2328
];
2429

25-
export const AboutSectionInfo = [
30+
export const AboutSectionInfo: AboutSectionInfoSection[] = [
2631
{
2732
header: 'About.NewP5',
2833
items: [

client/modules/Legal/components/PolicyContainer.jsx renamed to client/modules/Legal/components/PolicyContainer.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react';
22
import styled from 'styled-components';
33
import ReactMarkdown from 'react-markdown';
44
import remarkSlug from 'remark-slug';
5-
import PropTypes from 'prop-types';
65
import { remSize, prop } from '../../../theme';
76

87
const PolicyContainerMain = styled.main`
@@ -48,16 +47,13 @@ const PolicyContainerMain = styled.main`
4847
}
4948
`;
5049

51-
function PolicyContainer({ policy }) {
50+
export interface PolicyContainerProps {
51+
policy: string;
52+
}
53+
export function PolicyContainer({ policy }: PolicyContainerProps) {
5254
return (
5355
<PolicyContainerMain>
5456
<ReactMarkdown remarkPlugins={[remarkSlug]}>{policy}</ReactMarkdown>
5557
</PolicyContainerMain>
5658
);
5759
}
58-
59-
PolicyContainer.propTypes = {
60-
policy: PropTypes.string.isRequired
61-
};
62-
63-
export default PolicyContainer;
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import React from 'react';
22
import { useTranslation } from 'react-i18next';
3-
import Legal from './Legal';
3+
import { Legal } from './Legal';
44

5-
function CodeOfConduct() {
5+
export function CodeOfConduct() {
66
const { t } = useTranslation();
77

88
return (
99
<Legal policyFile="code-of-conduct.md" title={t('Legal.CodeOfConduct')} />
1010
);
1111
}
12-
13-
export default CodeOfConduct;

client/modules/Legal/pages/Legal.jsx renamed to client/modules/Legal/pages/Legal.tsx

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import axios from 'axios';
2-
import PropTypes from 'prop-types';
32
import React, { useEffect, useState } from 'react';
43
import Helmet from 'react-helmet';
54
import { useTranslation } from 'react-i18next';
@@ -9,7 +8,7 @@ import { RootPage } from '../../../components/RootPage';
98
import { remSize } from '../../../theme';
109
import Loader from '../../App/components/loader';
1110
import Nav from '../../IDE/components/Header/Nav';
12-
import PolicyContainer from '../components/PolicyContainer';
11+
import { PolicyContainer } from '../components/PolicyContainer';
1312

1413
const StyledTabList = styled.nav`
1514
display: flex;
@@ -21,8 +20,18 @@ const StyledTabList = styled.nav`
2120
gap: ${remSize(19)};
2221
}
2322
`;
24-
25-
function Legal({ policyFile, title }) {
23+
export interface LegalProps {
24+
/**
25+
* Path of the markdown '.md' file, relative to the /public directory.
26+
*/
27+
policyFile: string;
28+
/**
29+
* Used in the HTML <title> tag.
30+
* TODO: pass this to the Nav to use as the mobile title.
31+
*/
32+
title: string;
33+
}
34+
export function Legal({ policyFile, title }: LegalProps) {
2635
const { t } = useTranslation();
2736
const [isLoading, setIsLoading] = useState(true);
2837
const [policy, setPolicy] = useState('');
@@ -55,17 +64,3 @@ function Legal({ policyFile, title }) {
5564
</RootPage>
5665
);
5766
}
58-
59-
Legal.propTypes = {
60-
/**
61-
* Used in the HTML <title> tag.
62-
* TODO: pass this to the Nav to use as the mobile title.
63-
*/
64-
title: PropTypes.string.isRequired,
65-
/**
66-
* Path of the markdown '.md' file, relative to the /public directory.
67-
*/
68-
policyFile: PropTypes.string.isRequired
69-
};
70-
71-
export default Legal;
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import React from 'react';
22
import { useTranslation } from 'react-i18next';
3-
import Legal from './Legal';
3+
import { Legal } from './Legal';
44

5-
function PrivacyPolicy() {
5+
export function PrivacyPolicy() {
66
const { t } = useTranslation();
77

88
return (
99
<Legal policyFile="privacy-policy.md" title={t('Legal.PrivacyPolicy')} />
1010
);
1111
}
12-
13-
export default PrivacyPolicy;
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import React from 'react';
22
import { useTranslation } from 'react-i18next';
3-
import Legal from './Legal';
3+
import { Legal } from './Legal';
44

5-
function TermsOfUse() {
5+
export function TermsOfUse() {
66
const { t } = useTranslation();
77

88
return <Legal policyFile="terms-of-use.md" title={t('Legal.TermsOfUse')} />;
99
}
10-
11-
export default TermsOfUse;

client/routes.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { Route as RouterRoute, Switch } from 'react-router-dom';
66
import App from './modules/App/App';
77
import IDEView from './modules/IDE/pages/IDEView';
88
import FullView from './modules/IDE/pages/FullView';
9-
import About from './modules/About/pages/About';
10-
import CodeOfConduct from './modules/Legal/pages/CodeOfConduct';
11-
import PrivacyPolicy from './modules/Legal/pages/PrivacyPolicy';
12-
import TermsOfUse from './modules/Legal/pages/TermsOfUse';
9+
import { About } from './modules/About/pages/About';
10+
import { CodeOfConduct } from './modules/Legal/pages/CodeOfConduct';
11+
import { PrivacyPolicy } from './modules/Legal/pages/PrivacyPolicy';
12+
import { TermsOfUse } from './modules/Legal/pages/TermsOfUse';
1313
import LoginView from './modules/User/pages/LoginView';
1414
import SignupView from './modules/User/pages/SignupView';
1515
import ResetPasswordView from './modules/User/pages/ResetPasswordView';

package-lock.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)