(
+ `/api/review/like/${user.uid}`,
+ {
+ callback: (reviews) => {
+ const likedReviewsMap: Likes = {};
+ const likeStatusesMap: Likes = {};
+ reviews.forEach((review) => {
+ likedReviewsMap[review.id] = true;
+ likeStatusesMap[review.id] = false;
+ });
+ setLikedReviews(likedReviewsMap);
+ setLikeStatuses(likeStatusesMap);
+ },
+ },
+ createAuthHeaders(token)
+ );
+ });
+ }
+ });
+ }, []);
+
const likeHelper = (dislike = false) => {
return async (reviewId: string) => {
setLikeStatuses((reviews) => ({ ...reviews, [reviewId]: true }));
@@ -199,7 +234,16 @@ const ProfilePage = ({ user, setUser }: Props): ReactElement => {
const token = await user.getIdToken(true);
const endpoint = dislike ? '/api/remove-like' : '/api/add-like';
await axios.post(endpoint, { reviewId }, createAuthHeaders(token));
- setLikedReviews((reviews) => ({ ...reviews, [reviewId]: !dislike }));
+ setLikedReviews((reviews) => {
+ return { ...reviews, [reviewId]: !dislike };
+ });
+ setPendingReviews((reviews) =>
+ reviews.map((review) =>
+ review.id === reviewId
+ ? { ...review, likes: (review.likes || defaultLikes) + offsetLikes }
+ : review
+ )
+ );
setApprovedReviews((reviews) =>
reviews.map((review) =>
review.id === reviewId
@@ -261,6 +305,17 @@ const ProfilePage = ({ user, setUser }: Props): ReactElement => {
};
}, [isModalOpen, setIsModalOpen]);
+ const Modals = (
+ <>
+
+ >
+ );
+
return (
@@ -327,7 +382,7 @@ const ProfilePage = ({ user, setUser }: Props): ReactElement => {
{/* Maps list of pending reviews and calls Review Component with fields for each user*/}
{sortReviews(pendingReviews, 'date').map((review, index) => (
-
+
{
setToggle={setToggle}
triggerEditToast={showEditSuccessConfirmationToast}
triggerDeleteToast={showDeleteSuccessConfirmationToast}
+ triggerPhotoCarousel={showPhotoCarousel}
user={user}
setUser={setUser}
showLabel={true}
@@ -352,6 +408,7 @@ const ProfilePage = ({ user, setUser }: Props): ReactElement => {
{sortReviews(approvedReviews, 'date').map((review, index) => (
{
setToggle={setToggle}
triggerEditToast={showEditSuccessConfirmationToast}
triggerDeleteToast={showDeleteSuccessConfirmationToast}
+ triggerPhotoCarousel={showPhotoCarousel}
user={user}
setUser={setUser}
showLabel={true}
@@ -384,6 +442,7 @@ const ProfilePage = ({ user, setUser }: Props): ReactElement => {
)}
+ {Modals}
);
};