Rev 2245 | Rev 2381 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import React, { useState } from 'react'
import { useSelector } from 'react-redux'
import { SendOutlined, ChatOutlined } from '@mui/icons-material'
import withExternalShare from '../dashboard/linkedin/withExternalShare'
import withReactions from '@app/hocs/withReaction'
import Button from '../UI/buttons/Buttons'
import Paraphrase from '../UI/Paraphrase'
import PostFile from './PostFile'
import FeedReactions from '../dashboard/linkedin/feed/FeedReactions'
import CommentForm from '../dashboard/linkedin/comments/comment-form'
import CommentsList from '../dashboard/linkedin/comments/comment-list'
import Widget from '../UI/Widget'
function PostCard({
post,
addComment,
updateReactions,
updateMyReaction,
updateTotalShare
}) {
const {
reactions,
my_reaction,
reactions_url,
save_reaction_url,
delete_reaction_url,
total_share_external,
image,
title,
description,
file,
type,
comments,
share_external_url,
share_increment_external_counter_url
} = post
const [showComments, setShowComments] = useState(false)
const labels = useSelector(({ intl }) => intl.labels)
const displayCommentSection = () => {
setShowComments(!showComments)
}
const ExternalShareButton = withExternalShare(Button, share_external_url)
const ReactionButton = withReactions(Button)
return (
<Widget>
<Widget.Media
src={image}
alt={title}
styles={{
width: '100%',
maxHeight: '450px',
objectFit: 'contain'
}}
/>
<Widget.Body>
<h2>{title}</h2>
<Paraphrase>{description}</Paraphrase>
<PostFile file={file} type={type} />
</Widget.Body>
<div className='d-flex justify-content-between align-items-center px-3'>
<FeedReactions reactions={reactions} reactionsUrl={reactions_url} />
{!!total_share_external && (
<span>{`${total_share_external} ${labels.sends?.toLowerCase()}`}</span>
)}
</div>
<Widget.Actions>
<ReactionButton
currentReactionType={my_reaction}
saveUrl={save_reaction_url}
deleteUrl={delete_reaction_url}
onReaction={({ reactions }, currentReaction) => {
updateReactions(reactions)
updateMyReaction(currentReaction)
}}
/>
<Button onClick={displayCommentSection}>
<ChatOutlined style={{ color: 'gray' }} />
{labels.comment}
</Button>
<ExternalShareButton
shorterUrl={share_increment_external_counter_url}
setValue={updateTotalShare}
>
<SendOutlined style={{ color: 'gray' }} />
{labels.send}
</ExternalShareButton>
</Widget.Actions>
{showComments && (
<div className='px-3 pb-2'>
<CommentForm onSubmit={addComment} />
<CommentsList comments={comments} />
</div>
)}
</Widget>
)
}
export default PostCard