Skip to content

Birmingham | 26-SDC-Mar | Chioma Okeke | Sprint 2 | Chat App#84

Open
JanefrancessC wants to merge 8 commits into
CodeYourFuture:mainfrom
JanefrancessC:sprint2-chat-app
Open

Birmingham | 26-SDC-Mar | Chioma Okeke | Sprint 2 | Chat App#84
JanefrancessC wants to merge 8 commits into
CodeYourFuture:mainfrom
JanefrancessC:sprint2-chat-app

Conversation

@JanefrancessC
Copy link
Copy Markdown

@JanefrancessC JanefrancessC commented May 26, 2026

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

Backend link
Frontend link

Additional Feature

  • I added the like and dislike buttons, which are incremented on click.

@JanefrancessC JanefrancessC added 📅 Sprint 2 Assigned during Sprint 2 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Decomposition The name of the module. labels May 26, 2026
Copy link
Copy Markdown

@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.

  1. Code works well on normal circumstances. Well done.

  2. Code could use some documentation (comments).

    A useful rule of thumb is to ask yourself whether you could still explain or figure out how the code works few months from now. If the answer is uncertain, consider adding a comment to help future readers understand the intent and reasoning behind it.

  3. The README has this requirement:

    It must also support at least one additional feature.

    In the PR description, can you list the extra features you implemented?

Comment thread chat-app/backend/index.js Outdated
Comment thread chat-app/backend/index.js
Comment thread chat-app/backend/index.js Outdated
Comment thread chat-app/backend/index.js Outdated
Comment thread chat-app/frontend/script.js Outdated
Comment thread chat-app/frontend/script.js Outdated
Comment on lines +88 to +107
async function dislikeMessage(msgId) {
try {
const response = await fetch(`${serverURL}/${msgId}/dislike`, {
method: "POST",
});

if (!response.ok) {
feedbackEl.innerHTML = `<p>${await response.text()}</p>`;
return;
}
const updatedMessage = await response.json();

state.messages = state.messages.map((msg) =>
msg.id === updatedMessage.id ? updatedMessage : msg,
);
displayMessages();
} catch (error) {
console.error(error.message);
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The code in dislikeMessage() and likeMessage() is nearly identical and could be refactored to reduce duplication.

The same also applies to their counterparts on the server side.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I will also modify this by creating a generic function, then using a conditional statement to increment either the like or dislike button.

Comment thread chat-app/frontend/script.js Outdated
Comment thread chat-app/frontend/script.js Outdated
Comment thread chat-app/frontend/script.js Outdated
Comment thread chat-app/frontend/script.js Outdated
@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels May 29, 2026
@JanefrancessC
Copy link
Copy Markdown
Author

  1. Code works well on normal circumstances. Well done.

  2. Code could use some documentation (comments).
    A useful rule of thumb is to ask yourself whether you could still explain or figure out how the code works few months from now. If the answer is uncertain, consider adding a comment to help future readers understand the intent and reasoning behind it.

  3. The README has this requirement:

    It must also support at least one additional feature.

    In the PR description, can you list the extra features you implemented?

Thank you for the thorough feedback. I have edited the PR to include the extra feature and will modify my code per the review.

@JanefrancessC JanefrancessC added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Jun 4, 2026
Copy link
Copy Markdown

@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.

Changes look great. I especially like the internal documentation (comments) because they really make reading the code easier.

I only have a few more comments for you to consider. Change is optional.

Comment thread chat-app/backend/index.js
* longPoll - If true and there are no new messages, holds the connection open
* until there are new messages instead of returning empty array.
*/
app.get("/", (req, res) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I missed this in my previous review. Could you use an AI to find out

Why /messages would make a better URI than / for a service that get and add messages?

Comment thread chat-app/backend/index.js
Comment on lines +90 to +109
app.post("/:id/:reaction", (req, res) => {
const id = Number(req.params.id);
const reaction = req.params.reaction;

const message = messages.find((msg) => msg.id === id);
if (!message) {
res.status(404).json({ error: "Message not found" });
return;
}

if (reaction === "like") {
message.likes++;
} else if (reaction === "dislike") {
message.dislikes++;
} else {
res.status(400).json({ error: "Invalid reaction!" });
return;
}
res.json(message);
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could consider rearrange the code this way to prevent unnecessary operations from being performed when input is invalid:

app.post("/:id/:reaction", (req, res) => {
  const id = Number(req.params.id);
  const reaction = req.params.reaction;

  // Validate id and reaction first

  // if reaction is invalid
  if (...) {
    res.status(400).json({ error: "Invalid reaction!" });
    return;
  }

  const message = messages.find((msg) => msg.id === id);
  if (!message) {
    res.status(404).json({ error: "Message not found" });
    return;
  }

  if (reaction === "like") {
    message.likes++;
  } else if (reaction === "dislike") {
    message.dislikes++;
  }

  res.json(message);
});

const p = document.createElement("p");

const strong = document.createElement("strong");
strong.textContent = `${msg.user}: ${msg.message} `;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Note: An alternative is to implement a helper function

function escapeHtml(str) {
  const div = document.createElement("div");
  div.textContent = str;
  return div.innerHTML;
}

to escape special characters and use your original approach to construct the desired element.

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. Module-Decomposition The name of the module. 📅 Sprint 2 Assigned during Sprint 2 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants