Skip to content

Commit

Permalink
prettier codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenGrider committed Jun 16, 2017
1 parent 14ce76d commit 2de8c92
Show file tree
Hide file tree
Showing 35 changed files with 236 additions and 226 deletions.
22 changes: 12 additions & 10 deletions blog/src/actions/index.js
@@ -1,12 +1,12 @@
import axios from 'axios';
import axios from "axios";

export const FETCH_POSTS = 'fetch_posts';
export const FETCH_POST = 'fetch_post';
export const CREATE_POST = 'create_post';
export const DELETE_POST = 'delete_post';
export const FETCH_POSTS = "fetch_posts";
export const FETCH_POST = "fetch_post";
export const CREATE_POST = "create_post";
export const DELETE_POST = "delete_post";

const ROOT_URL = 'http://reduxblog.herokuapp.com/api';
const API_KEY = '?key=PAPERCLIP1234';
const ROOT_URL = "http://reduxblog.herokuapp.com/api";
const API_KEY = "?key=PAPERCLIP1234";

export function fetchPosts() {
const request = axios.get(`${ROOT_URL}/posts${API_KEY}`);
Expand All @@ -18,7 +18,8 @@ export function fetchPosts() {
}

export function createPost(values, callback) {
const request = axios.post(`${ROOT_URL}/posts${API_KEY}`, values)
const request = axios
.post(`${ROOT_URL}/posts${API_KEY}`, values)
.then(() => callback());

return {
Expand All @@ -37,11 +38,12 @@ export function fetchPost(id) {
}

export function deletePost(id, callback) {
const request = axios.delete(`${ROOT_URL}/posts/${id}${API_KEY}`)
const request = axios
.delete(`${ROOT_URL}/posts/${id}${API_KEY}`)
.then(() => callback());

return {
type: DELETE_POST,
payload: id
}
};
}
10 changes: 5 additions & 5 deletions blog/src/components/posts_index.js
@@ -1,8 +1,8 @@
import _ from 'lodash';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
import { fetchPosts } from '../actions';
import _ from "lodash";
import React, { Component } from "react";
import { connect } from "react-redux";
import { Link } from "react-router-dom";
import { fetchPosts } from "../actions";

class PostsIndex extends Component {
componentDidMount() {
Expand Down
32 changes: 13 additions & 19 deletions blog/src/components/posts_new.js
@@ -1,32 +1,28 @@
import React, { Component } from 'react';
import { Field, reduxForm } from 'redux-form';
import { Link } from 'react-router-dom';
import { connect } from 'react-redux';
import { createPost } from '../actions';
import React, { Component } from "react";
import { Field, reduxForm } from "redux-form";
import { Link } from "react-router-dom";
import { connect } from "react-redux";
import { createPost } from "../actions";

class PostsNew extends Component {
renderField(field) {
const { meta: { touched, error } } = field;
const className = `form-group ${touched && error ? 'has-danger' : ''}`;
const className = `form-group ${touched && error ? "has-danger" : ""}`;

return (
<div className={className}>
<label>{field.label}</label>
<input
className="form-control"
type="text"
{...field.input}
/>
<input className="form-control" type="text" {...field.input} />
<div className="text-help">
{touched ? error : ''}
{touched ? error : ""}
</div>
</div>
);
}

onSubmit(values) {
this.props.createPost(values, () => {
this.props.history.push('/');
this.props.history.push("/");
});
}

Expand Down Expand Up @@ -66,10 +62,10 @@ function validate(values) {
errors.title = "Enter a title";
}
if (!values.categories) {
errors.categories = 'Enter some categories';
errors.categories = "Enter some categories";
}
if (!values.content) {
errors.content = 'Enter some content please';
errors.content = "Enter some content please";
}

// If errors is empty, the form is fine to submit
Expand All @@ -79,7 +75,5 @@ function validate(values) {

export default reduxForm({
validate,
form: 'PostsNewForm'
})(
connect(null,{ createPost })(PostsNew)
);
form: "PostsNewForm"
})(connect(null, { createPost })(PostsNew));
10 changes: 5 additions & 5 deletions blog/src/components/posts_show.js
@@ -1,7 +1,7 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
import { fetchPost, deletePost } from '../actions';
import React, { Component } from "react";
import { connect } from "react-redux";
import { Link } from "react-router-dom";
import { fetchPost, deletePost } from "../actions";

class PostsShow extends Component {
componentDidMount() {
Expand All @@ -13,7 +13,7 @@ class PostsShow extends Component {
const { id } = this.props.match.params;

this.props.deletePost(id, () => {
this.props.history.push('/');
this.props.history.push("/");
});
}

Expand Down
25 changes: 13 additions & 12 deletions blog/src/index.js
@@ -1,14 +1,14 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import { BrowserRouter, Route, Switch } from 'react-router-dom';
import promise from 'redux-promise';
import React from "react";
import ReactDOM from "react-dom";
import { Provider } from "react-redux";
import { createStore, applyMiddleware } from "redux";
import { BrowserRouter, Route, Switch } from "react-router-dom";
import promise from "redux-promise";

import reducers from './reducers';
import PostsIndex from './components/posts_index';
import PostsNew from './components/posts_new';
import PostsShow from './components/posts_show';
import reducers from "./reducers";
import PostsIndex from "./components/posts_index";
import PostsNew from "./components/posts_new";
import PostsShow from "./components/posts_show";

const createStoreWithMiddleware = applyMiddleware(promise)(createStore);

Expand All @@ -23,5 +23,6 @@ ReactDOM.render(
</Switch>
</div>
</BrowserRouter>
</Provider>
, document.querySelector('.container'));
</Provider>,
document.querySelector(".container")
);
6 changes: 3 additions & 3 deletions blog/src/reducers/index.js
@@ -1,6 +1,6 @@
import { combineReducers } from 'redux';
import { reducer as formReducer } from 'redux-form';
import PostsReducer from './reducer_posts';
import { combineReducers } from "redux";
import { reducer as formReducer } from "redux-form";
import PostsReducer from "./reducer_posts";

const rootReducer = combineReducers({
posts: PostsReducer,
Expand Down
20 changes: 10 additions & 10 deletions blog/src/reducers/reducer_posts.js
@@ -1,15 +1,15 @@
import _ from 'lodash';
import { FETCH_POSTS, FETCH_POST, DELETE_POST } from '../actions';
import _ from "lodash";
import { FETCH_POSTS, FETCH_POST, DELETE_POST } from "../actions";

export default function(state = {}, action) {
switch (action.type) {
case DELETE_POST:
return _.omit(state, action.payload);
case FETCH_POST:
return { ...state, [action.payload.data.id]: action.payload.data };
case FETCH_POSTS:
return _.mapKeys(action.payload.data, 'id');
default:
return state;
case DELETE_POST:
return _.omit(state, action.payload);
case FETCH_POST:
return { ...state, [action.payload.data.id]: action.payload.data };
case FETCH_POSTS:
return _.mapKeys(action.payload.data, "id");
default:
return state;
}
}
8 changes: 4 additions & 4 deletions blog/test/components/app_test.js
@@ -1,14 +1,14 @@
import { renderComponent , expect } from '../test_helper';
import App from '../../src/components/app';
import { renderComponent, expect } from "../test_helper";
import App from "../../src/components/app";

describe('App' , () => {
describe("App", () => {
let component;

beforeEach(() => {
component = renderComponent(App);
});

it('renders something', () => {
it("renders something", () => {
expect(component).to.exist;
});
});
26 changes: 13 additions & 13 deletions blog/test/test_helper.js
@@ -1,23 +1,23 @@
import _$ from 'jquery';
import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import jsdom from 'jsdom';
import chai, { expect } from 'chai';
import chaiJquery from 'chai-jquery';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import reducers from '../src/reducers';
import _$ from "jquery";
import React from "react";
import ReactDOM from "react-dom";
import TestUtils from "react-addons-test-utils";
import jsdom from "jsdom";
import chai, { expect } from "chai";
import chaiJquery from "chai-jquery";
import { Provider } from "react-redux";
import { createStore } from "redux";
import reducers from "../src/reducers";

global.document = jsdom.jsdom('<!doctype html><html><body></body></html>');
global.document = jsdom.jsdom("<!doctype html><html><body></body></html>");
global.window = global.document.defaultView;
global.navigator = global.window.navigator;
const $ = _$(window);

chaiJquery(chai, chai.util, $);

function renderComponent(ComponentClass, props = {}, state = {}) {
const componentInstance = TestUtils.renderIntoDocument(
const componentInstance = TestUtils.renderIntoDocument(
<Provider store={createStore(reducers, state)}>
<ComponentClass {...props} />
</Provider>
Expand All @@ -33,4 +33,4 @@ $.fn.simulate = function(eventName, value) {
TestUtils.Simulate[eventName](this[0]);
};

export {renderComponent, expect};
export { renderComponent, expect };
26 changes: 13 additions & 13 deletions blog/webpack.config.js
@@ -1,26 +1,26 @@
module.exports = {
entry: [
'./src/index.js'
],
entry: ["./src/index.js"],
output: {
path: __dirname,
publicPath: '/',
filename: 'bundle.js'
publicPath: "/",
filename: "bundle.js"
},
module: {
loaders: [{
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['react', 'es2015', 'stage-1']
loaders: [
{
exclude: /node_modules/,
loader: "babel",
query: {
presets: ["react", "es2015", "stage-1"]
}
}
}]
]
},
resolve: {
extensions: ['', '.js', '.jsx']
extensions: ["", ".js", ".jsx"]
},
devServer: {
historyApiFallback: true,
contentBase: './'
contentBase: "./"
}
};
2 changes: 1 addition & 1 deletion book_list/src/actions/index.js
Expand Up @@ -2,7 +2,7 @@ export function selectBook(book) {
// selectBook is an ActionCreator, it needs to return an action,
// an object with a type property.
return {
type: 'BOOK_SELECTED',
type: "BOOK_SELECTED",
payload: book
};
}
8 changes: 4 additions & 4 deletions book_list/src/components/app.js
@@ -1,8 +1,8 @@
import React from 'react';
import { Component } from 'react';
import React from "react";
import { Component } from "react";

import BookList from '../containers/book-list';
import BookDetail from '../containers/book-detail';
import BookList from "../containers/book-list";
import BookDetail from "../containers/book-detail";

export default class App extends Component {
render() {
Expand Down
4 changes: 2 additions & 2 deletions book_list/src/containers/book-detail.js
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import React, { Component } from "react";
import { connect } from "react-redux";

class BookDetail extends Component {
render() {
Expand Down
15 changes: 8 additions & 7 deletions book_list/src/containers/book-list.js
@@ -1,16 +1,17 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { selectBook } from '../actions/index';
import { bindActionCreators } from 'redux';
import React, { Component } from "react";
import { connect } from "react-redux";
import { selectBook } from "../actions/index";
import { bindActionCreators } from "redux";

class BookList extends Component {
renderList() {
return this.props.books.map((book) => {
return this.props.books.map(book => {
return (
<li
key={book.title}
onClick={() => this.props.selectBook(book)}
className="list-group-item">
className="list-group-item"
>
{book.title}
</li>
);
Expand All @@ -22,7 +23,7 @@ class BookList extends Component {
<ul className="list-group col-sm-4">
{this.renderList()}
</ul>
)
);
}
}

Expand Down

0 comments on commit 2de8c92

Please sign in to comment.