Skip to content

Comments

Lee Zhao Yi Charles - Project 1 #39

Open
charlesleezhaoyi wants to merge 11 commits intorocketacademy:mainfrom
charlesleezhaoyi:main
Open

Lee Zhao Yi Charles - Project 1 #39
charlesleezhaoyi wants to merge 11 commits intorocketacademy:mainfrom
charlesleezhaoyi:main

Conversation

@charlesleezhaoyi
Copy link

Project 1 Pull Request

}

handleSubmit = (event) => {
const { userAction, moduleList, moduleName, grade } = this.state;

Choose a reason for hiding this comment

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

nice destructuring

handleSubmit = (event) => {
const { userAction, moduleList, moduleName, grade } = this.state;

console.log("handleSubmit");

Choose a reason for hiding this comment

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

never keep console logs in your pushed code. Especially this one serves no purpose


console.log("handleSubmit");

if (moduleName === "") {

Choose a reason for hiding this comment

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

Suggested change
if (moduleName === "") {
if (!moduleName) {

this.setState({ error: null });
}

console.log("Add Module");

Choose a reason for hiding this comment

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

Remove

return;
}
// Add logic for adding modules
if (userAction === "Add") {

Choose a reason for hiding this comment

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

I think since you have a couple of user actions, you could just create functions for those.
addModule(), editModule() etc.

Also, since you are checking against a static string, I would recommend creating ENUM strings for those, so no typos will ever sneak into your code. Example:

const USER_ACTIONS = {
    ADD: "Add",
    UPDATE: "Update"
}

You could even go further and describe the values as the functions:

const USER_ACTIONS = {
      ["Add"]: addModule(),
      ["Update"]: updateModule()
}

Then you don't need to run if/else spaghetti but can just do USER_ACTIONS[userAction] and it will call the relevant function

</select>
<Button
type="submit"
className={enabled > 0 ? "button-enabled" : "button-disabled"}

Choose a reason for hiding this comment

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

Suggested change
className={enabled > 0 ? "button-enabled" : "button-disabled"}
className={enabled ? "button-enabled" : "button-disabled"}

Above 0 is truthy. Also, enabled should not be a number, but a boolean.

{/* Display the module list */}
</form>
</Card>
{error ? <div className="error-message">{error}</div> : <div></div>}

Choose a reason for hiding this comment

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

I would not render an empty div

Suggested change
{error ? <div className="error-message">{error}</div> : <div></div>}
{error && <div className="error-message">{error}</div>}

{error ? <div className="error-message">{error}</div> : <div></div>}
<h2 className="module-list-title"> Module List</h2>
<Card>
<table>

Choose a reason for hiding this comment

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

I would advise to avoid tables as much as possible. If you need a table-like layout, use divs with flexbox instead.

<h3>Modules</h3>
<tr className="module-table-row-item">
<ListGroup>
{moduleList &&

Choose a reason for hiding this comment

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

since moduleList defaults to empty array as per above definition [], this statement will always be true

Choose a reason for hiding this comment

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

Also, if you make the mapped list group item conditional, you should include the ListGroup and the tr tag above into the condition to avoid rendering those without any content

Comment on lines +7 to +9
<div className="navbar navbar-expand-lg navbar-light bg-light">
<h3>GPA Calculator</h3>
</div>

Choose a reason for hiding this comment

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

Hmmmm I am a bit on the fence, if this really needs an own component, as there is only an h3 being displayed 😅

Comment on lines +5 to +7
padding: 1%;
height: 2%;
margin-left: 5%;

Choose a reason for hiding this comment

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

I would avoid percentages for these properties. What is a 5% margin for example or a 1% padding? This doesn't really make sense and might have odd behaviour

align-items: left;
}
/* Thead */
/* TO FIX ALL OF THE FOLLOWING*/

Choose a reason for hiding this comment

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

Such comments are kinda redunant :) Mostly we will not do it, and therefore can just not keep this comment but rather keep a task in your todo list

constructor(props) {
super(props);
this.state = {
enabled: "1",

Choose a reason for hiding this comment

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

this should be a boolean

moduleName: "",
moduleList: JSON.parse(localStorage.getItem("moduleList")) || [],
grade: "A",
error: "",

Choose a reason for hiding this comment

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

nice job on adding validation to your form

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants