mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
Add custom hooks for time distance and retrieving like count
Documentation added to all custom hooks
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import useCheckIfUserLikesBeerPost from '@/hooks/useCheckIfUserLikesBeerPost';
|
||||
import sendLikeRequest from '@/requests/sendLikeRequest';
|
||||
import { Dispatch, FC, SetStateAction, useState } from 'react';
|
||||
import { FC, useState } from 'react';
|
||||
import { FaThumbsUp, FaRegThumbsUp } from 'react-icons/fa';
|
||||
import { KeyedMutator } from 'swr';
|
||||
|
||||
const BeerPostLikeButton: FC<{
|
||||
beerPostId: string;
|
||||
setLikeCount: Dispatch<SetStateAction<number>>;
|
||||
}> = ({ beerPostId, setLikeCount }) => {
|
||||
mutateCount: KeyedMutator<number>;
|
||||
}> = ({ beerPostId, mutateCount }) => {
|
||||
const { isLiked, mutate: mutateLikeStatus } = useCheckIfUserLikesBeerPost(beerPostId);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
@@ -14,7 +15,7 @@ const BeerPostLikeButton: FC<{
|
||||
try {
|
||||
setLoading(true);
|
||||
await sendLikeRequest(beerPostId);
|
||||
setLikeCount((prevCount) => prevCount + (isLiked ? -1 : 1));
|
||||
mutateCount();
|
||||
mutateLikeStatus();
|
||||
setLoading(false);
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user