mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
group comments (bad way)
This commit is contained in:
parent
6bf14e6d5c
commit
39b0a2d568
6 changed files with 35 additions and 16 deletions
|
@ -8,6 +8,7 @@ type IProps = HTMLAttributes<HTMLDivElement> & {
|
||||||
photo?: string;
|
photo?: string;
|
||||||
is_empty?: boolean;
|
is_empty?: boolean;
|
||||||
is_loading?: boolean;
|
is_loading?: boolean;
|
||||||
|
is_same?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const CommentWrapper: FC<IProps> = ({
|
const CommentWrapper: FC<IProps> = ({
|
||||||
|
@ -16,15 +17,16 @@ const CommentWrapper: FC<IProps> = ({
|
||||||
is_empty,
|
is_empty,
|
||||||
is_loading,
|
is_loading,
|
||||||
className,
|
className,
|
||||||
|
is_same,
|
||||||
...props
|
...props
|
||||||
}) => (
|
}) => (
|
||||||
<Card
|
<Card
|
||||||
className={classNames(styles.wrap, className, { is_empty, is_loading })}
|
className={classNames(styles.wrap, className, { is_empty, is_loading, is_same })}
|
||||||
seamless
|
seamless
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<div className={styles.thumb}>
|
<div className={styles.thumb}>
|
||||||
{photo && (
|
{!is_same && photo && (
|
||||||
<div className={styles.thumb_image} style={{ backgroundImage: `url("${photo}")` }} />
|
<div className={styles.thumb_image} style={{ backgroundImage: `url("${photo}")` }} />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -2,11 +2,16 @@
|
||||||
background: $comment_bg;
|
background: $comment_bg;
|
||||||
min-height: $comment_height;
|
min-height: $comment_height;
|
||||||
display: flex;
|
display: flex;
|
||||||
box-shadow: $comment_shadow;
|
// box-shadow: $comment_shadow;
|
||||||
|
|
||||||
&:global(.is_empty) {
|
&:global(.is_empty) {
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&:global(.is_same) {
|
||||||
|
margin: 0 !important;
|
||||||
|
border-radius: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.text {
|
.text {
|
||||||
|
|
|
@ -9,15 +9,16 @@ import append from 'ramda/es/append';
|
||||||
import reduce from 'ramda/es/reduce';
|
import reduce from 'ramda/es/reduce';
|
||||||
import { UPLOAD_TYPES } from '~/redux/uploads/constants';
|
import { UPLOAD_TYPES } from '~/redux/uploads/constants';
|
||||||
import { Player } from '~/utils/player';
|
import { Player } from '~/utils/player';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
|
||||||
type IProps = HTMLAttributes<HTMLDivElement> & {
|
type IProps = HTMLAttributes<HTMLDivElement> & {
|
||||||
is_empty?: boolean;
|
is_empty?: boolean;
|
||||||
is_loading?: boolean;
|
is_loading?: boolean;
|
||||||
photo?: string;
|
|
||||||
comment?: IComment;
|
comment?: IComment;
|
||||||
|
is_same?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Comment: FC<IProps> = ({ comment, is_empty, is_loading, className, photo, ...props }) => {
|
const Comment: FC<IProps> = ({ comment, is_empty, is_same, is_loading, className, ...props }) => {
|
||||||
const groupped = useMemo<Record<keyof typeof UPLOAD_TYPES, IFile[]>>(
|
const groupped = useMemo<Record<keyof typeof UPLOAD_TYPES, IFile[]>>(
|
||||||
() =>
|
() =>
|
||||||
reduce(
|
reduce(
|
||||||
|
@ -30,16 +31,21 @@ const Comment: FC<IProps> = ({ comment, is_empty, is_loading, className, photo,
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CommentWrapper
|
<CommentWrapper
|
||||||
|
className={className}
|
||||||
is_empty={is_empty}
|
is_empty={is_empty}
|
||||||
is_loading={is_loading}
|
is_loading={is_loading}
|
||||||
photo={getURL(comment.user.photo)}
|
photo={getURL(comment.user.photo)}
|
||||||
|
is_same={is_same}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
{comment.text && (
|
{comment.text && (
|
||||||
<Group
|
<Group
|
||||||
className={styles.text}
|
className={styles.text}
|
||||||
dangerouslySetInnerHTML={{
|
dangerouslySetInnerHTML={{
|
||||||
__html: formatCommentText(comment.user && comment.user.username, comment.text),
|
__html: formatCommentText(
|
||||||
|
!is_same && comment.user && comment.user.username,
|
||||||
|
comment.text
|
||||||
|
),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -1,24 +1,24 @@
|
||||||
import React, { FC } from 'react';
|
import React, { FC } from 'react';
|
||||||
import range from 'ramda/es/range';
|
|
||||||
import { Comment } from '../Comment';
|
import { Comment } from '../Comment';
|
||||||
import { INode } from '~/redux/types';
|
|
||||||
import { CommentForm } from '../CommentForm';
|
|
||||||
import { Group } from '~/components/containers/Group';
|
|
||||||
import * as styles from './styles.scss';
|
|
||||||
import { Filler } from '~/components/containers/Filler';
|
import { Filler } from '~/components/containers/Filler';
|
||||||
|
|
||||||
|
import * as styles from './styles.scss';
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
comments?: any;
|
comments?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isSameComment = (comments, index) =>
|
||||||
|
comments[index - 1] && comments[index - 1].user.id === comments[index].user.id;
|
||||||
|
|
||||||
const NodeComments: FC<IProps> = ({ comments }) => (
|
const NodeComments: FC<IProps> = ({ comments }) => (
|
||||||
<Group className={styles.wrap}>
|
<div className={styles.wrap}>
|
||||||
{comments.map(comment => (
|
{comments.map((comment, index) => (
|
||||||
<Comment key={comment.id} comment={comment} />
|
<Comment key={comment.id} comment={comment} is_same={isSameComment(comments, index)} />
|
||||||
))}
|
))}
|
||||||
|
|
||||||
<Filler />
|
<Filler />
|
||||||
</Group>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
export { NodeComments };
|
export { NodeComments };
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
.wrap {
|
.wrap {
|
||||||
|
& > div {
|
||||||
|
margin: $gap 0 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
// display: flex;
|
// display: flex;
|
||||||
// flex-direction: column !important;
|
// flex-direction: column !important;
|
||||||
|
|
||||||
|
|
|
@ -71,5 +71,7 @@ export const formatCommentText = (author, text: string) =>
|
||||||
.replace(/</g, '<')
|
.replace(/</g, '<')
|
||||||
.replace(/>/g, '>')
|
.replace(/>/g, '>')
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.map((el, index) => (index === 0 ? `<p><b>${author}</b>: ${el}</p>` : `<p>${el}</p>`))
|
.map((el, index) =>
|
||||||
|
index === 0 ? `${author ? `<p><b>${author}</b>: ` : ''}${el}</p>` : `<p>${el}</p>`
|
||||||
|
)
|
||||||
.join('');
|
.join('');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue