import Link from 'next/link'; import format from 'date-fns/format'; import { FC, useContext } from 'react'; import UserContext from '@/contexts/userContext'; import { FaRegEdit } from 'react-icons/fa'; import beerPostQueryResult from '@/services/BeerPost/schema/BeerPostQueryResult'; import { z } from 'zod'; import useGetLikeCount from '@/hooks/useGetLikeCount'; import useTimeDistance from '@/hooks/useTimeDistance'; import BeerPostLikeButton from './BeerPostLikeButton'; const BeerInfoHeader: FC<{ beerPost: z.infer; }> = ({ beerPost }) => { const createdAt = new Date(beerPost.createdAt); const timeDistance = useTimeDistance(createdAt); const { user } = useContext(UserContext); const idMatches = user && beerPost.postedBy.id === user.id; const isPostOwner = !!(user && idMatches); const { likeCount, mutate } = useGetLikeCount(beerPost.id); return (

{beerPost.name}

by{' '} {beerPost.brewery.name}

{isPostOwner && (
)}

{' posted by '} {`${beerPost.postedBy.username} `} {timeDistance && ( {`${timeDistance} ago`} )}

{beerPost.description}

{beerPost.type.name}
{beerPost.abv}% ABV {beerPost.ibu} IBU
{likeCount && ( Liked by {likeCount} user{likeCount !== 1 && 's'} )}
{user && }
); }; export default BeerInfoHeader;