1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

output for mp3 files

This commit is contained in:
Fedor Katurov 2019-10-10 13:50:21 +07:00
parent 00a28377f1
commit 63b30b2921
3 changed files with 67 additions and 27 deletions

View file

@ -1,10 +1,15 @@
import React, { FC, HTMLAttributes } from 'react'; import React, { FC, HTMLAttributes, useMemo } from 'react';
import { CommentWrapper } from '~/components/containers/CommentWrapper'; import { CommentWrapper } from '~/components/containers/CommentWrapper';
import { IComment } from '~/redux/types'; import { IComment, IFile } from '~/redux/types';
import * as styles from './styles.scss'; import * as styles from './styles.scss';
import { formatCommentText, getURL } from '~/utils/dom'; import { formatCommentText, getURL } from '~/utils/dom';
import { Group } from '~/components/containers/Group'; import { Group } from '~/components/containers/Group';
import { ImageUpload } from '~/components/upload/ImageUpload'; 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<HTMLDivElement> & { type IProps = HTMLAttributes<HTMLDivElement> & {
is_empty?: boolean; is_empty?: boolean;
@ -13,7 +18,18 @@ type IProps = HTMLAttributes<HTMLDivElement> & {
comment?: IComment; comment?: IComment;
}; };
const Comment: FC<IProps> = ({ comment, is_empty, is_loading, className, photo, ...props }) => ( const Comment: FC<IProps> = ({ comment, is_empty, is_loading, className, photo, ...props }) => {
const groupped = useMemo<Record<keyof typeof UPLOAD_TYPES, IFile[]>>(
() =>
reduce(
(group, file) => assocPath([file.type], append(file, group[file.type]), group),
{},
comment.files
),
[comment]
);
return (
<CommentWrapper is_empty={is_empty} is_loading={is_loading} photo={photo} {...props}> <CommentWrapper is_empty={is_empty} is_loading={is_loading} photo={photo} {...props}>
{comment.text && ( {comment.text && (
<Group <Group
@ -24,16 +40,25 @@ const Comment: FC<IProps> = ({ comment, is_empty, is_loading, className, photo,
/> />
)} )}
{comment.files && comment.files.length > 0 && ( {groupped.image && (
<div className={styles.images}> <div className={styles.images}>
{comment.files.map(file => ( {groupped.image.map(file => (
<div key={file.id}> <div key={file.id}>
<img src={getURL(file.url)} alt={file.name} /> <img src={getURL(file.url)} alt={file.name} />
</div> </div>
))} ))}
</div> </div>
)} )}
{groupped.audio && (
<div className={styles.audios}>
{groupped.audio.map(file => (
<div key={file.id}>{file.name}</div>
))}
</div>
)}
</CommentWrapper> </CommentWrapper>
); );
};
export { Comment }; export { Comment };

View file

@ -1,3 +1,5 @@
@import 'flexbin/flexbin.scss';
.text { .text {
padding: $gap / 2; padding: $gap / 2;
font-weight: 300; font-weight: 300;
@ -8,14 +10,26 @@
} }
} }
@import 'flexbin/flexbin.scss';
.images { .images {
padding: 10px; padding: $gap;
@include flexbin(150px, 10px); @include flexbin(240px, 10px);
img { img {
border-radius: $radius; 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;
}
}

View file

@ -14,6 +14,7 @@
background: transparentize(black, 0.8); background: transparentize(black, 0.8);
padding: $gap / 2; padding: $gap / 2;
border-radius: 0 0 $radius $radius; border-radius: 0 0 $radius $radius;
flex-wrap: wrap;
svg { svg {
fill: transparentize(white, 0.9); fill: transparentize(white, 0.9);