mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
output for mp3 files
This commit is contained in:
parent
00a28377f1
commit
63b30b2921
3 changed files with 67 additions and 27 deletions
|
@ -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,27 +18,47 @@ 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 }) => {
|
||||||
<CommentWrapper is_empty={is_empty} is_loading={is_loading} photo={photo} {...props}>
|
const groupped = useMemo<Record<keyof typeof UPLOAD_TYPES, IFile[]>>(
|
||||||
{comment.text && (
|
() =>
|
||||||
<Group
|
reduce(
|
||||||
className={styles.text}
|
(group, file) => assocPath([file.type], append(file, group[file.type]), group),
|
||||||
dangerouslySetInnerHTML={{
|
{},
|
||||||
__html: formatCommentText(comment.user && comment.user.username, comment.text),
|
comment.files
|
||||||
}}
|
),
|
||||||
/>
|
[comment]
|
||||||
)}
|
);
|
||||||
|
|
||||||
{comment.files && comment.files.length > 0 && (
|
return (
|
||||||
<div className={styles.images}>
|
<CommentWrapper is_empty={is_empty} is_loading={is_loading} photo={photo} {...props}>
|
||||||
{comment.files.map(file => (
|
{comment.text && (
|
||||||
<div key={file.id}>
|
<Group
|
||||||
<img src={getURL(file.url)} alt={file.name} />
|
className={styles.text}
|
||||||
</div>
|
dangerouslySetInnerHTML={{
|
||||||
))}
|
__html: formatCommentText(comment.user && comment.user.username, comment.text),
|
||||||
</div>
|
}}
|
||||||
)}
|
/>
|
||||||
</CommentWrapper>
|
)}
|
||||||
);
|
|
||||||
|
{groupped.image && (
|
||||||
|
<div className={styles.images}>
|
||||||
|
{groupped.image.map(file => (
|
||||||
|
<div key={file.id}>
|
||||||
|
<img src={getURL(file.url)} alt={file.name} />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{groupped.audio && (
|
||||||
|
<div className={styles.audios}>
|
||||||
|
{groupped.audio.map(file => (
|
||||||
|
<div key={file.id}>{file.name}</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</CommentWrapper>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export { Comment };
|
export { Comment };
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue