Skip to content

Commit

Permalink
Fix eslint & prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
PW486 committed Jun 6, 2019
1 parent 97c2f2f commit 99a58aa
Show file tree
Hide file tree
Showing 24 changed files with 256 additions and 175 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ module.exports = {
'no-console': 1,
'no-unused-vars': 2,
'no-use-before-define': 0,
'no-case-declarations': 0,
'no-unused-expressions': 0,
'prefer-template': 2,
'react/destructuring-assignment': 0,
'react-hooks/rules-of-hooks': 'error',
Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,3 @@ Need to change the **`REACT_APP_BASE_URL`**. Here is an example server. [https:/
| Authentication | **JWT** |
| Linter | **ESLint** |
| Formatter | **Prettier** |

## TODO

- Linter + Formatter
- Release
9 changes: 1 addition & 8 deletions src/components/NotFound/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@ import React from 'react';
import { Alert } from 'antd';

function NotFound() {
return (
<Alert
message="404 Error"
description="Page Not Found."
type="error"
showIcon
/>
);
return <Alert message="404 Error" description="Page Not Found." type="error" showIcon />;
}

export default NotFound;
16 changes: 11 additions & 5 deletions src/components/PrivateRoute/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Route, Redirect } from 'react-router-dom';

function PrivateRoute({ component: Component, ...rest }) {
return (
<Route {...rest} render={props => (
localStorage.getItem('token')
? <Component {...props} />
: <Redirect to={{ pathname: '/signin', state: { from: props.location } }} />
)} />
<Route
{...rest}
render={props =>
localStorage.getItem('token') ? <Component {...props} /> : <Redirect to={{ pathname: '/signin' }} />
}
/>
);
}

PrivateRoute.propTypes = {
component: PropTypes.any,
};

export default PrivateRoute;
18 changes: 11 additions & 7 deletions src/components/Sider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,33 @@ import { Layout, Icon, Menu } from 'antd';
import routes from 'routes';
import { makeSelectUser } from 'containers/App/selectors';

/* eslint-disable indent */
function Sider(props) {
return (
<Layout.Sider>
<Menu theme="dark" selectedKeys={[props.location.pathname]} mode="inline">
{routes.map((route) => (
(!route.auth) ||
{routes.map(route =>
!route.auth ||
(!route.permission && props.user) ||
(props.user && props.user.permissions.includes(route.permission)) ?
(
<Menu.Item key={route.path || "/notfound"}>
<Link to={route.path || "/notfound"}>
(props.user && props.user.permissions.includes(route.permission)) ? (
<Menu.Item key={route.path || '/notfound'}>
<Link to={route.path || '/notfound'}>
<Icon type={route.Icon} />
<span>{route.name}</span>
</Link>
</Menu.Item>
) : (<React.Fragment />)))}
) : (
<React.Fragment />
),
)}
</Menu>
</Layout.Sider>
);
}

Sider.propTypes = {
user: PropTypes.object,
location: PropTypes.object,
};

export default connect(
Expand Down
9 changes: 5 additions & 4 deletions src/containers/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ import routes from 'routes';
export default function App() {
return (
<Layout style={{ minHeight: '100vh' }}>
<Helmet titleTemplate="%s - Create React Ant Design Boilerplate" defaultTitle="Create React Ant Design Boilerplate">
<Helmet
titleTemplate="%s - Create React Ant Design Boilerplate"
defaultTitle="Create React Ant Design Boilerplate"
>
<meta name="description" content="A Create React Ant Design Boilerplate application" />
</Helmet>
<Header />
<Layout>
<Sider />
<Layout>
<Layout.Content style={{ margin: '16px' }}>
<Switch>
{routes.map((route) => (route.auth ? <PrivateRoute {...route} /> : <Route {...route} />))}
</Switch>
<Switch>{routes.map(route => (route.auth ? <PrivateRoute {...route} /> : <Route {...route} />))}</Switch>
</Layout.Content>
<Layout.Footer style={{ textAlign: 'center' }}>Create React Ant Design Boilerplate</Layout.Footer>
</Layout>
Expand Down
8 changes: 4 additions & 4 deletions src/containers/App/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import { POST_SIGN_IN_SUCCESS } from '../SignIn/constants';
const token = localStorage.getItem('token');
const userState = token ? { user: jwtDecode(token) } : {};
export const initialState = {
...userState
...userState,
};

/* eslint-disable default-case, no-param-reassign */
const appReducer = (state = initialState, action) =>
produce(state, draft => {
switch (action.type) {
case POST_SIGN_IN_SUCCESS:
const token = action.payload.data.access_token;
localStorage.setItem('token', token);
draft.user = jwtDecode(token);
const newToken = action.payload.data.access_token;
localStorage.setItem('token', newToken);
draft.user = jwtDecode(newToken);
break;
}
});
Expand Down
26 changes: 16 additions & 10 deletions src/containers/App/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ import { initialState } from './reducer';
const selectGlobal = state => state.global || initialState;
const selectRouter = state => state.router;

const makeSelectUser = () => createSelector(selectGlobal, globalState => globalState.user);
const makeSelectUserId = () => createSelector(selectGlobal, globalState => globalState.user.id);
const makeSelectUserPermissions = () => createSelector(selectGlobal, globalState => globalState.user.permissions);
const makeSelectUser = () =>
createSelector(
selectGlobal,
globalState => globalState.user,
);
const makeSelectUserId = () =>
createSelector(
selectGlobal,
globalState => globalState.user.id,
);
const makeSelectUserPermissions = () =>
createSelector(
selectGlobal,
globalState => globalState.user.permissions,
);

export {
selectGlobal,
selectRouter,
makeSelectUser,
makeSelectUserId,
makeSelectUserPermissions,
};
export { selectGlobal, selectRouter, makeSelectUser, makeSelectUserId, makeSelectUserPermissions };
39 changes: 26 additions & 13 deletions src/containers/Board/actions.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
import { GET_POSTS_REQUEST, GET_POSTS_FAILURE, GET_POSTS_SUCCESS, POST_POSTS_REQUEST, POST_POSTS_SUCCESS, POST_POSTS_FAILURE, HANDLE_MODAL_SHOW, HANDLE_MODAL_CANCEL, ON_CHANGE_TITLE, ON_CHANGE_TEXT, ON_CHANGE_ADD_PHOTO, ON_CHANGE_DEL_PHOTO } from './constants';
import {
GET_POSTS_REQUEST,
GET_POSTS_FAILURE,
GET_POSTS_SUCCESS,
POST_POSTS_REQUEST,
POST_POSTS_SUCCESS,
POST_POSTS_FAILURE,
HANDLE_MODAL_SHOW,
HANDLE_MODAL_CANCEL,
ON_CHANGE_TITLE,
ON_CHANGE_TEXT,
ON_CHANGE_ADD_PHOTO,
ON_CHANGE_DEL_PHOTO,
} from './constants';

export const getPostsAction = (payload) => ({ type: GET_POSTS_REQUEST, payload });
export const getPostsSuccess = (payload) => ({ type: GET_POSTS_SUCCESS, payload });
export const getPostsFailure = (payload) => ({ type: GET_POSTS_FAILURE, payload });
export const getPostsAction = payload => ({ type: GET_POSTS_REQUEST, payload });
export const getPostsSuccess = payload => ({ type: GET_POSTS_SUCCESS, payload });
export const getPostsFailure = payload => ({ type: GET_POSTS_FAILURE, payload });

export const postPostsAction = (payload) => ({ type: POST_POSTS_REQUEST, payload });
export const postPostsSuccess = (payload) => ({ type: POST_POSTS_SUCCESS, payload });
export const postPostsFailure = (payload) => ({ type: POST_POSTS_FAILURE, payload });
export const postPostsAction = payload => ({ type: POST_POSTS_REQUEST, payload });
export const postPostsSuccess = payload => ({ type: POST_POSTS_SUCCESS, payload });
export const postPostsFailure = payload => ({ type: POST_POSTS_FAILURE, payload });

export const handleModalShowAction = (payload) => ({ type: HANDLE_MODAL_SHOW, payload });
export const handleModalCancelAction = (payload) => ({ type: HANDLE_MODAL_CANCEL, payload });
export const handleModalShowAction = payload => ({ type: HANDLE_MODAL_SHOW, payload });
export const handleModalCancelAction = payload => ({ type: HANDLE_MODAL_CANCEL, payload });

export const onChangeTitleAction = (payload) => ({ type: ON_CHANGE_TITLE, payload });
export const onChangeTextAction = (payload) => ({ type: ON_CHANGE_TEXT, payload });
export const onChangeAddPhotoAction = (payload) => ({ type: ON_CHANGE_ADD_PHOTO, payload });
export const onChangeDelPhotoAction = (payload) => ({ type: ON_CHANGE_DEL_PHOTO, payload });
export const onChangeTitleAction = payload => ({ type: ON_CHANGE_TITLE, payload });
export const onChangeTextAction = payload => ({ type: ON_CHANGE_TEXT, payload });
export const onChangeAddPhotoAction = payload => ({ type: ON_CHANGE_ADD_PHOTO, payload });
export const onChangeDelPhotoAction = payload => ({ type: ON_CHANGE_DEL_PHOTO, payload });
56 changes: 40 additions & 16 deletions src/containers/Board/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,24 @@ import { Button, Table, Modal, Input, Icon, Upload, Avatar } from 'antd';

import injectSaga from 'utils/injectSaga';
import injectReducer from 'utils/injectReducer';
import { makeSelectPostList, makeSelectModalVisible, makeSelectModalLoading, makeSelectTitle, makeSelectText, makeSelectPhoto } from './selectors';
import { getPostsAction, handleModalShowAction, handleModalCancelAction, postPostsAction, onChangeTitleAction, onChangeTextAction, onChangeAddPhotoAction, onChangeDelPhotoAction } from './actions';
import {
makeSelectPostList,
makeSelectModalVisible,
makeSelectModalLoading,
makeSelectTitle,
makeSelectText,
makeSelectPhoto,
} from './selectors';
import {
getPostsAction,
handleModalShowAction,
handleModalCancelAction,
postPostsAction,
onChangeTitleAction,
onChangeTextAction,
onChangeAddPhotoAction,
onChangeDelPhotoAction,
} from './actions';
import reducer from './reducer';
import saga from './saga';

Expand All @@ -28,27 +44,30 @@ const columns = [
title: 'Text',
dataIndex: 'text',
key: 'text',
render: text => (<pre style={{marginBottom: 0, maxHeight: 100}}>{text}</pre>),
render: text => <pre style={{ marginBottom: 0, maxHeight: 100 }}>{text}</pre>,
},
{
title: 'Photo',
dataIndex: 'photo',
key: 'photo',
render: photo => photo ?
(<Avatar src={process.env.REACT_APP_BASE_URL + '/' + photo} shape="square"/>) :
(<Avatar icon="file-image" shape="square" />),
render: photo =>
photo ? (
<Avatar src={`${process.env.REACT_APP_BASE_URL}/${photo}`} shape="square" />
) : (
<Avatar icon="file-image" shape="square" />
),
},
{
title: 'Created At',
dataIndex: 'createdAt',
key: 'createdAt',
render: time => (<span>{time}</span>),
render: time => <span>{time}</span>,
},
{
title: 'Updated At',
dataIndex: 'updatedAt',
key: 'updatedAt',
render: time => (<span>{time}</span>),
render: time => <span>{time}</span>,
},
];

Expand All @@ -65,7 +84,9 @@ class Board extends React.Component {
<meta name="description" content="Description of Board" />
</Helmet>
<div style={{ marginBottom: 16 }}>
<Button type="primary" onClick={this.props.handleModalShow}>Write</Button>
<Button type="primary" onClick={this.props.handleModalShow}>
Write
</Button>
</div>
<Modal
title="Write a Post"
Expand All @@ -75,11 +96,7 @@ class Board extends React.Component {
onCancel={this.props.handleModalCancel}
>
<div style={{ marginBottom: 16 }}>
<Input
placeholder="Title"
onChange={this.props.onChangeTitle}
value={this.props.title}
/>
<Input placeholder="Title" onChange={this.props.onChangeTitle} value={this.props.title} />
</div>
<div style={{ marginBottom: 16 }}>
<Input.TextArea
Expand Down Expand Up @@ -119,6 +136,10 @@ Board.propTypes = {
postPosts: PropTypes.func,
handleModalShow: PropTypes.func,
handleModalCancel: PropTypes.func,
onChangeTitle: PropTypes.func,
onChangeText: PropTypes.func,
onChangeAddPhoto: PropTypes.func,
onChangeDelPhoto: PropTypes.func,
};

const mapStateToProps = createStructuredSelector({
Expand All @@ -142,9 +163,12 @@ const mapDispatchToProps = dispatch => ({
return false;
},
onChangeDelPhoto: () => dispatch(onChangeDelPhotoAction()),
})
});

const withConnect = connect(mapStateToProps, mapDispatchToProps);
const withConnect = connect(
mapStateToProps,
mapDispatchToProps,
);
const withReducer = injectReducer({ key: 'board', reducer });
const withSaga = injectSaga({ key: 'board', saga });

Expand Down
13 changes: 12 additions & 1 deletion src/containers/Board/reducer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import produce from 'immer';
import { GET_POSTS_SUCCESS, HANDLE_MODAL_SHOW, HANDLE_MODAL_CANCEL, POST_POSTS_REQUEST, POST_POSTS_SUCCESS, POST_POSTS_FAILURE, ON_CHANGE_TEXT, ON_CHANGE_TITLE, ON_CHANGE_ADD_PHOTO, ON_CHANGE_DEL_PHOTO } from './constants';
import {
GET_POSTS_SUCCESS,
HANDLE_MODAL_SHOW,
HANDLE_MODAL_CANCEL,
POST_POSTS_REQUEST,
POST_POSTS_SUCCESS,
POST_POSTS_FAILURE,
ON_CHANGE_TEXT,
ON_CHANGE_TITLE,
ON_CHANGE_ADD_PHOTO,
ON_CHANGE_DEL_PHOTO,
} from './constants';

export const initialState = {
postList: [],
Expand Down
14 changes: 6 additions & 8 deletions src/containers/Board/saga.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { getPostsSuccess, getPostsFailure, postPostsFailure, postPostsSuccess, getPostsAction } from "./actions";
import { takeLatest, call, put, select } from 'redux-saga/effects';
import { GET_POSTS_REQUEST, POST_POSTS_REQUEST } from "./constants";
import { getPostsAPI, postPostsAPI } from "./api";
import { makeSelectTitle, makeSelectText, makeSelectPhoto } from "./selectors";
import { getPostsSuccess, getPostsFailure, postPostsFailure, postPostsSuccess, getPostsAction } from './actions';
import { GET_POSTS_REQUEST, POST_POSTS_REQUEST } from './constants';
import { getPostsAPI, postPostsAPI } from './api';
import { makeSelectTitle, makeSelectText, makeSelectPhoto } from './selectors';

export function* getPostsSaga() {
try {
const postList = yield call(getPostsAPI);
yield put(getPostsSuccess(postList));
}
catch (error) {
} catch (error) {
yield put(getPostsFailure(error));
}
}
Expand All @@ -24,8 +23,7 @@ export function* postPostsSaga() {
yield call(postPostsAPI, { title, text, photo });
yield put(postPostsSuccess());
yield put(getPostsAction());
}
catch (error) {
} catch (error) {
yield put(postPostsFailure(error));
}
}
Expand Down
Loading

0 comments on commit 99a58aa

Please sign in to comment.