From 63b30b292154b8fc8fc2bc3752082b1ab913d857 Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Thu, 10 Oct 2019 13:50:21 +0700 Subject: [PATCH] output for mp3 files --- src/components/node/Comment/index.tsx | 71 ++++++++++++++------- src/components/node/Comment/styles.scss | 22 +++++-- src/components/node/CommentForm/styles.scss | 1 + 3 files changed, 67 insertions(+), 27 deletions(-) diff --git a/src/components/node/Comment/index.tsx b/src/components/node/Comment/index.tsx index c56f431d..bc730eba 100644 --- a/src/components/node/Comment/index.tsx +++ b/src/components/node/Comment/index.tsx @@ -1,10 +1,15 @@ -import React, { FC, HTMLAttributes } from 'react'; +import React, { FC, HTMLAttributes, useMemo } from 'react'; import { CommentWrapper } from '~/components/containers/CommentWrapper'; -import { IComment } from '~/redux/types'; +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 { ImageUpload } from '~/components/upload/ImageUpload'; +import { getFileType } from '~/utils/uploader'; +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'; type IProps = HTMLAttributes & { is_empty?: boolean; @@ -13,27 +18,47 @@ type IProps = HTMLAttributes & { comment?: IComment; }; -const Comment: FC = ({ comment, is_empty, is_loading, className, photo, ...props }) => ( - - {comment.text && ( - - )} +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] + ); - {comment.files && comment.files.length > 0 && ( -
- {comment.files.map(file => ( -
- {file.name} -
- ))} -
- )} -
-); + return ( + + {comment.text && ( + + )} + + {groupped.image && ( +
+ {groupped.image.map(file => ( +
+ {file.name} +
+ ))} +
+ )} + + {groupped.audio && ( +
+ {groupped.audio.map(file => ( +
{file.name}
+ ))} +
+ )} +
+ ); +}; export { Comment }; diff --git a/src/components/node/Comment/styles.scss b/src/components/node/Comment/styles.scss index bf271470..c1fa26aa 100644 --- a/src/components/node/Comment/styles.scss +++ b/src/components/node/Comment/styles.scss @@ -1,3 +1,5 @@ +@import 'flexbin/flexbin.scss'; + .text { padding: $gap / 2; font-weight: 300; @@ -8,14 +10,26 @@ } } -@import 'flexbin/flexbin.scss'; - .images { - padding: 10px; + padding: $gap; - @include flexbin(150px, 10px); + @include flexbin(240px, 10px); img { border-radius: $radius; } } + +.audios { + padding: $gap; + + & > div { + height: 64px; + border-radius: $radius; + background: lighten($color: $comment_bg, $amount: 5%); + display: flex; + justify-content: center; + align-items: center; + text-align: center; + } +} diff --git a/src/components/node/CommentForm/styles.scss b/src/components/node/CommentForm/styles.scss index de992cba..277960af 100644 --- a/src/components/node/CommentForm/styles.scss +++ b/src/components/node/CommentForm/styles.scss @@ -14,6 +14,7 @@ background: transparentize(black, 0.8); padding: $gap / 2; border-radius: 0 0 $radius $radius; + flex-wrap: wrap; svg { fill: transparentize(white, 0.9);