|
1 | | -import React, { useState, useEffect } from 'react'; |
2 | | -import { useHistory, useLocation } from 'react-router-dom'; |
3 | | -import { Tab, Tabs, TabList, TabPanel } from 'react-tabs'; |
4 | | -import styled from 'styled-components'; |
| 1 | +import axios from 'axios'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | +import React, { useEffect, useState } from 'react'; |
| 4 | +import Helmet from 'react-helmet'; |
5 | 5 | import { useTranslation } from 'react-i18next'; |
6 | | -import PrivacyPolicy from './PrivacyPolicy'; |
7 | | -import TermsOfUse from './TermsOfUse'; |
8 | | -import CodeOfConduct from './CodeOfConduct'; |
| 6 | +import styled from 'styled-components'; |
| 7 | +import RouterTab from '../../../common/RouterTab'; |
9 | 8 | import RootPage from '../../../components/RootPage'; |
| 9 | +import { remSize } from '../../../theme'; |
| 10 | +import Loader from '../../App/components/loader'; |
10 | 11 | import Nav from '../../IDE/components/Header/Nav'; |
11 | | -import { remSize, prop } from '../../../theme'; |
| 12 | +import PolicyContainer from '../components/PolicyContainer'; |
12 | 13 |
|
13 | | -const StyledTabList = styled(TabList)` |
| 14 | +const StyledTabList = styled.nav` |
14 | 15 | display: flex; |
15 | | - max-width: ${remSize(680)}; |
16 | | - padding-top: ${remSize(10)}; |
| 16 | + max-width: ${remSize(700)}; |
17 | 17 | margin: 0 auto; |
18 | | - border-bottom: 1px solid ${prop('Modal.separator')}; |
19 | | -`; |
20 | | - |
21 | | -const TabTitle = styled.p` |
22 | | - padding: 0 ${remSize(5)} ${remSize(5)} ${remSize(5)}; |
23 | | - cursor: pointer; |
24 | | - color: ${prop('inactiveTextColor')}; |
25 | | - &:hover, |
26 | | - &:focus { |
27 | | - color: ${prop('primaryTextColor')}; |
| 18 | + padding: 0 ${remSize(10)}; |
| 19 | + & ul { |
| 20 | + padding-top: ${remSize(10)}; |
| 21 | + gap: ${remSize(19)}; |
28 | 22 | } |
29 | 23 | `; |
30 | 24 |
|
31 | | -function Legal() { |
32 | | - const [selectedIndex, setSelectedIndex] = useState(0); |
| 25 | +function Legal({ policyFile, title }) { |
33 | 26 | const { t } = useTranslation(); |
34 | | - const location = useLocation(); |
35 | | - const history = useHistory(); |
| 27 | + const [isLoading, setIsLoading] = useState(true); |
| 28 | + const [policy, setPolicy] = useState(''); |
36 | 29 |
|
37 | 30 | useEffect(() => { |
38 | | - if (location.pathname === '/privacy-policy') { |
39 | | - setSelectedIndex(0); |
40 | | - } else if (location.pathname === '/terms-of-use') { |
41 | | - setSelectedIndex(1); |
42 | | - } else { |
43 | | - setSelectedIndex(2); |
44 | | - } |
45 | | - }, [location]); |
46 | | - |
47 | | - function onSelect(index, lastIndex, event) { |
48 | | - if (index === lastIndex) return; |
49 | | - if (index === 0) { |
50 | | - setSelectedIndex(0); |
51 | | - history.push('/privacy-policy'); |
52 | | - } else if (index === 1) { |
53 | | - setSelectedIndex(1); |
54 | | - history.push('/terms-of-use'); |
55 | | - } else if (index === 2) { |
56 | | - setSelectedIndex(2); |
57 | | - history.push('/code-of-conduct'); |
58 | | - } |
59 | | - } |
| 31 | + axios.get(policyFile).then((response) => { |
| 32 | + setPolicy(response.data); |
| 33 | + setIsLoading(false); |
| 34 | + }); |
| 35 | + }, [policyFile]); |
60 | 36 |
|
61 | 37 | return ( |
62 | 38 | <RootPage> |
| 39 | + {/* TODO: translate site name */} |
| 40 | + <Helmet> |
| 41 | + <title>p5.js Web Editor | {title}</title> |
| 42 | + </Helmet> |
63 | 43 | <Nav layout="dashboard" /> |
64 | | - <Tabs selectedIndex={selectedIndex} onSelect={onSelect}> |
65 | | - <StyledTabList> |
66 | | - <Tab> |
67 | | - <TabTitle>{t('Legal.PrivacyPolicy')}</TabTitle> |
68 | | - </Tab> |
69 | | - <Tab> |
70 | | - <TabTitle>{t('Legal.TermsOfUse')}</TabTitle> |
71 | | - </Tab> |
72 | | - <Tab> |
73 | | - <TabTitle>{t('Legal.CodeOfConduct')}</TabTitle> |
74 | | - </Tab> |
75 | | - </StyledTabList> |
76 | | - <TabPanel> |
77 | | - <PrivacyPolicy /> |
78 | | - </TabPanel> |
79 | | - <TabPanel> |
80 | | - <TermsOfUse /> |
81 | | - </TabPanel> |
82 | | - <TabPanel> |
83 | | - <CodeOfConduct /> |
84 | | - </TabPanel> |
85 | | - </Tabs> |
| 44 | + <StyledTabList className="dashboard-header__switcher"> |
| 45 | + <ul className="dashboard-header__tabs"> |
| 46 | + <RouterTab to="/privacy-policy">{t('Legal.PrivacyPolicy')}</RouterTab> |
| 47 | + <RouterTab to="/terms-of-use">{t('Legal.TermsOfUse')}</RouterTab> |
| 48 | + <RouterTab to="/code-of-conduct"> |
| 49 | + {t('Legal.CodeOfConduct')} |
| 50 | + </RouterTab> |
| 51 | + </ul> |
| 52 | + </StyledTabList> |
| 53 | + <PolicyContainer policy={policy} /> |
| 54 | + {isLoading && <Loader />} |
86 | 55 | </RootPage> |
87 | 56 | ); |
88 | 57 | } |
89 | 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 | + |
90 | 71 | export default Legal; |
0 commit comments