Skip to content

Delete round#3

Open
MedusCode wants to merge 3 commits intomainfrom
delete-round
Open

Delete round#3
MedusCode wants to merge 3 commits intomainfrom
delete-round

Conversation

@MedusCode
Copy link
Copy Markdown
Collaborator

Description

Add "delete round" functionality to the SpeedScore app. A user can delete a round by clicking on the garbage can icon associated with the round in the "Rounds" table.

Related Issue(s)

Addresses #1

Type of Change

  • New Feature
  • Bug Fix
  • Documentation update
  • Other (describe)

Testing

I manually tested this functionality by creating and deleting rounds.

Pre-Submission Checklist

  • The code executes; my changes do not break the build
  • My changes do not generate new warnings
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added automated tests demonstrating that the feature works or that fix is correct
  • New and existing unit tests pass locally with my changes
  • Any changes on which this PR depends have been merged and published in upstream modules

@MedusCode MedusCode requested review from a team as code owners May 5, 2025 22:55
Copy link
Copy Markdown
Collaborator Author

@MedusCode MedusCode left a comment

Choose a reason for hiding this comment

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

Good job with HTML markup

Comment thread index.html
Comment on lines +1560 to +1578
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Delete Round?</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>Do you really want to delete that round?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
No, Cancel
</button>
<button type="button" id="confirmDeleteBtn" class="btn btn-primary" onclick="">
Yes, Delete Round
</button>
</div>
</div>
</div>
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good job. The HTML markup is well written, and most semantic tags are correctly used.

Comment thread index.html
</form>
</div>
<div class="modal-dialog">
<div class="modal-content">
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Consider using a semantic <section> tag for better structure and accessibility.

Comment thread index.html
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
No, Cancel
</button>
<button type="button" id="confirmDeleteBtn" class="btn btn-primary" onclick="">
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

onClick="" doesn't do anything and might confuse. Consider removing it since the event listener is set in the JS.

Comment thread scripts/roundsMode.js
Comment on lines +221 to +257
* @function confirmDelete
* @desc
* Present pop-up modal dialog asking user to confirm delete operation
* @param roundId -- the unique id of the round to be deleted
* @returns -- true if user confirms delete, false otherwise
*************************************************************************/
function confirmDelete(roundId) {
//TO DO: Present modal dialog prompting user to confirm delete
//Return true if user confirms delete, false otherwise
let modal = new bootstrap.Modal(
document.getElementById("confirmDeleteRoundModal")
);
let confirmBtn = document.getElementById("confirmDeleteBtn");
confirmBtn.addEventListener("click", function (event) {
event.preventDefault();
console.log("deleting round with id " + roundId);
for (var i = 0; i < GlobalRoundsTable.rows.length; i++) {
let row = GlobalRoundsTable.rows[i];
// Check if the id of the row matches the id you're looking for
if (row.id === "r-" + roundId) {
GlobalRoundsTable.deleteRow(i);
break;
}
}
deleteRound(roundId);
localStorage.setItem(
GlobalUserData.accountInfo.email,
JSON.stringify(GlobalUserData)
);
GlobalRoundsTableCaption.textContent =
"Table displaying " +
(GlobalRoundsTable.rows.length - 1) +
" speedgolf rounds";
modal.hide();
});
modal.show();
}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Well implemented function, it's easy to follow and the logic is clear. Just a couple of things to consider below

Comment thread scripts/roundsMode.js
* @desc
* Present pop-up modal dialog asking user to confirm delete operation
* @param roundId -- the unique id of the round to be deleted
* @returns -- true if user confirms delete, false otherwise
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The function doesn't return anything, but the comment says it returns a boolean. To avoid confusion, it might be a good idea to either update the comment or return a boolean.

Comment thread scripts/roundsMode.js
* @param roundId -- the unique id of the round to be deleted
* @returns -- true if user confirms delete, false otherwise
*************************************************************************/
function confirmDelete(roundId) {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Would it make sense to add a quick check for roundId type? This could help prevent issues with unexpected input.

Comment thread scripts/roundsMode.js
Comment on lines +230 to +233
let modal = new bootstrap.Modal(
document.getElementById("confirmDeleteRoundModal")
);
let confirmBtn = document.getElementById("confirmDeleteBtn");
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Consider moving HTML elements to global constants in main.js and checking they're not undefined before use for better reliability.

Comment thread scripts/roundsMode.js
document.getElementById("confirmDeleteRoundModal")
);
let confirmBtn = document.getElementById("confirmDeleteBtn");
confirmBtn.addEventListener("click", function (event) {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Each time confirmDelete runs, a new click handler is added. To prevent duplicates, consider using { once: true } when adding the listener.

Comment thread scripts/roundsMode.js
confirmBtn.addEventListener("click", function (event) {
event.preventDefault();
console.log("deleting round with id " + roundId);
for (var i = 0; i < GlobalRoundsTable.rows.length; i++) {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Consider switching to let for better block scoping and modern JS practice.

You could also use findIndex() instead of the loop to make the code shorter and more readable.

Copy link
Copy Markdown
Collaborator Author

@MedusCode MedusCode left a comment

Choose a reason for hiding this comment

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

Good job with deleteRound function. Check my comments for improvement.

Comment thread scripts/roundsMode.js
Comment on lines +220 to +232
/*************************************************************************
* @function deleteRound
* @desc
* Deletes a round from the "Rounds" table and from local storage
* @param roundId -- the unique id of the round to be deleted
* @returns -- true if round could be deleted, false otherwise
*************************************************************************/
function deleteRound(roundId) {
GlobalUserData.rounds = GlobalUserData.rounds.filter(function (round) {
return round.roundNum !== roundId;
});
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good function implementation. Using filter to remove the round is a good idea.

Comment thread scripts/roundsMode.js
/*************************************************************************
* @function deleteRound
* @desc
* Deletes a round from the "Rounds" table and from local storage
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The docstring says this deletes from both a "Rounds" table and local storage, but it looks like it only updates the GlobalUserData.rounds array. You might want to tweak the description so it doesn't cause confusion later.

Comment thread scripts/roundsMode.js
* @desc
* Deletes a round from the "Rounds" table and from local storage
* @param roundId -- the unique id of the round to be deleted
* @returns -- true if round could be deleted, false otherwise
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The function doesn't return anything, but the comment says it returns a boolean. To avoid confusion, it might be a good idea to either update the comment or return a boolean.

Comment thread scripts/roundsMode.js
* @param roundId -- the unique id of the round to be deleted
* @returns -- true if round could be deleted, false otherwise
*************************************************************************/
function deleteRound(roundId) {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Would it make sense to add a quick check for roundId type? This could help prevent issues with unexpected input.

Comment thread scripts/roundsMode.js
Comment on lines +228 to +230
GlobalUserData.rounds = GlobalUserData.rounds.filter(function (round) {
return round.roundNum !== roundId;
});
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Consider using an arrow function for brevity and modern JS style.

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.

1 participant