Conversation
MedusCode
left a comment
There was a problem hiding this comment.
Good job with HTML markup
| <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> |
There was a problem hiding this comment.
Good job. The HTML markup is well written, and most semantic tags are correctly used.
| </form> | ||
| </div> | ||
| <div class="modal-dialog"> | ||
| <div class="modal-content"> |
There was a problem hiding this comment.
Consider using a semantic <section> tag for better structure and accessibility.
| <button type="button" class="btn btn-secondary" data-bs-dismiss="modal"> | ||
| No, Cancel | ||
| </button> | ||
| <button type="button" id="confirmDeleteBtn" class="btn btn-primary" onclick=""> |
There was a problem hiding this comment.
onClick="" doesn't do anything and might confuse. Consider removing it since the event listener is set in the JS.
| * @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(); | ||
| } |
There was a problem hiding this comment.
Well implemented function, it's easy to follow and the logic is clear. Just a couple of things to consider below
| * @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 |
There was a problem hiding this comment.
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.
| * @param roundId -- the unique id of the round to be deleted | ||
| * @returns -- true if user confirms delete, false otherwise | ||
| *************************************************************************/ | ||
| function confirmDelete(roundId) { |
There was a problem hiding this comment.
Would it make sense to add a quick check for roundId type? This could help prevent issues with unexpected input.
| let modal = new bootstrap.Modal( | ||
| document.getElementById("confirmDeleteRoundModal") | ||
| ); | ||
| let confirmBtn = document.getElementById("confirmDeleteBtn"); |
There was a problem hiding this comment.
Consider moving HTML elements to global constants in main.js and checking they're not undefined before use for better reliability.
| document.getElementById("confirmDeleteRoundModal") | ||
| ); | ||
| let confirmBtn = document.getElementById("confirmDeleteBtn"); | ||
| confirmBtn.addEventListener("click", function (event) { |
There was a problem hiding this comment.
Each time confirmDelete runs, a new click handler is added. To prevent duplicates, consider using { once: true } when adding the listener.
| confirmBtn.addEventListener("click", function (event) { | ||
| event.preventDefault(); | ||
| console.log("deleting round with id " + roundId); | ||
| for (var i = 0; i < GlobalRoundsTable.rows.length; i++) { |
There was a problem hiding this comment.
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.
MedusCode
left a comment
There was a problem hiding this comment.
Good job with deleteRound function. Check my comments for improvement.
| /************************************************************************* | ||
| * @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; | ||
| }); | ||
| } | ||
|
|
There was a problem hiding this comment.
Good function implementation. Using filter to remove the round is a good idea.
| /************************************************************************* | ||
| * @function deleteRound | ||
| * @desc | ||
| * Deletes a round from the "Rounds" table and from local storage |
There was a problem hiding this comment.
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.
| * @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 |
There was a problem hiding this comment.
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.
| * @param roundId -- the unique id of the round to be deleted | ||
| * @returns -- true if round could be deleted, false otherwise | ||
| *************************************************************************/ | ||
| function deleteRound(roundId) { |
There was a problem hiding this comment.
Would it make sense to add a quick check for roundId type? This could help prevent issues with unexpected input.
| GlobalUserData.rounds = GlobalUserData.rounds.filter(function (round) { | ||
| return round.roundNum !== roundId; | ||
| }); |
There was a problem hiding this comment.
Consider using an arrow function for brevity and modern JS style.
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
Testing
I manually tested this functionality by creating and deleting rounds.
Pre-Submission Checklist