-
-
Notifications
You must be signed in to change notification settings - Fork 893
/
tutorials.js
79 lines (69 loc) · 2.17 KB
/
tutorials.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import PropTypes from 'prop-types';
import Head from 'next/head';
import Header from '../components/HomeHeader';
import Footer from '../components/HomeFooter';
import SubscribeForm from '../components/SubscribeForm';
import withLayout from '../lib/withLayout';
import withAuth from '../lib/withAuth';
import { getTutorials } from '../lib/api/public';
import { styleH1 } from '../components/SharedStyles';
const styleExcerpt = {
margin: '0px 20px',
opacity: '0.75',
fontSize: '13px',
};
function renderTutorials(tutorialItem) {
return (
<li style={{ padding: '20px 0px' }} key={tutorialItem.order}>
<a href={tutorialItem.link} target="_blank">
{tutorialItem.title}
</a>{' '}
<span style={{ fontSize: '12px', fontWeight: '400' }}>({tutorialItem.domain})</span>
<p style={styleExcerpt}>{tutorialItem.excerpt}</p>
</li>
);
}
const Tutorials = ({ user, tutorials }) => (
<div>
<Head>
<title>Tutorials at builderbook.org</title>
<meta
name="description"
content="Practical tutorials on JavaScript, React, Next, Express, Mongoose, MongoDB, Node."
/>
</Head>
<Header user={user} />
<div style={{ padding: '10px 18%', fontSize: '15px' }}>
<br />
<h1 style={styleH1}>Our tutorials</h1>
<p style={{ margin: '0px 20px', textAlign: 'center' }}>Get notified about new tutorials:</p>
<SubscribeForm />
{tutorials && tutorials.length > 0 ? (
<div style={{ margin: '20px 0px 400px 0px' }}>
{tutorials.map(tutorialItem => renderTutorials(tutorialItem))}
</div>
) : null}
<br />
</div>
<Footer />
</div>
);
Tutorials.propTypes = {
user: PropTypes.shape({
_id: PropTypes.string.isRequired,
}),
tutorials: PropTypes.arrayOf(PropTypes.object).isRequired,
};
Tutorials.defaultProps = {
user: null,
};
Tutorials.getInitialProps = async function getInitialProps() {
let tutorials;
try {
tutorials = await getTutorials({ slug: 'builder-book' });
} catch (error) {
console.log(error); // eslint-disable-line
}
return { tutorials };
};
export default withAuth(withLayout(Tutorials, { noHeader: true }), { loginRequired: false });