Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
38 changes: 13 additions & 25 deletions pages/_app.js
Original file line number Diff line number Diff line change
@@ -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 (
<Container>
<Provider store={store}>
<div style={{
maxWidth: '960px',
margin: '50px auto',
}}
>
<Link href="/">
<a>Homepage</a>
</Link>
<Component {...pageProps} />
</div>
</Provider>
</Container>
<Provider store={store}>
<div style={{
maxWidth: '960px',
margin: '50px auto',
}}
>
<Link href="/">
<a>Homepage</a>
</Link>
<Component {...pageProps} />
</div>
</Provider>
)
}
}
Expand Down
5 changes: 3 additions & 2 deletions pages/_document.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import Document, {
Head,
Html,
Main,
NextScript,
} from 'next/document';
Expand All @@ -14,15 +15,15 @@ export default class MyDocument extends Document {

render() {
return (
<html lang="en">
<Html lang="en">
<Head>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.2/semantic.min.css" />
</Head>
<body>
<Main />
<NextScript />
</body>
</html>
</Html>
);
}
}
15 changes: 9 additions & 6 deletions pages/card.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import { connect } from 'react-redux';
import initsStore from '../app/store';

import {
Card,
Expand All @@ -19,14 +18,13 @@ class CardDetails extends React.Component {
await store.dispatch(fetchCardDetails(query.id));
}

return {};
return card;
}

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 (
<Layout>
{ card ? <Card style={{ margin: '0 auto' }}>
Expand All @@ -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);

23 changes: 13 additions & 10 deletions pages/index.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -16,11 +16,6 @@ import { fetchRandomCard } from '../app/actions/cardsActions';
import Layout from '../app/components/Layout';

class Home extends React.Component {
static getInitialProps({ store }) {
this.store = store;
return {};
}

constructor(props) {
super(props);
this.state = {
Expand Down Expand Up @@ -55,12 +50,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 },
});
}

Expand Down Expand Up @@ -104,4 +98,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);

17 changes: 9 additions & 8 deletions pages/search.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -14,14 +13,12 @@ class Search extends React.Component {
static async getInitialProps({ store, query }) {
const searchPhrase = query.q;
const selectedFormat = query.f;
await store.dispatch(fetchCards(selectedFormat, searchPhrase));

return {};
return await store.dispatch(fetchCards(selectedFormat, searchPhrase));
}

render() {
const store = this.props.getState();
const cards = store.cards.results.map((card => (
const cards = this.props.cards.results.map((card => (
<Table.Row key={card.id}>
<Table.Cell>
<Link href={{ pathname: '/card', query: { id: card.id } }}>
Expand All @@ -33,7 +30,7 @@ class Search extends React.Component {
<Table.Cell>{ card.eur ? `${card.eur}€` : 'N/A' }</Table.Cell>
</Table.Row>
)));
const errors = store.cards.errors.map((error, index) => (
const errors = this.props.cards.errors.map((error, index) => (
<Table.Row textAlign="center" key={index}>
<Table.Cell colSpan="4">{ error }</Table.Cell>
</Table.Row>
Expand All @@ -52,12 +49,16 @@ class Search extends React.Component {
</Table.Header>
<Table.Body>
{ cards }
{ errors }
{ this.props.cards.errors && errors }
</Table.Body>
</Table>
</Layout>
);
}
}

export default connect(initsStore)(Search);
const mapStateToProps = state => ({
cards: state.cards,
});

export default connect(mapStateToProps)(Search);
Loading