-
-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
1,021 additions
and
386 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nodeLinker: node-modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React from 'react'; | ||
import {useDispatch, useSelector, useStore} from 'react-redux'; | ||
import Link from 'next/link'; | ||
import {InferGetServerSidePropsType, NextPage} from 'next'; | ||
import { | ||
fetchDetail, | ||
selectDetailPageData, | ||
selectDetailPageId, | ||
selectDetailPageStateTimestamp, | ||
selectDetailPageSummary, | ||
wrapper, | ||
} from '../../store'; | ||
|
||
const Page: NextPage<InferGetServerSidePropsType<typeof getServerSideProps>> = ({serverTimestamp}) => { | ||
console.log('State on render', useStore().getState()); | ||
console.log('Timestamp on server: ', serverTimestamp); | ||
const dispatch = useDispatch(); | ||
const pageId = useSelector(selectDetailPageId); | ||
const pageSummary = useSelector(selectDetailPageSummary); | ||
const stateTimestamp = useSelector(selectDetailPageStateTimestamp); | ||
const data = useSelector(selectDetailPageData); | ||
|
||
console[pageSummary ? 'info' : 'warn']('Rendered pageName: ', pageSummary); | ||
|
||
if (!pageSummary || !pageId || !data) { | ||
throw new Error('Whoops! We do not have the pageId and pageSummary selector data!'); | ||
} | ||
|
||
return ( | ||
<> | ||
<div style={{backgroundColor: 'pink', padding: '20px'}}>Timestamp on server: {serverTimestamp}</div> | ||
<div style={{backgroundColor: 'lavender', padding: '20px'}}>Timestamp in state: {stateTimestamp}</div> | ||
<div className={`page${pageId}`}> | ||
<h3>{pageSummary}</h3> | ||
<Link href="/subject/1">Go id=1</Link> | ||
| ||
<Link href="/subject/2">Go id=2</Link> | ||
| ||
<Link href="/detail/1">Go to details id=1</Link> | ||
| ||
<Link href="/detail/2">Go to details id=2</Link> | ||
| ||
<Link href="/gipp">Go to gip page</Link> | ||
| ||
<Link href="/pokemon/pikachu">Go to Pokemon</Link> | ||
| ||
<Link href="/">Go to homepage</Link> | ||
</div> | ||
<button onClick={() => dispatch(fetchDetail(pageId))}>Refresh timestamp</button> | ||
</> | ||
); | ||
}; | ||
|
||
export const getServerSideProps = wrapper.getServerSideProps(store => async ({params}) => { | ||
const id = params?.id; | ||
if (!id || Array.isArray(id)) { | ||
throw new Error('Param id must be a string'); | ||
} | ||
|
||
await store.dispatch(fetchDetail(id)); | ||
|
||
return { | ||
props: { | ||
serverTimestamp: new Date().getTime(), | ||
}, | ||
}; | ||
}); | ||
|
||
export default Page; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react'; | ||
import {useDispatch, useSelector, useStore} from 'react-redux'; | ||
import Link from 'next/link'; | ||
import {NextPage} from 'next'; | ||
import {fetchGipp, selectGippPageData, selectGippPageStateTimestamp, selectGippPageTestData, wrapper} from '../store'; | ||
|
||
const Page: NextPage = () => { | ||
console.log('State on render', useStore().getState()); | ||
const dispatch = useDispatch(); | ||
const testData = useSelector(selectGippPageTestData); | ||
const stateTimestamp = useSelector(selectGippPageStateTimestamp); | ||
const data = useSelector(selectGippPageData); | ||
|
||
console[testData ? 'info' : 'warn']('Rendered testData: ', testData); | ||
|
||
if (!testData || !data) { | ||
throw new Error('Whoops! We do not have the data and testData selector data!'); | ||
} | ||
|
||
return ( | ||
<> | ||
<div style={{backgroundColor: 'lavender', padding: '20px'}}>Timestamp in state: {stateTimestamp}</div> | ||
<div className={`page${1}`}> | ||
<h3>{testData}</h3> | ||
<Link href="/subject/1">Go id=1</Link> | ||
| ||
<Link href="/subject/2">Go id=2</Link> | ||
| ||
<Link href="/detail/1">Go to details id=1</Link> | ||
| ||
<Link href="/detail/2">Go to details id=2</Link> | ||
| ||
<Link href="/pokemon/pikachu">Go to Pokemon</Link> | ||
| ||
<Link href="/">Go to homepage</Link> | ||
</div> | ||
<button onClick={() => dispatch(fetchGipp())}>Refresh timestamp</button> | ||
</> | ||
); | ||
}; | ||
|
||
Page.getInitialProps = wrapper.getInitialPageProps(store => async () => { | ||
await store.dispatch(fetchGipp()); | ||
return {}; | ||
}); | ||
|
||
export default Page; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.