diff --git a/client/src/components/PostCard.jsx b/client/src/components/PostCard.jsx
index d9133fc..7700afc 100644
--- a/client/src/components/PostCard.jsx
+++ b/client/src/components/PostCard.jsx
@@ -1,7 +1,7 @@
import React, { useRef, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { Card, CardHeader, CardMedia, CardContent, CardActions, IconButton, Typography, Button, Popover, Paper, Stack, Box, Fade, CircularProgress, TextField, Autocomplete, Input, Tooltip } from '@mui/material'
-import { ThumbUp, Delete, Favorite, EmojiEmotions, SentimentVeryDissatisfied, Mood, SentimentDissatisfied, ThumbUpOutlined, Edit, Cancel, Save, Refresh, VisibilityOff, Visibility, LockOpen, Lock } from '@mui/icons-material'
+import { ThumbUp, Delete, Favorite, EmojiEmotions, SentimentVeryDissatisfied, Mood, SentimentDissatisfied, ThumbUpOutlined, Edit, Cancel, Save, Refresh, VisibilityOff, Visibility, Lock } from '@mui/icons-material'
import { UserAvatar } from '.'
import moment from 'moment'
import { getThumbnail, convertToBase64 } from '@/lib/utils'
@@ -21,19 +21,22 @@ const PostCard = ({ post }) => {
const { user } = useUser()
const [editing, setEditing] = useState(false)
const [editedPost, setEditedPost] = useState(post)
-
+ const initialErrors = { title: '', description: '', tags: '', media: '' }
const { mutate: deletePost, isPending: isDeleting } = useDeletePost()
const { mutate: updatePost, isPending: isUpdating } = useUpdatePost()
const [reactionAnchorEl, setReactionAnchorEl] = useState(null)
const [currentReaction, setCurrentReaction] = useState(post.reactions[0]?.reactionType)
- const [errors, setErrors] = useState({ title: '', description: '', tags: '', media: '' })
+ const [errors, setErrors] = useState(initialErrors)
const popoverTimeoutRef = useRef(null)
const navigate = useNavigate()
const handleReactionIconEnter = (event) => {
+ if (!user) {
+ return
+ }
clearTimeout(popoverTimeoutRef.current)
setReactionAnchorEl(event.currentTarget)
}
@@ -112,6 +115,7 @@ const PostCard = ({ post }) => {
media: editedPost.media ? await convertToBase64(editedPost.media) : editedPost.imageUrl
})
setEditing(false)
+ setEditedPost(post)
} catch (error) {
console.error(error)
}
@@ -122,7 +126,26 @@ const PostCard = ({ post }) => {
setErrors({ title: '', description: '', tags: '', media: '' })
}
- const handleTagInput = (params) =>
+ const handleTagInput = (params) => {
+ return (
+
+ )
+ }
+ const truncate = (text, wordLimit) => {
+ const words = text.split(' ')
+ if (words.length > wordLimit) {
+ return words.slice(0, wordLimit).join(' ') + '...'
+ }
+ return text
+ }
return (
@@ -139,8 +162,9 @@ const PostCard = ({ post }) => {
sx={{
height: { md: 160, xs: 200 },
position: 'relative',
+
...(!editing && {
- '&::after': {
+ ':after': {
content: '""',
position: 'absolute',
top: 0,
@@ -151,9 +175,10 @@ const PostCard = ({ post }) => {
zIndex: 1
}
}),
+
...(editing && {
- '&:hover': {
- '&::after': {
+ ':hover': {
+ ':after': {
height: '100%',
content: '"Click to change image"',
display: 'flex',
@@ -210,16 +235,9 @@ const PostCard = ({ post }) => {
) : (
- {post.title}
+ {truncate(post.title, 10)}
)}
- {!editing && post.visibility === 'PRIVATE' && (
-
-
-
-
-
- )}
{editing ? (
{
{post.tags.map(({ tag }) => `#${tag.name} `)}
)}
+ {!editing && post.visibility === 'PRIVATE' && (
+
+
+
+
+
+ )}
{editing ? (
) : (
- {post.description}
+ {truncate(post.description, 20)}
)}
-
+
{!editing ? (
-
+
{currentReaction ? : }
{post.reactionCount || ''}