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

Dev environment setup #2

Merged
merged 19 commits into from
Aug 10, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"presets": [
"env",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you typically have to pass some configuration options to env?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. Works out of the box

"react",
"stage-2",
"flow"
"stage-2"
],
plugins: [
"react-hot-loader/babel"
Expand Down
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
/public
/config/**
registerServiceWorker.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there something about service workers that eslint disagrees with?

Copy link
Contributor Author

@ynigoreyes ynigoreyes Aug 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, lines 2 and 3 are not needed anymore. The service worker is all over the place. It'm mainly so serve content offline. That is all is seems to do but that boilerplate from CRA. However, it is not styled in any way really, but i don't want to touch it since it is boilerplate from CRA

/src
8 changes: 0 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,3 @@ cache:
- $HOME/.npm
script:
- npm test
- npm run docs
deploy:
provider: pages
skip_cleanup: true
github_token: $GITHUB_TOKEN # Set in travis-ci.org dashboard
local_dir: docs/
on:
branch: master
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"url": "https://github.com/TTUSDC/CPCEEDWebApp/issues"
},
"dependencies": {
"@material-ui/core": "1.4.3",
"@material-ui/icons": "2.0.1",
"@material-ui/core": "^1.4.3",
"@material-ui/icons": "^2.0.1",
"axios": "0.16.1",
"dotenv": "4.0.0",
"dotenv-expand": "4.2.0",
Expand Down Expand Up @@ -63,7 +63,6 @@
"eslint-plugin-react": "7.10.0",
"extract-text-webpack-plugin": "3.0.2",
"file-loader": "1.1.5",
"flow-bin": "^0.78.0",
"fs-extra": "3.0.1",
"html-webpack-plugin": "2.29.0",
"jest": "23.4.2",
Expand Down
29 changes: 21 additions & 8 deletions src/layout/Auth/components/Auth.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,30 @@ class Auth extends React.Component {
}

render() {
const {
authCancelled,
handleLogin,
handleRegister,
regErr,
waiting,
logErr,
} = this.props;

const {
index,
} = this.state;

return (
<Layer
closer
flush={false}
align='center'
onClose={() => {
this.props.authCancelled();
authCancelled();
}}
>
<Tabs
activeIndex={this.state.index}
activeIndex={index}
justify='center'
responsive={false}
onActive={(event) => {
Expand All @@ -45,16 +58,16 @@ class Auth extends React.Component {
>
<Tab title='Login'>
<Login
handleLogin={this.props.handleLogin}
logErr={this.props.logErr}
waiting={this.props.waiting}
handleLogin={handleLogin}
logErr={logErr}
waiting={waiting}
/>
</Tab>
<Tab title='Register'>
<Register
handleRegister={this.props.handleRegister}
regErr={this.props.regErr}
waiting={this.props.waiting}
handleRegister={handleRegister}
regErr={regErr}
waiting={waiting}
/>
</Tab>
</Tabs>
Expand Down
23 changes: 11 additions & 12 deletions src/layout/Auth/components/Register.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Register extends React.Component {
this.inputChecking = this.inputChecking.bind(this);
}

handlePasswordChange(event) {
handlePasswordChange = (event) => {
this.setState({
password: event.target.value,
confirmPass: '',
Expand All @@ -47,26 +47,25 @@ class Register extends React.Component {
});
}

handleInputChange(event) {
const target = event.target;
const value = target.value;
const name = target.name;
handleInputChange = (event) => {
const { target } = event;
const { value, name } = target;

this.setState({
[name]: value,
});
}

handleSelectChange(event) {
const name = event.target.name;
const option = event.option;
handleSelectChange = (event) => {
const { name } = event.target;
const { option } = event;

this.setState({
[name]: option,
});
}

handleSubmit(event) {
handleSubmit = (event) => {
// This prevents a '?' from being appended to the URL
event.preventDefault();

Expand All @@ -78,8 +77,8 @@ class Register extends React.Component {
});
}

handleFocus(event) {
const name = event.target.name;
handleFocus = (event) => {
const { name } = event.target;

switch (name) {
case 'email':
Expand Down Expand Up @@ -118,7 +117,7 @@ class Register extends React.Component {
}

inputChecking(event) {
const name = event.target.name;
const { name } = event.target;
let value = null;

switch (name) {
Expand Down
1 change: 0 additions & 1 deletion src/layout/NavBar/NavBarContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import * as server from 'server';
import logger from 'logger.js';
import { NavBar } from './components';


class NavBarContainer extends React.Component {
state = {
auth: false,
Expand Down
6 changes: 0 additions & 6 deletions src/layout/NavBar/components/NavBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,4 @@ NavBar.propTypes = {
logout: PropTypes.func.isRequired,
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the linter got mad when we had a requiredProp along with a default value. If the user was not passed, then webpack would not compile altogether, so there was no need to add a default prop value

NavBar.defaultProps = {
user: {
name: '',
},
};

export default NavBar;
4 changes: 2 additions & 2 deletions src/pages/Settings/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import Header from 'grommet/components/Header';
import Button from 'grommet/components/Button';

import RequireAuth from 'hoc/RequireAuth.jsx';
import { AccountContainer } from './routes/Account';
import { ProfileContainer } from './routes/Profile';
import AccountContainer from './routes/Account';
import ProfileContainer from './routes/Profile';

class Settings extends React.Component {
navigate = (url) => {
Expand Down
102 changes: 48 additions & 54 deletions src/pages/Settings/routes/Account/AccountContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,105 +2,97 @@ import React from 'react';
import * as firebase from 'firebase';
import { connect } from 'react-redux';
import update from 'immutability-helper';
import logger from 'logger.js';
import PropTypes from 'prop-types';

import { Account } from './components';
import { updateUser } from 'redux/actions.js';
import logger from 'logger.js';
import { Account } from './components';

class AccountContainer extends React.Component {
constructor(props) {
super(props);
this.state = {
err: {
email: '',
password: ''
},
waiting: {
email: false,
password: false
}
};

this.handlePassword = this.handlePassword.bind(this);
this.handleEmail = this.handleEmail.bind(this);
}
state = {
err: {
email: '',
password: '',
},
waiting: {
email: false,
password: false,
},
};

handlePassword(password, old) {
handlePassword = (password, old) => { // eslint-disable-line no-unused-vars
// TODO (Nils) utilize the old password

this.setState({
waiting: update(this.state.waiting, {
password: {$set: true}
password: { $set: true },
}),
err: update(this.state.err, {
password: {$set: ''}
})
password: { $set: '' },
}),
});

var user = firebase.auth().currentUser;
const user = firebase.auth().currentUser;
user.updatePassword(password)
.then(() => {
logger.info('Password was changed');
this.setState({
waiting: update(this.state.waiting, {
password: {$set: false}
})
password: { $set: false },
}),
});
})
.catch((e) => {
logger.error(e.message);
this.setState({
waiting: update(this.state.waiting, {
password: {$set: false}
password: { $set: false },
}),
err: update(this.state.err, {
password: {$set: e.message}
})
password: { $set: e.message },
}),
});
});
}

handleEmail(email) {
this.setState({
waiting: update(this.state.waiting, {
email: {$set: true}
email: { $set: true },
}),
err: update(this.state.err, {
email: {$set: ''}
})
email: { $set: '' },
}),
});

var user = firebase.auth().currentUser;
const userRef = firebase.database().ref().child('users/' + user.uid);
const user = firebase.auth().currentUser;
const userRef = firebase.database().ref().child(`users/${user.uid}`);

user.updateEmail(email)
.then(() => {
return userRef.update({
email: email
});
})
.then(() => userRef.update({
email,
}))
.then(() => {
logger.info('Email was updated');

var newUser = this.props.user;
const { user: newUser } = this.props;
newUser.email = email;
this.props.dispatch(updateUser(newUser));

this.setState({
waiting: update(this.state.waiting, {
email: {$set: false}
})
email: { $set: false },
}),
});
})
.catch((e) => {
logger.error(e.message);
this.setState({
waiting: update(this.state.waiting, {
email: {$set: false}
email: { $set: false },
}),
err: update(this.state.err, {
email: {$set: e.message}
})
email: { $set: e.message },
}),
});
});
}
Expand All @@ -112,19 +104,21 @@ class AccountContainer extends React.Component {
handleEmail={this.handleEmail}
user={this.props.user}
waiting={this.state.waiting}
err={this.state.err}/>
err={this.state.err}
/>
);
}
}

const getUser = (user) => {
return user;
}
AccountContainer.propTypes = {
user: PropTypes.shape({}).isRequired,
dispatch: PropTypes.func.isRequired,
};

const mapStateToProps = (state) => {
return {
user: getUser(state.user)
}
}
const getUser = user => user;

const mapStateToProps = state => ({
user: getUser(state.user),
});

export default connect(mapStateToProps)(AccountContainer);
Loading