Iamogeee / KUDOS-BOARD

0 stars 0 forks source link

Codepath Week 3 feedback - Kudos Board #2

Open jose-esquivel opened 4 days ago

jose-esquivel commented 4 days ago

Thread for providing feedback for Ogenna's third week project.

Commits: https://github.com/Iamogeee/KUDOS-BOARD/commits/main/

sinap-fb commented 4 days ago

Nice work! The server code was well organized and easy to follow! One thing I noticed is that the deployed site doesn't seem to work for. It seems like the fetches are hitting localhost:3000 instead of the production backend.

Screenshot 2024-06-24 at 3 32 48 PM

However, I didn't see any mention of localhost in the code, so I assume this was fixed but the fix hasn't been deployed yet?

Code review:

Things to consider for the future:

Super nitpicks:

jose-esquivel commented 3 days ago

Great work again, Ogenna!

I'm happy to see how you continue to develop your knowledge and coding style through these projects.

Highlights

Code feedback

Commit style

UI/UX polish feedback

mylesdomingo commented 22 hours ago

Hey, a bit of a late review, but this project looks good! I have a couple points of feedback:

Highlights

  1. Nice work on handling various promises and improving on async/await calls from last week. Looks like you got the hang of it.

    Code Quality

  2. When rendering multiple elements in a list, its generally good to use a map. Instead of:
    <Button name="All" />
    <Button name="Recent" />
    <Button name="Celebration" />
    <Button name="Thank You" />
    <Button name="Inspiration" />

    I'd do something like:

    const buttons = {...}
    return buttons.map(({name}) => <Button name={name} />)

It's a bit silly now, but when you have multiple of the same props and stylings and more than 5 objects, it saves a lot of time/redundancy.

  1. I think handleDisplayBoard and handleDeleteBoard could have been handled more efficiently. For context, handleDisplayBoard makes a call to our backend to fetch data. That call could be computationally expensive.

We also have a local state const [boards, setBoards] = useState([]); that tracks the boards currently on display in the screen. When we delete a board via handleDeleteBoard. We call handleDisplayBoard and make that fetch all over again -- in cases where network fetching is expensive, so we want to avoid doing so!

Instead I would have like to have seen treating the local state as a "cache". In handleDeleteBoard, we write to our db. We know what our local state should look like, so we can update this as well directly. We do not call handleDisplayBoard again. We only should fetch maybe once per refresh. This would look something like:

  async function handleDisplayBoard() {
    const response = await fetch("http://localhost:3000/boards", {
      method: "GET",
      headers: {
        "Content-Type": "application/json",
      },
    });
    const data = await response.json();
    setBoards(data);
  }

  useEffect(() => {
    handleDisplayBoard();
  });

  async function handleDeleteBoard(id) {
    try {
      const response = await fetch(`http://localhost:3000/boards/${id}`, {
        method: "DELETE",
        headers: {
          "Content-Type": "application/json",
        },
      });
      if (response.ok) {
         setBoards(boards.filter(boards => board.id != id)) 
      }
    } catch (err) {
      console.log(err);
    }
  }

Notice how we update our local state without making a roundabout fetch from our db. There's more optimizations to be done with caching, maybe turning the list into an object for O(1) indexing. But the principles remains the same: network calls are performance intensive, optimizing these calls increases app responsivity!

You probabaly already know this, but here's a primer on big-O notation (just in case). It's applicable for front-end too! https://www.shecodes.io/athena/52559-understanding-big-o-notation-in-javascript#:~:text=Big%20O%20notation%20is%20a,the%20more%20time%20it%20takes.