Skip to content

Commit 9e78643

Browse files
committed
book update Ch 9, comment for getServerSideProps
1 parent 152cf0f commit 9e78643

File tree

32 files changed

+6202
-6893
lines changed

32 files changed

+6202
-6893
lines changed

book/5-end/pages/public/read-chapter.jsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,32 @@ class ReadChapter extends React.Component {
126126
ReadChapter.propTypes = propTypes;
127127
ReadChapter.defaultProps = defaultProps;
128128

129+
// export async function getServerSideProps(context) {
130+
// const { bookSlug, chapterSlug, buy, checkout_canceled, error } = context.query;
131+
// const { req } = context;
132+
133+
// const headers = {};
134+
// if (req && req.headers && req.headers.cookie) {
135+
// headers.cookie = req.headers.cookie;
136+
// }
137+
138+
// try {
139+
// const chapter = await getChapterDetailApiMethod({ bookSlug, chapterSlug }, { headers });
140+
// const redirectToCheckout = !!buy;
141+
142+
// return {
143+
// props: {
144+
// chapter,
145+
// redirectToCheckout,
146+
// checkoutCanceled: !!checkout_canceled,
147+
// error: !error ? null : error,
148+
// },
149+
// };
150+
// } catch (err) {
151+
// return { props: {} };
152+
// }
153+
// }
154+
155+
// see our explanation for not using getServerSideProps at this time: https://github.com/async-labs/builderbook/issues/514
156+
129157
export default withAuth(ReadChapter, { loginRequired: false });

book/6-begin/pages/public/read-chapter.jsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,32 @@ class ReadChapter extends React.Component {
126126
ReadChapter.propTypes = propTypes;
127127
ReadChapter.defaultProps = defaultProps;
128128

129+
// export async function getServerSideProps(context) {
130+
// const { bookSlug, chapterSlug, buy, checkout_canceled, error } = context.query;
131+
// const { req } = context;
132+
133+
// const headers = {};
134+
// if (req && req.headers && req.headers.cookie) {
135+
// headers.cookie = req.headers.cookie;
136+
// }
137+
138+
// try {
139+
// const chapter = await getChapterDetailApiMethod({ bookSlug, chapterSlug }, { headers });
140+
// const redirectToCheckout = !!buy;
141+
142+
// return {
143+
// props: {
144+
// chapter,
145+
// redirectToCheckout,
146+
// checkoutCanceled: !!checkout_canceled,
147+
// error: !error ? null : error,
148+
// },
149+
// };
150+
// } catch (err) {
151+
// return { props: {} };
152+
// }
153+
// }
154+
155+
// see our explanation for not using getServerSideProps at this time: https://github.com/async-labs/builderbook/issues/514
156+
129157
export default withAuth(ReadChapter, { loginRequired: false });

book/6-end/pages/public/read-chapter.jsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,32 @@ class ReadChapter extends React.Component {
126126
ReadChapter.propTypes = propTypes;
127127
ReadChapter.defaultProps = defaultProps;
128128

129+
// export async function getServerSideProps(context) {
130+
// const { bookSlug, chapterSlug, buy, checkout_canceled, error } = context.query;
131+
// const { req } = context;
132+
133+
// const headers = {};
134+
// if (req && req.headers && req.headers.cookie) {
135+
// headers.cookie = req.headers.cookie;
136+
// }
137+
138+
// try {
139+
// const chapter = await getChapterDetailApiMethod({ bookSlug, chapterSlug }, { headers });
140+
// const redirectToCheckout = !!buy;
141+
142+
// return {
143+
// props: {
144+
// chapter,
145+
// redirectToCheckout,
146+
// checkoutCanceled: !!checkout_canceled,
147+
// error: !error ? null : error,
148+
// },
149+
// };
150+
// } catch (err) {
151+
// return { props: {} };
152+
// }
153+
// }
154+
155+
// see our explanation for not using getServerSideProps at this time: https://github.com/async-labs/builderbook/issues/514
156+
129157
export default withAuth(ReadChapter, { loginRequired: false });

book/7-begin/pages/public/read-chapter.jsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,32 @@ class ReadChapter extends React.Component {
126126
ReadChapter.propTypes = propTypes;
127127
ReadChapter.defaultProps = defaultProps;
128128

129+
// export async function getServerSideProps(context) {
130+
// const { bookSlug, chapterSlug, buy, checkout_canceled, error } = context.query;
131+
// const { req } = context;
132+
133+
// const headers = {};
134+
// if (req && req.headers && req.headers.cookie) {
135+
// headers.cookie = req.headers.cookie;
136+
// }
137+
138+
// try {
139+
// const chapter = await getChapterDetailApiMethod({ bookSlug, chapterSlug }, { headers });
140+
// const redirectToCheckout = !!buy;
141+
142+
// return {
143+
// props: {
144+
// chapter,
145+
// redirectToCheckout,
146+
// checkoutCanceled: !!checkout_canceled,
147+
// error: !error ? null : error,
148+
// },
149+
// };
150+
// } catch (err) {
151+
// return { props: {} };
152+
// }
153+
// }
154+
155+
// see our explanation for not using getServerSideProps at this time: https://github.com/async-labs/builderbook/issues/514
156+
129157
export default withAuth(ReadChapter, { loginRequired: false });

book/7-end/pages/public/read-chapter.jsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,4 +333,32 @@ class ReadChapter extends React.Component {
333333
ReadChapter.propTypes = propTypes;
334334
ReadChapter.defaultProps = defaultProps;
335335

336+
// export async function getServerSideProps(context) {
337+
// const { bookSlug, chapterSlug, buy, checkout_canceled, error } = context.query;
338+
// const { req } = context;
339+
340+
// const headers = {};
341+
// if (req && req.headers && req.headers.cookie) {
342+
// headers.cookie = req.headers.cookie;
343+
// }
344+
345+
// try {
346+
// const chapter = await getChapterDetailApiMethod({ bookSlug, chapterSlug }, { headers });
347+
// const redirectToCheckout = !!buy;
348+
349+
// return {
350+
// props: {
351+
// chapter,
352+
// redirectToCheckout,
353+
// checkoutCanceled: !!checkout_canceled,
354+
// error: !error ? null : error,
355+
// },
356+
// };
357+
// } catch (err) {
358+
// return { props: {} };
359+
// }
360+
// }
361+
362+
// see our explanation for not using getServerSideProps at this time: https://github.com/async-labs/builderbook/issues/514
363+
336364
export default withAuth(ReadChapter, { loginRequired: false });

book/8-begin/pages/public/read-chapter.jsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,4 +332,32 @@ class ReadChapter extends React.Component {
332332
ReadChapter.propTypes = propTypes;
333333
ReadChapter.defaultProps = defaultProps;
334334

335+
// export async function getServerSideProps(context) {
336+
// const { bookSlug, chapterSlug, buy, checkout_canceled, error } = context.query;
337+
// const { req } = context;
338+
339+
// const headers = {};
340+
// if (req && req.headers && req.headers.cookie) {
341+
// headers.cookie = req.headers.cookie;
342+
// }
343+
344+
// try {
345+
// const chapter = await getChapterDetailApiMethod({ bookSlug, chapterSlug }, { headers });
346+
// const redirectToCheckout = !!buy;
347+
348+
// return {
349+
// props: {
350+
// chapter,
351+
// redirectToCheckout,
352+
// checkoutCanceled: !!checkout_canceled,
353+
// error: !error ? null : error,
354+
// },
355+
// };
356+
// } catch (err) {
357+
// return { props: {} };
358+
// }
359+
// }
360+
361+
// see our explanation for not using getServerSideProps at this time: https://github.com/async-labs/builderbook/issues/514
362+
335363
export default withAuth(ReadChapter, { loginRequired: false });

book/8-end/pages/public/read-chapter.jsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,34 @@ class ReadChapter extends React.Component {
373373
ReadChapter.propTypes = propTypes;
374374
ReadChapter.defaultProps = defaultProps;
375375

376+
// export async function getServerSideProps(context) {
377+
// const { bookSlug, chapterSlug, buy, checkout_canceled, error } = context.query;
378+
// const { req } = context;
379+
380+
// const headers = {};
381+
// if (req && req.headers && req.headers.cookie) {
382+
// headers.cookie = req.headers.cookie;
383+
// }
384+
385+
// try {
386+
// const chapter = await getChapterDetailApiMethod({ bookSlug, chapterSlug }, { headers });
387+
// const redirectToCheckout = !!buy;
388+
389+
// return {
390+
// props: {
391+
// chapter,
392+
// redirectToCheckout,
393+
// checkoutCanceled: !!checkout_canceled,
394+
// error: !error ? null : error,
395+
// },
396+
// };
397+
// } catch (err) {
398+
// return { props: {} };
399+
// }
400+
// }
401+
402+
// see our explanation for not using getServerSideProps at this time: https://github.com/async-labs/builderbook/issues/514
403+
376404
export default withAuth(withRouter(ReadChapter), {
377405
loginRequired: false,
378406
});

book/9-begin/pages/public/read-chapter.jsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,34 @@ class ReadChapter extends React.Component {
373373
ReadChapter.propTypes = propTypes;
374374
ReadChapter.defaultProps = defaultProps;
375375

376+
// export async function getServerSideProps(context) {
377+
// const { bookSlug, chapterSlug, buy, checkout_canceled, error } = context.query;
378+
// const { req } = context;
379+
380+
// const headers = {};
381+
// if (req && req.headers && req.headers.cookie) {
382+
// headers.cookie = req.headers.cookie;
383+
// }
384+
385+
// try {
386+
// const chapter = await getChapterDetailApiMethod({ bookSlug, chapterSlug }, { headers });
387+
// const redirectToCheckout = !!buy;
388+
389+
// return {
390+
// props: {
391+
// chapter,
392+
// redirectToCheckout,
393+
// checkoutCanceled: !!checkout_canceled,
394+
// error: !error ? null : error,
395+
// },
396+
// };
397+
// } catch (err) {
398+
// return { props: {} };
399+
// }
400+
// }
401+
402+
// see our explanation for not using getServerSideProps at this time: https://github.com/async-labs/builderbook/issues/514
403+
376404
export default withAuth(withRouter(ReadChapter), {
377405
loginRequired: false,
378406
});

book/9-end-functional/components/Header.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ function Header({ user, hideHeader, redirectUrl }) {
115115
pathname: '/login',
116116
query: { redirectUrl },
117117
}}
118+
style={{ margin: '0px 20px 0px auto' }}
118119
>
119-
<a style={{ margin: '0px 20px 0px auto' }}>Log in</a>
120+
Log in
120121
</Link>
121122
)}
122123
</Grid>

book/9-end-functional/lib/withAuth.jsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,7 @@ export default function withAuth(
6767
return null;
6868
}
6969

70-
return (
71-
<>
72-
<BaseComponent {...this.props} />
73-
</>
74-
);
70+
return <BaseComponent {...this.props} />;
7571
}
7672
}
7773

0 commit comments

Comments
 (0)