Skip to content

Commit

Permalink
Merge pull request #12 from NorikDavtian/light-dashboard
Browse files Browse the repository at this point in the history
Refactor to reduce complexity with latest react hooks
  • Loading branch information
NorikDavtian committed Aug 4, 2019
2 parents dd0d27a + bb2970e commit ba83703
Show file tree
Hide file tree
Showing 40 changed files with 14,232 additions and 13,217 deletions.
1 change: 1 addition & 0 deletions .sample-env → .env.default
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ REACT_APP_API_URL=http://localhost:5000

# path to the root dir of the app ie: "/semantic-dashboard" or leave it blank if do not run the app from a sub directory
REACT_APP_HOMEPAGE=
REACT_APP_DB_NAME="SEMANTIC_DASHBOARD"
4 changes: 1 addition & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
"react/no-unescaped-entities": [
0
],
"react/forbid-prop-types": [
0
],
"react/prop-types": 0,
"jsx-a11y/href-no-hash": 0,
"jsx-a11y/img-has-alt": 0,
"no-console": 0,
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# misc
.DS_Store
.env*
.env
npm-debug.log*
yarn-debug.log*
yarn-error.log*
Expand Down
26,363 changes: 13,940 additions & 12,423 deletions package-lock.json

Large diffs are not rendered by default.

41 changes: 22 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,21 @@
"version": "0.1.0",
"homepage": "https://norikdavtian.github.io/semantic-dashboard",
"dependencies": {
"@reach/router": "^1.2.1",
"history": "^4.7.2",
"humps": "^2.0.1",
"micro": "^9.0.2",
"micro-cors": "^0.1.0",
"microrouter": "^3.0.0",
"prop-types": "^15.6.0",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-redux": "^5.0.6",
"react-router-dom": "^4.2.2",
"react-router-redux": "^5.0.0-alpha.6",
"redux": "^3.7.2",
"redux-devtools": "^3.4.0",
"redux-devtools-dock-monitor": "^1.1.2",
"redux-devtools-log-monitor": "^1.3.0",
"redux-logger": "^3.0.6",
"redux-observable": "^0.17.0",
"rxjs": "^5.5.6",
"pouchdb": "^7.1.1",
"pouchdb-debug": "^7.1.1",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"semantic-ui-css": "^2.2.12",
"semantic-ui-react": "^0.73.1"
"semantic-ui-react": "^0.87.2"
},
"devDependencies": {
"babel-eslint": "^8.0.0",
"eslint": "^4.7.1",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^15.1.0",
"eslint-config-react-app": "^2.0.0",
"eslint-plugin-flowtype": "^2.35.1",
Expand All @@ -38,19 +29,19 @@
"lint-staged": "^4.2.1",
"node-sass": "^4.5.3",
"npm-run-all": "^4.1.1",
"react-scripts": "1.0.13"
"react-scripts": "^3.0.1"
},
"scripts": {
"build": "npm run minify-css && react-scripts build",
"build-css": "node-sass src/ -o src/ --output-style expanded",
"clean": "rm -rf node_modules/ && rm -rf package-lock.json && npm install",
"cp-env-local": "cp .sample-env .env.local && echo 'Coppied .sample-env -> .env.local'",
"cp-env-local": "cp .env.default .env.local && echo 'Coppied .env.default -> .env.local'",
"eject": "react-scripts eject",
"fixit": "eslint src/ --fix",
"lint": "eslint src/",
"minify-css": "node-sass src/ -o src/ --output-style compressed",
"mock-server": "micro mock_server/ -p ${PORT:-5000}",
"postinstall": "[ -f '.env' ] || (cp .sample-env .env && echo 'Coppied .sample-env -> .env')",
"postinstall": "[ -f '.env' ] || (cp .env.default .env && echo 'Coppied .env.default -> .env')",
"precommit": "lint-staged",
"start": "npm-run-all -p mock-server watch-css start-js",
"start-js": "react-scripts start",
Expand All @@ -64,5 +55,17 @@
"eslint --fix",
"git add"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
18 changes: 0 additions & 18 deletions src/actions/index.js

This file was deleted.

3 changes: 1 addition & 2 deletions src/api/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ export const getEmail = async (emailId) => {

if (response.status === 200) {
const body = await response.json();
console.log('response: ', body);
return camelizeKeys(body);
}
throw new Error('Can not fetch bookings.');
throw new Error('Can not fetch email.');
};

export default {};
7 changes: 5 additions & 2 deletions src/api/inbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ export const getEmails = async (pageNo = 1) => {

if (response.status === 200) {
const body = await response.json();
console.log('response: ', body);
// console.log('response: ', body);
const res = camelizeKeys(body)
console.log('RES: ', res);

return camelizeKeys(body);
}
throw new Error('Can not fetch bookings.');
throw new Error('Can not fetch emails');
};


Expand Down
3 changes: 1 addition & 2 deletions src/api/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as inbox from './inbox';
import * as email from './email';

export default {};
export { inbox, email };
export default { inbox, email };

33 changes: 0 additions & 33 deletions src/components/Dashboard.js

This file was deleted.

56 changes: 17 additions & 39 deletions src/components/Email.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,24 @@
import React from 'react';
import React, { useEffect, useState } from 'react';
import { Segment } from 'semantic-ui-react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { Link } from 'react-router-dom';
import PropTypes from 'prop-types';
import { requestEmail, requestInbox } from '../actions';
import { Link } from '@reach/router';
import './Email.css';
import { home } from '../config';

// @todo decide if will fetch data in constructor or via dispatched actions
// constructor (props) {
// super(props);
// const id = this.props.location.pathname.substring('/email/'.length);
// this.props.getEmail(id);
// }
const Email = (props) => {
const { service, emailId } = props;
const [email, setEmail] = useState({});

const Email = ({ email }) => (
<Segment basic id="content">
<h2><Link to={`${home}/`}>Inbox</Link> / {email.subject}</h2>
<p><b>Date: </b>{email.date}</p>
<p><b>From:</b> {email.sender}</p>
<p>{email.text}</p>
</Segment>
);
useEffect(() => {
service(emailId, setEmail);
}, [service, emailId]);

Email.propTypes = {
// getInbox: PropTypes.func.isRequired,
// getEmail: PropTypes.func.isRequired,
email: PropTypes.object
return (
<Segment basic id="content">
<h2><Link to={'/'}>Inbox</Link> / {email.subject}</h2>
<p><b>Date: </b>{email.date}</p>
<p><b>From:</b> {email.sender}</p>
<p>{email.text}</p>
</Segment>
);
};

Email.defaultProps = {
email: {}
};

const mapStateToProps = state => ({
email: state.email.details
});

const mapDispatchToProps = dispatch => ({
getInbox: bindActionCreators(requestInbox, dispatch),
getEmail: bindActionCreators(requestEmail, dispatch)
});

export default connect(mapStateToProps, mapDispatchToProps)(Email);
export default Email;
Loading

0 comments on commit ba83703

Please sign in to comment.