From 59f790e7dd6c910c77a68be9ee19175a50aedd9d Mon Sep 17 00:00:00 2001
From: Paulina Prokop
Date: Fri, 22 Feb 2019 11:04:08 +0100
Subject: [PATCH 1/2] Modify pages
---
pages/card.js | 13 ++++++++-----
pages/index.js | 18 +++++++++++++-----
pages/search.js | 14 ++++++++------
3 files changed, 29 insertions(+), 16 deletions(-)
diff --git a/pages/card.js b/pages/card.js
index 5960634..92e54fb 100644
--- a/pages/card.js
+++ b/pages/card.js
@@ -1,6 +1,5 @@
import React from 'react';
import { connect } from 'react-redux';
-import initsStore from '../app/store';
import {
Card,
@@ -23,10 +22,9 @@ class CardDetails extends React.Component {
}
render() {
- const store = this.props.getState();
- const card = store.cards.details;
+ const card = this.props.cards.details;
- const { errors } = store.cards;
+ const { errors } = this.props.cards;
return (
{ card ?
@@ -52,4 +50,9 @@ class CardDetails extends React.Component {
}
}
-export default connect(initsStore)(CardDetails);
+const mapStateToProps = state => ({
+ cards: state.cards,
+});
+
+export default connect(mapStateToProps)(CardDetails);
+
diff --git a/pages/index.js b/pages/index.js
index ac061d8..66a16c4 100644
--- a/pages/index.js
+++ b/pages/index.js
@@ -1,7 +1,7 @@
import React from 'react';
import Router from 'next/router';
import { connect } from 'react-redux';
-import initsStore from '../app/store';
+import { bindActionCreators } from 'redux';
import {
Button,
@@ -55,12 +55,11 @@ class Home extends React.Component {
}
async findRandomCard() {
- const store = this.props.getState();
- await this.props.dispatch(fetchRandomCard());
+ await this.props.fetchRandomCard();
Router.push({
pathname: '/card',
- query: { id: store.cards.details.id },
+ query: { id: this.props.cards.details.id },
});
}
@@ -104,4 +103,13 @@ class Home extends React.Component {
}
}
-export default connect(initsStore)(Home);
+const mapStateToProps = state => ({
+ cards: state.cards,
+});
+
+const mapDispatchToProps = dispatch => bindActionCreators({
+ fetchRandomCard,
+}, dispatch);
+
+export default connect(mapStateToProps, mapDispatchToProps)(Home);
+
diff --git a/pages/search.js b/pages/search.js
index 5aae5f1..f43614c 100644
--- a/pages/search.js
+++ b/pages/search.js
@@ -1,7 +1,6 @@
import React from 'react';
import Link from 'next/link';
import { connect } from 'react-redux';
-import initsStore from '../app/store';
import {
Table,
Header,
@@ -20,8 +19,7 @@ class Search extends React.Component {
}
render() {
- const store = this.props.getState();
- const cards = store.cards.results.map((card => (
+ const cards = this.props.cards.results.map((card => (
@@ -33,7 +31,7 @@ class Search extends React.Component {
{ card.eur ? `${card.eur}€` : 'N/A' }
)));
- const errors = store.cards.errors.map((error, index) => (
+ const errors = this.props.cards.errors.map((error, index) => (
{ error }
@@ -52,7 +50,7 @@ class Search extends React.Component {
{ cards }
- { errors }
+ { this.props.cards.errors && errors }
@@ -60,4 +58,8 @@ class Search extends React.Component {
}
}
-export default connect(initsStore)(Search);
+const mapStateToProps = state => ({
+ cards: state.cards,
+});
+
+export default connect(mapStateToProps)(Search);
From ac15d71706fa662072852e888d0d26dfa46a68ad Mon Sep 17 00:00:00 2001
From: Marcin Wasilewski
Date: Thu, 17 Oct 2019 12:51:28 +0200
Subject: [PATCH 2/2] Update all dependencies and application to next.js 9
---
package.json | 16 +-
pages/_app.js | 38 +-
pages/_document.js | 5 +-
pages/card.js | 2 +-
pages/index.js | 5 -
pages/search.js | 3 +-
yarn.lock | 4095 ++++++++++++++++++++++++++++++--------------
7 files changed, 2824 insertions(+), 1340 deletions(-)
diff --git a/package.json b/package.json
index 98a35b4..c5574b1 100644
--- a/package.json
+++ b/package.json
@@ -5,15 +5,15 @@
"start": "next start"
},
"dependencies": {
- "next": "^8.0.1",
- "next-redux-wrapper": "^3.0.0-alpha.1",
- "node-fetch": "^2.3.0",
- "react": "^16.8.2",
- "react-dom": "^16.8.2",
- "react-redux": "^6.0.1",
- "redux": "^4.0.1",
+ "next": "^9.1.1",
+ "next-redux-wrapper": "^4.0.1",
+ "node-fetch": "^2.6.0",
+ "react": "^16.10.2",
+ "react-dom": "^16.10.2",
+ "react-redux": "^7.1.1",
+ "redux": "^4.0.4",
"redux-devtools-extension": "^2.13.8",
"redux-thunk": "^2.3.0",
- "semantic-ui-react": "^0.85.0"
+ "semantic-ui-react": "^0.88.1"
}
}
diff --git a/pages/_app.js b/pages/_app.js
index eb589d9..24cff4d 100644
--- a/pages/_app.js
+++ b/pages/_app.js
@@ -1,40 +1,28 @@
import React from 'react'
import Link from 'next/link';
-import App, { Container } from 'next/app'
+import App from 'next/app'
import { Provider } from 'react-redux';
import withRedux from 'next-redux-wrapper';
import initsStore from '../app/store';
class MyApp extends App {
- static async getInitialProps({ Component, ctx, store }) {
- let pageProps = {}
-
- if (Component.getInitialProps) {
- pageProps = await Component.getInitialProps(ctx)
- }
-
- return { pageProps, store }
- }
-
render () {
const { Component, pageProps, store } = this.props
return (
-
-
-
-
-
+
+
+
)
}
}
diff --git a/pages/_document.js b/pages/_document.js
index 6d28bcf..1efba5e 100644
--- a/pages/_document.js
+++ b/pages/_document.js
@@ -1,6 +1,7 @@
import React from 'react';
import Document, {
Head,
+ Html,
Main,
NextScript,
} from 'next/document';
@@ -14,7 +15,7 @@ export default class MyDocument extends Document {
render() {
return (
-
+
@@ -22,7 +23,7 @@ export default class MyDocument extends Document {
-
+