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

first commit #223

Open
wants to merge 1 commit 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
30 changes: 19 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"name": "redux-simple-starter",
"name": "blog",
"version": "1.0.0",
"description": "Simple starter package for Redux with React and Babel support",
"description":
"Simple starter package for Redux with React and Babel support",
"main": "index.js",
"repository": "[email protected]:StephenGrider/ReduxSimpleStarter.git",
"scripts": {
"start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js",
"test": "mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test",
"test":
"mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test",
"test:watch": "npm run test -- --watch"
},
"author": "",
Expand All @@ -26,12 +28,18 @@
"webpack-dev-server": "^1.14.0"
},
"dependencies": {
"babel-preset-stage-1": "^6.1.18",
"lodash": "^3.10.1",
"react": "^0.14.3",
"react-dom": "^0.14.3",
"react-redux": "4.3.0",
"react-router": "^2.0.1",
"redux": "^3.0.4"
}
"axios": "0.18.0",
"babel-preset-stage-1": "6.24.1",
"bootstrap": "4.1.0",
"lodash": "4.17.5",
"react": "16.3.1",
"react-bootstrap": "0.32.1",
"react-dom": "16.3.1",
"react-redux": "5.0.7",
"react-router": "4.2.0",
"react-router-dom": "4.2.2",
"redux": "3.7.2",
"redux-promise": "0.5.3"
},
"keywords": []
}
14 changes: 14 additions & 0 deletions src/actions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import axios from "axios";

const URL = "https://reduxblog.herokuapp.com/api/posts"
const MainURL = `${URL}?key=st0539`;

export const ALLPOSTS = "allposts";

export function allposts() {
const request = axios.get(MainURL);
return {
type: ALLPOSTS,
payload: request
};
}
7 changes: 7 additions & 0 deletions src/components/NewPost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React, { Component } from "react";

export default class NewPost extends Component {
render() {
return <div> New Post </div>;
}
}
64 changes: 64 additions & 0 deletions src/components/PostIndex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React, { Component } from "react";
import { connect } from 'react-redux';
import _ from 'lodash';

import {allposts} from '../actions/index';
class PostIndex extends Component {

componentDidMount(){
this.props.allposts();
}
renderList(){
return _.map(this.props.posts , post => {
return (
<li key = {post.id} className= "list-group-item" >
{post.title}
</li>
);
} );
}
render() {
console.log(this.props.posts)
return (
<div>
<h2> Blog Posts!! </h2>
<ul className ="list-group">
{this.renderList()}
</ul>
<div className="card card-outline-danger mb-3 text-center">
<div className="card-block">
<blockquote className="card-blockquote">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.</p>
<footer>Someone famous in <cite title="Source Title">Source Title</cite></footer>
</blockquote>
</div>
</div>
</div>
);
}
}

function mapStateToProps(state){
return{
posts: state.posts
}
}

export default connect(mapStateToProps , { allposts })(PostIndex)

















7 changes: 7 additions & 0 deletions src/components/ShowPost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React, { Component } from "react";

export default class ShowPost extends Component {
render() {
return <div> Show Post </div>;
}
}
9 changes: 0 additions & 9 deletions src/components/app.js

This file was deleted.

34 changes: 23 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import React from "react";
import ReactDOM from "react-dom";
import { Provider } from "react-redux";
import { createStore, applyMiddleware } from "redux";
import PostIndex from "./components/PostIndex";
import NewPost from "./components/NewPost";
import ShowPost from "./components/ShowPost";
import reducers from "./reducers";
import { BrowserRouter, Route, Link, Switch } from "react-router-dom";
import ReducerPromise from "redux-promise";

import App from './components/app';
import reducers from './reducers';

const createStoreWithMiddleware = applyMiddleware()(createStore);
const createStoreWithMiddleware = applyMiddleware(ReducerPromise)(createStore);

ReactDOM.render(
<Provider store={createStoreWithMiddleware(reducers)}>
<App />
</Provider>
, document.querySelector('.container'));
<BrowserRouter>
<div>
<Switch>
<Route exact path="/" component={PostIndex} />
<Route path="/post/new" component={NewPost} />
<Route path="/post/:id" component={ShowPost} />
</Switch>
</div>
</BrowserRouter>
</Provider>,
document.querySelector(".container")
);
12 changes: 12 additions & 0 deletions src/reducers/MainReducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import _ from "lodash";
import { ALLPOSTS } from "../actions";

export default function(state = {}, action) {
switch (action.type) {

case ALLPOSTS:
return _.mapKeys(action.payload.data, "id");
default:
return state;
}
}
6 changes: 3 additions & 3 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { combineReducers } from 'redux';

import { combineReducers } from "redux";
import MainReducer from "./MainReducer";
const rootReducer = combineReducers({
state: (state = {}) => state
posts: MainReducer
});

export default rootReducer;