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

CYF-ITP-South Africa | Serna Malala | Module-Data-Groups | Week 3 Todo List #287

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

sernamalala
Copy link

@sernamalala sernamalala commented Jan 11, 2025

Learners, PR Template

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

Briefly explain your PR.
I created a todolist app that dynamically adds todo items to the screen using javascript. The check mark and delete buttons also work to strikethrough and delete the items.

Questions

Ask any questions you have for your reviewer.

@sernamalala sernamalala added 📅 Sprint 3 Assigned during Sprint 3 of this module Needs Review Participant to add when requesting review labels Jan 11, 2025
Copy link

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

The code works well. I only have some suggestions and comments for possible code improvement.

Comment on lines +24 to +31
listItem.style.background = "lightblue";
listItem.style.padding = "1em";
listItem.style.display = "inline-block";
listItem.style.margin = "0.5em";
listItem.textContent = todoItem.task;
list.style.margin = "0 auto";
list.style.backgroundColor = "#FCC4AB";
body.style.textAlign = "center"
Copy link

Choose a reason for hiding this comment

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

Why not set CSS styles in styles.css? That way, whenever we need to change the view we don't have to change the code.

list.style.backgroundColor = "#FCC4AB";
body.style.textAlign = "center"

list.appendChild(breakLine);
Copy link

Choose a reason for hiding this comment

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

Adding <br> to a list would result in creating something like

<ul>
<li>....</li>
<br>
<li>...</li>
<br>
</ul>

which is considered an error in HTML.

Can you think of a better way to create space between list items using only CSS?


let todo = {};

if (inputFieldValue.length > 0) {
Copy link

Choose a reason for hiding this comment

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

Do you want to accept any input containing only space characters?


if (todoID) {
todos.splice(parseInt(todoID), 1);
listItem.remove();
Copy link

Choose a reason for hiding this comment

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

Is line 76 necessary? The next statement, populateTodoList(), will update the whole UI by reconstructing all the elements that make up UI.



deleteButton.addEventListener("click", function () {
const listItem = this.closest("li");
Copy link

Choose a reason for hiding this comment

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

Do you know what this is at line 71?

Comment on lines +57 to +65
if (todoID && todos[parseInt(todoID)].completed === false) {
todos[parseInt(todoID)].completed = true;
listItem.style.textDecoration = "line-through";

}
else {
todos[parseInt(todoID)].completed = false;
listItem.style.textDecoration = "none";
}
Copy link

Choose a reason for hiding this comment

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

Why not just call populateTodoList() at line 59 and 64 to update the whole UI?

Any chance todoID is undefined or an empty string?
The code at lines 57-65 could possibly be reduced to 2-3 lines of code.

Comment on lines +44 to +46
checkMark.id = todoButtonsIndex;
deleteButton.id = todoButtonsIndex;
todoButtonsIndex++;
Copy link

Choose a reason for hiding this comment

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

  • These id values are not unique.
  • Why do you want to assign id to these two buttons? Where are these id values being used?
  • If you don't need these id values, you probably won't need todoButtonsIndex.


let todoButtonsIndex = 0;

let todoButtons = `<span class="badge bg-primary rounded-pill">
Copy link

Choose a reason for hiding this comment

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

If todoButtons does not need to be reassigned a different value later, it is better to declare it using const.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review and removed Needs Review Participant to add when requesting review labels Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reviewed Volunteer to add when completing a review 📅 Sprint 3 Assigned during Sprint 3 of this module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants