import * as React from 'react';
import { useSelector } from 'react-redux';
// material-ui
import { useTheme } from '@mui/material/styles';
import {
Button,
ButtonBase,
CardMedia,
Collapse,
FormHelperText,
Grid,
IconButton,
Menu,
MenuItem,
Stack,
TextField,
Typography,
useMediaQuery
} from '@mui/material';
// third-party
import * as yup from 'yup';
import uniqueId from 'lodash/uniqueId';
import { Controller, FormProvider, useForm } from 'react-hook-form';
import { yupResolver } from '@hookform/resolvers/yup';
import ReactMarkdown from 'react-markdown';
import gfm from 'remark-gfm';
// project imports
import Comment from './Comment';
import MainCard from '../MainCard';
import AnimateButton from 'ui-component/extended/AnimateButton';
import ImageList from 'ui-component/extended/ImageList';
import Avatar from 'ui-component/extended/Avatar';
import { DefaultRootStateProps, FormInputProps } from 'types';
import { CommentData, PostProps, Reply } from '_mockApis/user-profile/types';
// assets
import ShareTwoToneIcon from '@mui/icons-material/ShareTwoTone';
import FiberManualRecordIcon from '@mui/icons-material/FiberManualRecord';
import PeopleAltTwoToneIcon from '@mui/icons-material/PeopleAltTwoTone';
import ChatTwoToneIcon from '@mui/icons-material/ChatTwoTone';
import ContentCopyTwoToneIcon from '@mui/icons-material/ContentCopyTwoTone';
import MoreVertTwoToneIcon from '@mui/icons-material/MoreVertTwoTone';
import ThumbUpAltTwoToneIcon from '@mui/icons-material/ThumbUpAltTwoTone';
import ChatBubbleTwoToneIcon from '@mui/icons-material/ChatBubbleTwoTone';
const avatarImage = require.context('assets/images/profile', true);
const validationSchema = yup.object().shape({
name: yup.string().required('Comment Field is Required')
});
// ==============================|| COMMENT TEXTFIELD ||============================== //
const FormInput = ({ bug, label, size, fullWidth = true, name, required, ...others }: FormInputProps) => {
let isError = false;
let errorMessage = '';
if (bug && Object.prototype.hasOwnProperty.call(bug, name)) {
isError = true;
errorMessage = bug[name].message;
}
return (
<>
{errorMessage && (
{errorMessage}
)}
>
);
};
// ==============================|| SOCIAL PROFILE - POST ||============================== //
const Post = ({ commentAdd, handleCommentLikes, handlePostLikes, handleReplayLikes, post, replyAdd }: PostProps) => {
const theme = useTheme();
const { id, data, profile } = post;
const customization = useSelector((state: DefaultRootStateProps) => state.customization);
const matchesXS = useMediaQuery(theme.breakpoints.down('md'));
const [anchorEl, setAnchorEl] = React.useState(null);
const handleClick = (event: React.SyntheticEvent) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
const [anchorSharedEl, setAnchorSharedEl] = React.useState(null);
const handleSharedClick = (event: React.MouseEvent) => {
setAnchorSharedEl(event.currentTarget);
};
const handleSharedClose = () => {
setAnchorSharedEl(null);
};
const [openComment, setOpenComment] = React.useState(!(data.comments && data.comments.length > 0));
const handleChangeComment = () => {
setOpenComment((prev) => !prev);
};
let commentsResult:
| React.ReactElement>
| React.ReactElement>[] = <>>;
if (data && data.comments) {
commentsResult = data.comments.map((comment, index) => (
));
}
const methods = useForm({
resolver: yupResolver(validationSchema)
});
const { handleSubmit, errors, reset } = methods;
const onSubmit = async (comment: CommentData) => {
handleChangeComment();
const commentId = uniqueId('#COMMENT_');
const newComment: Reply = {
id: commentId,
profile,
data: {
comment: comment.name,
likes: {
like: false,
value: 0
},
replies: []
}
};
commentAdd(id, newComment);
reset({ name: '' });
};
return (
{profile.name}
{' '}
{profile.time}
{/* post - content */}
p': {
...theme.typography.body1,
mb: 0
}
}}
>
{data.content}
{/* post - photo grid */}
{data && data.images && data.images.length > 0 && (
)}
{/* post - video */}
{data.video && (
)}
{/* post - comment, likes and replay history */}
}
>
{data.comments ? data.comments.length : 0} comments
{/* add new comment */}
{commentsResult}
);
};
export default Post;