-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import axios from "axios"; | ||
import { SET_ARTICLE_DETAILS } from "./types"; | ||
|
||
export function fetchArticleDetails() { | ||
return function(dispatch) { | ||
return axios.get("https://api.myjson.com/bins/19dtxc").then(({ data }) => { | ||
dispatch(setArticleDetails(data)); | ||
}); | ||
}; | ||
} | ||
|
||
function setArticleDetails(data) { | ||
return { | ||
type: SET_ARTICLE_DETAILS, | ||
payload: data | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const FETCH_ARTICLE_DETAILS = "FETCH_ARTICLE_DETAILS"; | ||
export const SET_ARTICLE_DETAILS = "SET_ARTICLE_DETAILS"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import React, { Component } from "react"; | ||
import { connect } from "react-redux"; | ||
import styled from "styled-components"; | ||
import Article from "../components/Article"; | ||
import Clap from "../components/Clap"; | ||
import { fetchArticleDetails } from "../actions"; | ||
|
||
const StyledApp = styled.div` | ||
min-height: 100vh; | ||
|
@@ -21,6 +23,9 @@ const StyledApp = styled.div` | |
|
||
class App extends Component { | ||
state = {}; | ||
componentDidMount() { | ||
this.props.fetchArticleDetails(); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
emanuelbierman
|
||
} | ||
render() { | ||
return ( | ||
<StyledApp> | ||
|
@@ -35,4 +40,12 @@ class App extends Component { | |
} | ||
} | ||
|
||
export default App; | ||
const mapStateToProps = ({ data = {} }) => ({ | ||
data | ||
}); | ||
export default connect( | ||
mapStateToProps, | ||
{ | ||
fetchArticleDetails | ||
} | ||
)(App); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
import React from "react"; | ||
import ReactDOM from "react-dom"; | ||
import { Provider } from "react-redux"; | ||
import "./index.css"; | ||
import App from "./containers/App"; | ||
import registerServiceWorker from "./registerServiceWorker"; | ||
import store from "./store"; | ||
|
||
ReactDOM.render(<App />, document.getElementById("root")); | ||
ReactDOM.render( | ||
<Provider store={store}> | ||
<App /> | ||
</Provider>, | ||
document.getElementById("root") | ||
); | ||
registerServiceWorker(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { SET_ARTICLE_DETAILS } from "../actions/types"; | ||
|
||
export default function(state = {}, action) { | ||
switch (action.type) { | ||
case SET_ARTICLE_DETAILS: | ||
return { data: action.payload }; | ||
default: | ||
return state; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { createStore, applyMiddleware } from "redux"; | ||
import thunk from "redux-thunk"; | ||
import rootReducer from "../reducers"; | ||
|
||
const store = createStore(rootReducer, applyMiddleware(thunk)); | ||
export default store; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -336,6 +336,13 @@ aws4@^1.6.0: | |
version "1.8.0" | ||
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f" | ||
|
||
axios@^0.18.0: | ||
version "0.18.0" | ||
resolved "https://registry.yarnpkg.com/axios/-/axios-0.18.0.tgz#32d53e4851efdc0a11993b6cd000789d70c05102" | ||
dependencies: | ||
follow-redirects "^1.3.0" | ||
is-buffer "^1.1.5" | ||
|
||
axobject-query@^0.1.0: | ||
version "0.1.0" | ||
resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-0.1.0.tgz#62f59dbc59c9f9242759ca349960e7a2fe3c36c0" | ||
|
@@ -2805,7 +2812,7 @@ flatten@^1.0.2: | |
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.2.tgz#dae46a9d78fbe25292258cc1e780a41d95c03782" | ||
|
||
follow-redirects@^1.0.0: | ||
follow-redirects@^1.0.0, follow-redirects@^1.3.0: | ||
version "1.5.2" | ||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.2.tgz#5a9d80e0165957e5ef0c1210678fc5c4acb9fb03" | ||
dependencies: | ||
|
@@ -3387,7 +3394,7 @@ interpret@^1.0.0: | |
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.1.0.tgz#7ed1b1410c6a0e0f78cf95d3b8440c63f78b8614" | ||
|
||
invariant@^2.2.2: | ||
invariant@^2.0.0, invariant@^2.2.2: | ||
version "2.2.4" | ||
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6" | ||
dependencies: | ||
|
@@ -4230,6 +4237,10 @@ locate-path@^2.0.0: | |
p-locate "^2.0.0" | ||
path-exists "^3.0.0" | ||
|
||
lodash-es@^4.17.5: | ||
version "4.17.10" | ||
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.10.tgz#62cd7104cdf5dd87f235a837f0ede0e8e5117e05" | ||
|
||
lodash._reinterpolate@~3.0.0: | ||
version "3.0.0" | ||
resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d" | ||
|
@@ -4271,7 +4282,7 @@ lodash.uniq@^4.5.0: | |
version "4.5.0" | ||
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" | ||
|
||
"lodash@>=3.5 <5", lodash@^4.15.0, lodash@^4.17.10, lodash@^4.17.2, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.3.0: | ||
"lodash@>=3.5 <5", lodash@^4.15.0, lodash@^4.17.10, lodash@^4.17.2, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.3.0: | ||
version "4.17.10" | ||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7" | ||
|
||
|
@@ -5589,6 +5600,17 @@ react-is@^16.3.1: | |
version "16.4.2" | ||
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.4.2.tgz#84891b56c2b6d9efdee577cc83501dfc5ecead88" | ||
|
||
react-redux@^5.0.7: | ||
version "5.0.7" | ||
resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-5.0.7.tgz#0dc1076d9afb4670f993ffaef44b8f8c1155a4c8" | ||
dependencies: | ||
hoist-non-react-statics "^2.5.0" | ||
invariant "^2.0.0" | ||
lodash "^4.17.5" | ||
lodash-es "^4.17.5" | ||
loose-envify "^1.1.0" | ||
prop-types "^15.6.0" | ||
|
||
[email protected]: | ||
version "1.1.4" | ||
resolved "https://registry.yarnpkg.com/react-scripts/-/react-scripts-1.1.4.tgz#d5c230e707918d6dd2d06f303b10f5222d017c88" | ||
|
@@ -5730,6 +5752,17 @@ reduce-function-call@^1.0.1: | |
dependencies: | ||
balanced-match "^0.4.2" | ||
|
||
redux-thunk@^2.3.0: | ||
version "2.3.0" | ||
resolved "https://registry.yarnpkg.com/redux-thunk/-/redux-thunk-2.3.0.tgz#51c2c19a185ed5187aaa9a2d08b666d0d6467622" | ||
|
||
redux@^4.0.0: | ||
version "4.0.0" | ||
resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.0.tgz#aa698a92b729315d22b34a0553d7e6533555cc03" | ||
dependencies: | ||
loose-envify "^1.1.0" | ||
symbol-observable "^1.2.0" | ||
|
||
regenerate@^1.2.1: | ||
version "1.4.0" | ||
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11" | ||
|
@@ -6505,6 +6538,10 @@ sw-toolbox@^3.4.0: | |
path-to-regexp "^1.0.1" | ||
serviceworker-cache-polyfill "^4.0.0" | ||
|
||
symbol-observable@^1.2.0: | ||
version "1.2.0" | ||
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804" | ||
|
||
symbol-tree@^3.2.1: | ||
version "3.2.2" | ||
resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.2.tgz#ae27db38f660a7ae2e1c3b7d1bc290819b8519e6" | ||
|
I don't understand this line, how did
fetchArticleDetails
end up inthis.props
?