Skip to content

Commit

Permalink
fix: favorites notification
Browse files Browse the repository at this point in the history
  • Loading branch information
wrujel committed May 15, 2023
1 parent 821c3d4 commit 6b9929a
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions app/hooks/useFavorite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,15 @@ const useFavorite = ({ listingId, currentUser }: IUseFavorite) => {
}

try {
let request;

if (hasFavorited) {
request = () => axios.delete(`/api/favorites/${listingId}`);
await axios.delete(`/api/favorites/${listingId}`);
toast.success("Removed from favorites.");
} else {
request = () => axios.post(`/api/favorites/${listingId}`);
await axios.post(`/api/favorites/${listingId}`);
toast.success("Added to favorites.");
}

await request();
router.refresh();
if (hasFavorited) {
toast.success("Added to favorites.");
} else {
toast.success("Removed from favorites.");
}
} catch (error) {
toast.error("Something went wrong.");
}
Expand Down

0 comments on commit 6b9929a

Please sign in to comment.