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 } 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'; type IProps = HTMLAttributes & { is_empty?: boolean; is_loading?: boolean; photo?: string; comment?: IComment; }; const Comment: FC = ({ comment, is_empty, is_loading, className, photo, ...props }) => { const groupped = useMemo>( () => reduce( (group, file) => assocPath([file.type], append(file, group[file.type]), group), {}, comment.files ), [comment] ); return ( {comment.text && ( )} {groupped.image && ( {groupped.image.map(file => ( ))} )} {groupped.audio && ( {groupped.audio.map(file => ( { Player.set(getURL(file.url)); Player.load(); Player.play(); }} > {file.name} ))} )} ); }; export { Comment };