import React, { FC, HTMLAttributes, useMemo } from 'react'; import { CommentWrapper } from '~/components/containers/CommentWrapper'; import { IComment, IFile } from '~/redux/types'; import * as styles from './styles.scss'; import { formatCommentText, getURL, getPrettyDate } from '~/utils/dom'; import { Group } from '~/components/containers/Group'; import assocPath from 'ramda/es/assocPath'; import append from 'ramda/es/append'; import reduce from 'ramda/es/reduce'; import { UPLOAD_TYPES } from '~/redux/uploads/constants'; import { Player } from '~/utils/player'; import classNames from 'classnames'; type IProps = HTMLAttributes & { is_empty?: boolean; is_loading?: boolean; comment?: IComment; is_same?: boolean; }; const Comment: FC = ({ comment, is_empty, is_same, is_loading, className, ...props }) => { const groupped = useMemo>( () => reduce( (group, file) => assocPath([file.type], append(file, group[file.type]), group), {}, comment.files ), [comment] ); return ( {comment.text && ( )} {getPrettyDate(comment.created_at)} {groupped.image && ( {groupped.image.map(file => ( ))} )} {groupped.audio && ( {groupped.audio.map(file => ( { Player.set(getURL(file)); Player.load(); Player.play(); }} > {file.name} ))} )} ); }; export { Comment };