Added some api and state actions
This commit is contained in:
parent
ac3c1b2060
commit
930708ffec
|
|
@ -1,9 +1,9 @@
|
|||
import github from '../apis/github';
|
||||
import api from '../apis/api';
|
||||
|
||||
export const getUser = (username) => async (dispatch, getState) => {
|
||||
const response = await github.get(`/users/${username}`);
|
||||
|
||||
console.log(response.data);
|
||||
|
||||
dispatch({
|
||||
type: 'GET_USER',
|
||||
|
|
@ -20,6 +20,20 @@ export const getRepos = (username) => async (dispatch, getState) => {
|
|||
});
|
||||
};
|
||||
|
||||
export const getArticles = async (dispatch, getState) => {
|
||||
const state = getState();
|
||||
|
||||
if (!state.articles || state.articles.length <= 0){
|
||||
const response = await api.get(`/articles`); // axios request for articles json file
|
||||
|
||||
dispatch({
|
||||
type: 'GET_ARTICLES',
|
||||
payload: response.data,
|
||||
});
|
||||
return response;
|
||||
}
|
||||
};
|
||||
|
||||
export const updateEmailBody = (event) => async (dispatch, getState) => {
|
||||
// Update the email body
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
import axios from 'axios';
|
||||
|
||||
// Axios request used to make requests to api.github.com
|
||||
|
||||
export default axios.create({
|
||||
baseURL: '/api' // Change if a real api server is created
|
||||
});
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import './css/Articles.css';
|
||||
import Theater from './subcomponents/Theater';
|
||||
import Article from './Article';
|
||||
import { getArticles} from '../actions/index';
|
||||
import { Route, Link } from 'react-router-dom';
|
||||
|
||||
|
||||
|
|
@ -20,7 +22,7 @@ class Articles extends React.Component {
|
|||
|
||||
return (
|
||||
<div>
|
||||
"Articles"
|
||||
{this.props.getArticles()}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -49,5 +51,9 @@ class Articles extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = (state) => {
|
||||
return { articles: state.articles.articles};
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, { getArticles })(Articles);
|
||||
|
||||
export default Articles;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
let articleReducer = (state={articles=[]}, action) => {
|
||||
let articlesReducer = (state={articles: []}, action) => {
|
||||
switch(action.type) {
|
||||
case "GET_ARTICLES":
|
||||
return { ...state, articles: action.payload };
|
||||
|
|
@ -9,4 +9,4 @@ let articleReducer = (state={articles=[]}, action) => {
|
|||
};
|
||||
|
||||
|
||||
export default articleReducer;
|
||||
export default articlesReducer;
|
||||
|
|
@ -4,10 +4,12 @@ import githubReducer from './githubReducer';
|
|||
import contactModalReducer from "./contactModalReducer";
|
||||
import introReducer from "./introReducer";
|
||||
import navigationReducer from "./navigationReducer";
|
||||
import articlesReducer from "./articlesReducer";
|
||||
|
||||
export default combineReducers({
|
||||
github: githubReducer,
|
||||
contactModal: contactModalReducer,
|
||||
intro: introReducer,
|
||||
navigation: navigationReducer,
|
||||
articles: articlesReducer,
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue