Skip to content

Commit c689d3c

Browse files
authored
Adjusted superfluous comments, used setState where required, and general readability adjustments (#123)
1 parent 85f1ab0 commit c689d3c

File tree

6 files changed

+35
-45
lines changed

6 files changed

+35
-45
lines changed

split-webapp/split/src/components/MenuBar.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,10 @@ const useStyles = makeStyles(theme => ({
2525

2626
export default function MenuBar() {
2727
const classes = useStyles();
28-
// relates to handleChange
29-
const [auth /* , setAuth */] = React.useState(true);
28+
const [auth] = React.useState(true);
3029
const [anchorEl, setAnchorEl] = React.useState(null);
3130
const open = Boolean(anchorEl);
3231

33-
// const handleChange = event => {
34-
// setAuth(event.target.checked);
35-
// };
36-
3732
const handleMenu = event => {
3833
setAnchorEl(event.currentTarget);
3934
};

split-webapp/split/src/components/TransactionList.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class TransactionList extends React.Component {
3939
}
4040

4141
componentDidMount() {
42-
fetch("/api/bill_data/get_bills") // temp
42+
fetch("/api/bill_data/get_bills")
4343
.then(res => {
4444
return res.json();
4545
})
@@ -79,7 +79,7 @@ class TransactionList extends React.Component {
7979
<ExpansionPanelSummary>
8080
<div className="BillSummary">
8181
<div className="BillTitle">{bill.title}</div>
82-
<div className="BillAmount">${bill.total.toFixed(2)}</div>
82+
<div className="BillAmount">${Number(bill.total).toFixed(2)}</div>
8383
</div>
8484
</ExpansionPanelSummary>
8585
<ExpansionPanelDetails className="Payments">
@@ -101,7 +101,9 @@ class TransactionList extends React.Component {
101101
</div>
102102
</div>
103103
{bill.payments.map(payment => {
104-
const label = `${payment.from} owes ${payment.to} $${payment.amount.toFixed(2)}`;
104+
const label = `${payment.from} owes ${payment.to} $${Number(
105+
payment.amount
106+
).toFixed(2)}`;
105107
return (
106108
<div key={payment.id}>
107109
<FormControlLabel

split-webapp/split/src/pages/Home.js

-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ function Home() {
1717
<button type="button">Sign Out</button>
1818
</NavLink>
1919
<NavList />
20-
{/* <ul className="">
21-
<NavLink className="NavText" to="/home/transactions"><button className="NavOptions">Transactions</button></NavLink>
22-
<NavLink className="NavText" to="/home/split"><button className="NavOptions">Split</button></NavLink>
23-
</ul> */}
2420
</div>
2521
<div className="HomeScreen">
2622
<Route path="/home/transactions" component={Transactions} />

split-webapp/split/src/pages/Login.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,27 @@ class Login extends Component {
2222
}
2323

2424
handleOnChangeUser = event => {
25-
this.state.username = event.target.value;
25+
this.setState({ username: event.target.value });
2626
};
2727

2828
handleOnChangePassword = event => {
29-
this.state.password = event.target.value;
29+
this.setState({ password: event.target.value });
3030
};
3131

3232
handleAuth = () => {
3333
this.setState({ failedAuth: true });
3434
};
3535

36-
// creates user and passes it to the api call.
3736
createDetails() {
38-
const user = this.state;
37+
const { username, password, failedAuth } = this.state;
38+
const user = {
39+
username,
40+
password,
41+
failedAuth
42+
};
3943
this.authenticate(user);
4044
}
4145

42-
// api call to the back-end
4346
authenticate(user) {
4447
const { history } = this.props;
4548
fetch("/api/account/login", {

split-webapp/split/src/pages/SignUp.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class SignUp extends Component {
3131
this.setState({ user, failed: false });
3232
};
3333

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

3737
createUser() {
3838
const { user } = this.state;
@@ -58,8 +58,6 @@ class SignUp extends Component {
5858
})
5959
.then(data => {
6060
if (data.success === true) {
61-
// If the POST returns success, route user to the split page
62-
// eslint-ignore
6361
history.push("/home/split");
6462
} else {
6563
this.setState({
@@ -72,15 +70,11 @@ class SignUp extends Component {
7270
}
7371
}
7472

75-
// Checks that the two passwords match
76-
7773
validatePassword() {
7874
const { user } = this.state;
7975
return user.password === user.confPassword;
8076
}
8177

82-
// Check the username is non empty
83-
8478
validateUsername() {
8579
const { user } = this.state;
8680
return user.username !== "";

split-webapp/split/src/pages/Split.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ import {
1313
} from "@material-ui/core";
1414
import PropTypes from "prop-types";
1515

16+
const createBill = data => {
17+
fetch("/api/bill_exec/create_bill", {
18+
method: "POST",
19+
body: JSON.stringify(data),
20+
headers: {
21+
"Content-Type": "application/json"
22+
}
23+
})
24+
.then(res => {
25+
return res;
26+
})
27+
.catch(err => console.log(err));
28+
};
29+
1630
class Split extends Component {
1731
constructor(props) {
1832
super(props);
@@ -88,15 +102,17 @@ class Split extends Component {
88102
outstanding_payments: paymentArray
89103
};
90104

91-
this.createBill(bill);
105+
createBill(bill);
92106

93107
if (!title) {
94108
alert("Please enter a title description for this bill.");
95109
return;
96-
} if (!cost) {
110+
}
111+
if (!cost) {
97112
alert("Please enter an amount for this bill.");
98113
return;
99-
} if (transaction.users.length < 2) {
114+
}
115+
if (transaction.users.length < 2) {
100116
alert(
101117
"There is not enough people to split a bill. Please make sure at least 2 people are on the list."
102118
);
@@ -110,22 +126,6 @@ class Split extends Component {
110126
history.push("/home/transactions");
111127
}
112128

113-
createBill(data) {
114-
fetch("/api/bill_exec/create_bill", {
115-
method: "POST",
116-
body: JSON.stringify(data),
117-
headers: {
118-
"Content-Type": "application/json"
119-
}
120-
})
121-
.then(res => {
122-
// If "this" is not called in the createBill method, you may have to create the function outside of the class (es-lint rule)
123-
this.setState({});
124-
return res;
125-
})
126-
.catch(err => console.log(err));
127-
}
128-
129129
render() {
130130
const { transaction } = this.state;
131131
return (

0 commit comments

Comments
 (0)