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

[Ready for Review] Fix Helpful Reviews #377

Merged
merged 13 commits into from
Dec 4, 2024
Merged

[Ready for Review] Fix Helpful Reviews #377

merged 13 commits into from
Dec 4, 2024

Conversation

kea-roy
Copy link
Member

@kea-roy kea-roy commented Nov 8, 2024

Summary

This pull request resolves front-end and back-end issues with marking reviews as helpful. The most important changes include updating the backend API endpoint for fetching liked reviews, adding a new icon for helpful reviews on the frontend, and refactoring the frontend components to handle review data more efficiently.

Checklist

  • Front-end
    • Added helpful icon to the button
    • Adjust Pages with Reviews to fetch status on start.
      • apartment page
      • bookmarks page
      • landlord page
      • profile page
    • Ensure the page only attempts to fetch helpful status if the user is logged in
  • Back-end
    • Changed API endpoint to support working on pending reviews, uses a query parameter to support filtering by type of review

Changes

Backend Changes:

  • Updated the API endpoint to fetch reviews liked by a user, including the ability to filter by review status. Added error handling for unauthorized access. (backend/src/app.ts)

Frontend Changes:

  • Review Component Enhancements:

    • Added a new HelpfulIcon for displaying the helpfulness of reviews. (frontend/src/components/Review/Review.tsx) [1] [2] [3]
    • Refactored the ReviewComponent to directly use the review prop instead of maintaining a separate state for reviewData. (frontend/src/components/Review/Review.tsx) [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]
  • Page Component Updates:

    • Added logic to fetch and set the reviews liked by the user on various pages, ensuring the liked reviews and their statuses are correctly displayed. (frontend/src/pages/ApartmentPage.tsx) [1] (frontend/src/pages/BookmarksPage.tsx) [2] [3] [4] (frontend/src/pages/LandlordPage.tsx) [5] (frontend/src/pages/ProfilePage.tsx) [6]

Test Plan

Tested using Postman and end-to-end user testing. I tested the API endpoint to ensure it returns correctly and is called correctly on all pages. I tried testing while logged in and while not logged in, liking it before and after, and spam clicking.

(Not marked helpful)
Screenshot 2024-11-11 at 4 41 57 PM

(Marked helpful)
Screenshot 2024-11-11 at 4 40 40 PM

Notes

  • This PR changes ReviewComponent by removing the reviewData react state. This allows the review parameter to control the state of ReviewComponent, so that when a page updates that review, the review also updates.

- supports optional query parameter to filter by status
- by default it will not filter by status
- add documentation for review/like/:userId
- simplified update process
- removed useState for reviewData so changes to originally passed prop review will update on the component.
- added helpful icon
- ensure color of icon updated when liked
- adds query term for APPROVED
- delete from the list locally when it is disliked
- update pending reviews locally when like changes
@dti-github-bot
Copy link
Member

dti-github-bot commented Nov 8, 2024

[diff-counting] Significant lines: 249.

@kea-roy kea-roy linked an issue Nov 8, 2024 that may be closed by this pull request
@kea-roy kea-roy changed the title [WIP] Fix Helpful Reviews [Ready for Review] Fix Helpful Reviews Nov 12, 2024
Copy link
Contributor

@CasperL1218 CasperL1218 left a comment

Choose a reason for hiding this comment

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

The like/helpful review functionality is robust and works well on each page.

I like the implementation of the design which makes the functionality more intuitive.

There is an edge case in the /api/review/like/:userId endpoint where a user with an existing likes document but no actual likes (so empty document) will trigger a Firestore error:

Error: Invalid Query. A non-empty array is required for 'in' filters.

Suggested fix is adding to backend/src/app.ts:184-187:

if (reviewIds.length === 0) { res.status(200).send(JSON.stringify([])); return; }

This fix handles the empty like situation by returning an empty array, which is the same behavior as if the user does not have an existing document.

backend/src/app.ts Show resolved Hide resolved
@kea-roy kea-roy dismissed CasperL1218’s stale review December 3, 2024 23:49

I have resolved and fixed the issue

@ggsawatyanon ggsawatyanon self-requested a review December 4, 2024 00:46
Copy link
Contributor

@ggsawatyanon ggsawatyanon 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 on this PR, this has been a bug in our codebase for a while so thanks for fixing it! Also, the updated helpful reviews button helps us match the site to the CU Apts design system for consistency so good job with that too.

@ggsawatyanon ggsawatyanon merged commit 4b57b98 into main Dec 4, 2024
4 checks passed
@ggsawatyanon ggsawatyanon deleted the fix-helpful branch December 4, 2024 00:51
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.

Like reviews not recognized on Apt/ Landlord page
4 participants