|
1 | 1 | import dayjs from 'dayjs'; |
2 | | -import React, { useEffect, useRef, useState } from 'react'; |
3 | | -import { FaHeart, FaRegHeart } from 'react-icons/fa'; |
4 | | -import { MdMoreHoriz } from 'react-icons/md'; |
5 | | -import { RiChat1Line } from 'react-icons/ri'; |
| 2 | +import React, { useEffect, useRef } from 'react'; |
6 | 3 | import { Link, useParams } from 'react-router-dom'; |
7 | 4 | import Avatar from '../components-ui/Avatar'; |
8 | 5 | import Card from '../components-ui/Card'; |
9 | 6 | import Container from '../components-ui/Container'; |
| 7 | +import Spinner from '../components-ui/Spinner'; |
10 | 8 | import AddComment from '../components/AddComment'; |
11 | | -import LikeButton from '../components/LikeButton'; |
12 | | -import { useGetSinglePostQuery } from '../generated/graphql'; |
| 9 | +import PostActions from '../components/PostActions'; |
| 10 | +import PostOptions from '../components/PostOptions'; |
| 11 | +import { Post, useGetSinglePostQuery } from '../generated/graphql'; |
13 | 12 |
|
14 | 13 | const SinglePost = () => { |
15 | | - const [liked, setLiked] = useState(false); |
16 | 14 | const { postId }: any = useParams(); |
17 | 15 | const { data, loading } = useGetSinglePostQuery({ variables: { postId } }); |
18 | 16 |
|
19 | 17 | // const { me } = apolloClient.readQuery({ query: MeDocument }); |
20 | 18 | const addCommentRef = useRef<HTMLInputElement>(null); |
21 | 19 |
|
22 | | - useEffect(() => { |
23 | | - setLiked(data?.getSinglePost?.userLike || false); |
24 | | - }, [setLiked, data]); |
25 | | - |
26 | 20 | useEffect(() => { |
27 | 21 | window.scrollTo({ top: 0 }); |
28 | 22 | }, []); |
29 | 23 |
|
30 | | - if (loading) return <div>Loading...</div>; |
| 24 | + if (loading) return <Spinner />; |
31 | 25 | if (data && data.getSinglePost) { |
32 | 26 | const { |
33 | 27 | id, |
@@ -55,9 +49,7 @@ const SinglePost = () => { |
55 | 49 | </Link> |
56 | 50 | </div> |
57 | 51 | {/* TODO Icon Button */} |
58 | | - <button> |
59 | | - <MdMoreHoriz size='1.5em' /> |
60 | | - </button> |
| 52 | + <PostOptions post={data.getSinglePost as Post} /> |
61 | 53 | </header> |
62 | 54 | {/* Media */} |
63 | 55 | <div className='md:h-full md:mr-80'> |
@@ -130,30 +122,16 @@ const SinglePost = () => { |
130 | 122 | </div> |
131 | 123 | {/* Like And Comment Button */} |
132 | 124 | <div> |
133 | | - <div className='flex items-center px-3 py-2 border-t border-gray-300'> |
134 | | - <LikeButton postId={id} liked={liked} setLiked={setLiked}> |
135 | | - {userLike ? ( |
136 | | - <FaHeart |
137 | | - size='1.5em' |
138 | | - className='mr-2 text-red-600 duration-150 transform cursor-pointer active:scale-110' |
139 | | - /> |
140 | | - ) : ( |
141 | | - <FaRegHeart |
142 | | - size='1.5em' |
143 | | - className='mr-2 duration-150 transform cursor-pointer active:scale-110' |
144 | | - /> |
145 | | - )} |
146 | | - </LikeButton> |
147 | | - <RiChat1Line |
148 | | - size='1.6em' |
149 | | - onClick={() => { |
150 | | - addCommentRef.current?.focus(); |
151 | | - }} |
152 | | - className='cursor-pointer' |
153 | | - /> |
154 | | - </div> |
| 125 | + <PostActions |
| 126 | + className='p-3' |
| 127 | + postId={id} |
| 128 | + addCommentRef={addCommentRef} |
| 129 | + userLike={userLike} |
| 130 | + /> |
155 | 131 | {/* Like Count */} |
156 | | - <p className='px-3 font-semibold'>{likeCount} likes</p> |
| 132 | + <p className='px-3 font-semibold'> |
| 133 | + {likeCount} like{likeCount === 1 ? '' : 's'} |
| 134 | + </p> |
157 | 135 | {/* TimeStamp */} |
158 | 136 | <Link |
159 | 137 | to={`/p/${id}`} |
|
0 commit comments