Skip to content

Commit

Permalink
Adjusted superfluous comments, used setState where required, and gene…
Browse files Browse the repository at this point in the history
…ral readability adjustments (#123)
  • Loading branch information
azizul-i authored Mar 20, 2020
1 parent 85f1ab0 commit c689d3c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 45 deletions.
7 changes: 1 addition & 6 deletions split-webapp/split/src/components/MenuBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,10 @@ const useStyles = makeStyles(theme => ({

export default function MenuBar() {
const classes = useStyles();
// relates to handleChange
const [auth /* , setAuth */] = React.useState(true);
const [auth] = React.useState(true);
const [anchorEl, setAnchorEl] = React.useState(null);
const open = Boolean(anchorEl);

// const handleChange = event => {
// setAuth(event.target.checked);
// };

const handleMenu = event => {
setAnchorEl(event.currentTarget);
};
Expand Down
8 changes: 5 additions & 3 deletions split-webapp/split/src/components/TransactionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TransactionList extends React.Component {
}

componentDidMount() {
fetch("/api/bill_data/get_bills") // temp
fetch("/api/bill_data/get_bills")
.then(res => {
return res.json();
})
Expand Down Expand Up @@ -79,7 +79,7 @@ class TransactionList extends React.Component {
<ExpansionPanelSummary>
<div className="BillSummary">
<div className="BillTitle">{bill.title}</div>
<div className="BillAmount">${bill.total.toFixed(2)}</div>
<div className="BillAmount">${Number(bill.total).toFixed(2)}</div>
</div>
</ExpansionPanelSummary>
<ExpansionPanelDetails className="Payments">
Expand All @@ -101,7 +101,9 @@ class TransactionList extends React.Component {
</div>
</div>
{bill.payments.map(payment => {
const label = `${payment.from} owes ${payment.to} $${payment.amount.toFixed(2)}`;
const label = `${payment.from} owes ${payment.to} $${Number(
payment.amount
).toFixed(2)}`;
return (
<div key={payment.id}>
<FormControlLabel
Expand Down
4 changes: 0 additions & 4 deletions split-webapp/split/src/pages/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ function Home() {
<button type="button">Sign Out</button>
</NavLink>
<NavList />
{/* <ul className="">
<NavLink className="NavText" to="/home/transactions"><button className="NavOptions">Transactions</button></NavLink>
<NavLink className="NavText" to="/home/split"><button className="NavOptions">Split</button></NavLink>
</ul> */}
</div>
<div className="HomeScreen">
<Route path="/home/transactions" component={Transactions} />
Expand Down
13 changes: 8 additions & 5 deletions split-webapp/split/src/pages/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,27 @@ class Login extends Component {
}

handleOnChangeUser = event => {
this.state.username = event.target.value;
this.setState({ username: event.target.value });
};

handleOnChangePassword = event => {
this.state.password = event.target.value;
this.setState({ password: event.target.value });
};

handleAuth = () => {
this.setState({ failedAuth: true });
};

// creates user and passes it to the api call.
createDetails() {
const user = this.state;
const { username, password, failedAuth } = this.state;
const user = {
username,
password,
failedAuth
};
this.authenticate(user);
}

// api call to the back-end
authenticate(user) {
const { history } = this.props;
fetch("/api/account/login", {
Expand Down
10 changes: 2 additions & 8 deletions split-webapp/split/src/pages/SignUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class SignUp extends Component {
this.setState({ user, failed: false });
};

// Creates a new user JSON and sends to the create account end point. On success routes
// user to the create a bill page. User should get logged in as well as session created.
// Creates a new user JSON and sends to the create account end point.
// User should get logged in as well as session created.

createUser() {
const { user } = this.state;
Expand All @@ -58,8 +58,6 @@ class SignUp extends Component {
})
.then(data => {
if (data.success === true) {
// If the POST returns success, route user to the split page
// eslint-ignore
history.push("/home/split");
} else {
this.setState({
Expand All @@ -72,15 +70,11 @@ class SignUp extends Component {
}
}

// Checks that the two passwords match

validatePassword() {
const { user } = this.state;
return user.password === user.confPassword;
}

// Check the username is non empty

validateUsername() {
const { user } = this.state;
return user.username !== "";
Expand Down
38 changes: 19 additions & 19 deletions split-webapp/split/src/pages/Split.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ import {
} from "@material-ui/core";
import PropTypes from "prop-types";

const createBill = data => {
fetch("/api/bill_exec/create_bill", {
method: "POST",
body: JSON.stringify(data),
headers: {
"Content-Type": "application/json"
}
})
.then(res => {
return res;
})
.catch(err => console.log(err));
};

class Split extends Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -88,15 +102,17 @@ class Split extends Component {
outstanding_payments: paymentArray
};

this.createBill(bill);
createBill(bill);

if (!title) {
alert("Please enter a title description for this bill.");
return;
} if (!cost) {
}
if (!cost) {
alert("Please enter an amount for this bill.");
return;
} if (transaction.users.length < 2) {
}
if (transaction.users.length < 2) {
alert(
"There is not enough people to split a bill. Please make sure at least 2 people are on the list."
);
Expand All @@ -110,22 +126,6 @@ class Split extends Component {
history.push("/home/transactions");
}

createBill(data) {
fetch("/api/bill_exec/create_bill", {
method: "POST",
body: JSON.stringify(data),
headers: {
"Content-Type": "application/json"
}
})
.then(res => {
// If "this" is not called in the createBill method, you may have to create the function outside of the class (es-lint rule)
this.setState({});
return res;
})
.catch(err => console.log(err));
}

render() {
const { transaction } = this.state;
return (
Expand Down

0 comments on commit c689d3c

Please sign in to comment.