mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
refactor comment components
This commit is contained in:
parent
60da84aad9
commit
eea7095e65
42 changed files with 89 additions and 76 deletions
|
@ -1,36 +0,0 @@
|
||||||
import React, { forwardRef, KeyboardEventHandler, TextareaHTMLAttributes, useCallback } from 'react';
|
|
||||||
|
|
||||||
import { Textarea } from '~/components/input/Textarea';
|
|
||||||
import { useRandomPhrase } from '~/constants/phrases';
|
|
||||||
import { useCommentFormContext } from '~/hooks/comments/useCommentFormFormik';
|
|
||||||
|
|
||||||
interface IProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {
|
|
||||||
isLoading?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const LocalCommentFormTextarea = forwardRef<HTMLTextAreaElement, IProps>(({ ...rest }, ref) => {
|
|
||||||
const { values, handleChange, handleSubmit, isSubmitting } = useCommentFormContext();
|
|
||||||
|
|
||||||
const onKeyDown = useCallback<KeyboardEventHandler<HTMLTextAreaElement>>(
|
|
||||||
({ ctrlKey, key, metaKey }) => {
|
|
||||||
if ((ctrlKey || metaKey) && key === 'Enter') handleSubmit(undefined);
|
|
||||||
},
|
|
||||||
[handleSubmit]
|
|
||||||
);
|
|
||||||
|
|
||||||
const placeholder = useRandomPhrase('SIMPLE');
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Textarea
|
|
||||||
{...rest}
|
|
||||||
ref={ref}
|
|
||||||
value={values.text}
|
|
||||||
handler={handleChange('text')}
|
|
||||||
onKeyDown={onKeyDown}
|
|
||||||
disabled={isSubmitting}
|
|
||||||
placeholder={placeholder}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
export { LocalCommentFormTextarea };
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
import React, {
|
||||||
|
forwardRef,
|
||||||
|
KeyboardEventHandler,
|
||||||
|
TextareaHTMLAttributes,
|
||||||
|
useCallback,
|
||||||
|
} from 'react';
|
||||||
|
|
||||||
|
import { Textarea } from '~/components/input/Textarea';
|
||||||
|
import { useRandomPhrase } from '~/constants/phrases';
|
||||||
|
import { useCommentFormContext } from '~/hooks/comments/useCommentFormFormik';
|
||||||
|
|
||||||
|
interface IProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {
|
||||||
|
isLoading?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const CommentFormTextarea = forwardRef<HTMLTextAreaElement, IProps>(
|
||||||
|
({ ...rest }, ref) => {
|
||||||
|
const { values, handleChange, handleSubmit, isSubmitting } =
|
||||||
|
useCommentFormContext();
|
||||||
|
|
||||||
|
const onKeyDown = useCallback<KeyboardEventHandler<HTMLTextAreaElement>>(
|
||||||
|
({ ctrlKey, key, metaKey }) => {
|
||||||
|
if ((ctrlKey || metaKey) && key === 'Enter') handleSubmit(undefined);
|
||||||
|
},
|
||||||
|
[handleSubmit],
|
||||||
|
);
|
||||||
|
|
||||||
|
const placeholder = useRandomPhrase('SIMPLE');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Textarea
|
||||||
|
{...rest}
|
||||||
|
ref={ref}
|
||||||
|
value={values.text}
|
||||||
|
handler={handleChange('text')}
|
||||||
|
onKeyDown={onKeyDown}
|
||||||
|
disabled={isSubmitting}
|
||||||
|
placeholder={placeholder}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export { CommentFormTextarea };
|
|
@ -3,10 +3,6 @@ import { FC, useCallback, useState } from 'react';
|
||||||
import { FormikProvider } from 'formik';
|
import { FormikProvider } from 'formik';
|
||||||
import { observer } from 'mobx-react-lite';
|
import { observer } from 'mobx-react-lite';
|
||||||
|
|
||||||
import { CommentFormAttachButtons } from '~/components/comment/CommentFormAttachButtons';
|
|
||||||
import { CommentFormAttaches } from '~/components/comment/CommentFormAttaches';
|
|
||||||
import { CommentFormFormatButtons } from '~/components/comment/CommentFormFormatButtons';
|
|
||||||
import { LocalCommentFormTextarea } from '~/components/comment/LocalCommentFormTextarea';
|
|
||||||
import { Filler } from '~/components/containers/Filler';
|
import { Filler } from '~/components/containers/Filler';
|
||||||
import { Button } from '~/components/input/Button';
|
import { Button } from '~/components/input/Button';
|
||||||
import { ERROR_LITERAL } from '~/constants/errors';
|
import { ERROR_LITERAL } from '~/constants/errors';
|
||||||
|
@ -14,10 +10,12 @@ import { EMPTY_COMMENT } from '~/constants/node';
|
||||||
import { useCommentFormFormik } from '~/hooks/comments/useCommentFormFormik';
|
import { useCommentFormFormik } from '~/hooks/comments/useCommentFormFormik';
|
||||||
import { useInputPasteUpload } from '~/hooks/dom/useInputPasteUpload';
|
import { useInputPasteUpload } from '~/hooks/dom/useInputPasteUpload';
|
||||||
import { IComment } from '~/types';
|
import { IComment } from '~/types';
|
||||||
import {
|
import { useUploaderContext } from '~/utils/context/UploaderContextProvider';
|
||||||
useUploaderContext,
|
|
||||||
} from '~/utils/context/UploaderContextProvider';
|
|
||||||
|
|
||||||
|
import { CommentFormAttachButtons } from './components/CommentFormAttachButtons';
|
||||||
|
import { CommentFormAttaches } from './components/CommentFormAttaches';
|
||||||
|
import { CommentFormFormatButtons } from './components/CommentFormFormatButtons';
|
||||||
|
import { CommentFormTextarea } from './components/CommentFormTextarea';
|
||||||
import styles from './styles.module.scss';
|
import styles from './styles.module.scss';
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
|
@ -63,7 +61,7 @@ const CommentForm: FC<IProps> = observer(
|
||||||
<form onSubmit={formik.handleSubmit} className={styles.wrap}>
|
<form onSubmit={formik.handleSubmit} className={styles.wrap}>
|
||||||
<FormikProvider value={formik}>
|
<FormikProvider value={formik}>
|
||||||
<div className={styles.input}>
|
<div className={styles.input}>
|
||||||
<LocalCommentFormTextarea onPaste={onPaste} ref={setTextArea} />
|
<CommentFormTextarea onPaste={onPaste} ref={setTextArea} />
|
||||||
|
|
||||||
{!!error && (
|
{!!error && (
|
||||||
<div className={styles.error} onClick={clearError}>
|
<div className={styles.error} onClick={clearError}>
|
|
@ -1,8 +1,9 @@
|
||||||
import React, { useCallback, useState, VFC } from 'react';
|
import React, { useCallback, useState, VFC } from 'react';
|
||||||
|
|
||||||
import styles from '~/components/comment/CommentMenu/styles.module.scss';
|
|
||||||
import { MenuDots } from '~/components/common/MenuDots';
|
import { MenuDots } from '~/components/common/MenuDots';
|
||||||
|
|
||||||
|
import styles from './styles.module.scss';
|
||||||
|
|
||||||
interface MenuAction {
|
interface MenuAction {
|
||||||
title: string;
|
title: string;
|
||||||
action: () => void;
|
action: () => void;
|
||||||
|
@ -18,7 +19,12 @@ const CornerMenu: VFC<CornerMenuProps> = ({ actions }) => {
|
||||||
const onBlur = useCallback(() => setIsMenuOpened(false), [setIsMenuOpened]);
|
const onBlur = useCallback(() => setIsMenuOpened(false), [setIsMenuOpened]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.wrap} onFocus={onFocus} onBlur={onBlur} tabIndex={-1}>
|
<div
|
||||||
|
className={styles.wrap}
|
||||||
|
onFocus={onFocus}
|
||||||
|
onBlur={onBlur}
|
||||||
|
tabIndex={-1}
|
||||||
|
>
|
||||||
<MenuDots onClick={onFocus} />
|
<MenuDots onClick={onFocus} />
|
||||||
|
|
||||||
{is_menu_opened && (
|
{is_menu_opened && (
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
import { CommentEmbedBlock } from '~/components/comment/CommentEmbedBlock';
|
|
||||||
import { CommentTextBlock } from '~/components/comment/CommentTextBlock';
|
|
||||||
|
|
||||||
export const COMMENT_BLOCK_TYPES = {
|
export const COMMENT_BLOCK_TYPES = {
|
||||||
TEXT: 'TEXT',
|
TEXT: 'TEXT',
|
||||||
MARK: 'MARK',
|
MARK: 'MARK',
|
||||||
|
@ -31,10 +28,4 @@ export type ICommentBlockProps = {
|
||||||
block: ICommentBlock;
|
block: ICommentBlock;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const COMMENT_BLOCK_RENDERERS = {
|
|
||||||
[COMMENT_BLOCK_TYPES.TEXT]: CommentTextBlock,
|
|
||||||
[COMMENT_BLOCK_TYPES.MARK]: CommentTextBlock,
|
|
||||||
[COMMENT_BLOCK_TYPES.EMBED]: CommentEmbedBlock,
|
|
||||||
};
|
|
||||||
|
|
||||||
export const NEW_COMMENT_CLASSNAME = 'newComment';
|
export const NEW_COMMENT_CLASSNAME = 'newComment';
|
||||||
|
|
|
@ -3,8 +3,8 @@ import { FC } from 'react';
|
||||||
import { Group } from '~/components/containers/Group';
|
import { Group } from '~/components/containers/Group';
|
||||||
import { Footer } from '~/components/main/Footer';
|
import { Footer } from '~/components/main/Footer';
|
||||||
import { NodeNoComments } from '~/components/node/NodeNoComments';
|
import { NodeNoComments } from '~/components/node/NodeNoComments';
|
||||||
import { NodeCommentFormSSR } from '~/containers/node/NodeCommentForm/ssr';
|
import { NodeCommentFormSSR } from '~/containers/comments/NodeCommentForm/ssr';
|
||||||
import { NodeComments } from '~/containers/node/NodeComments';
|
import { NodeComments } from '~/containers/comments/NodeComments';
|
||||||
import { useCommentContext } from '~/utils/context/CommentContextProvider';
|
import { useCommentContext } from '~/utils/context/CommentContextProvider';
|
||||||
|
|
||||||
interface Props {}
|
interface Props {}
|
||||||
|
|
|
@ -2,11 +2,11 @@ import React, { FC } from 'react';
|
||||||
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
|
||||||
import { CommentAvatar } from '~/components/comment/CommentAvatar';
|
|
||||||
import { IUser } from '~/types/auth';
|
import { IUser } from '~/types/auth';
|
||||||
import { path } from '~/utils/ramda';
|
import { path } from '~/utils/ramda';
|
||||||
import { DivProps } from '~/utils/types';
|
import { DivProps } from '~/utils/types';
|
||||||
|
|
||||||
|
import { CommentAvatar } from './components/CommentAvatar';
|
||||||
import styles from './styles.module.scss';
|
import styles from './styles.module.scss';
|
||||||
|
|
||||||
type IProps = DivProps & {
|
type IProps = DivProps & {
|
|
@ -2,8 +2,7 @@ import { FC, useCallback } from 'react';
|
||||||
|
|
||||||
import { observer } from 'mobx-react-lite';
|
import { observer } from 'mobx-react-lite';
|
||||||
|
|
||||||
import { CommentForm } from '~/components/comment/CommentForm';
|
import { CommentForm } from '~/components/common/CommentForm';
|
||||||
import { CommentWrapper } from '~/components/containers/CommentWrapper';
|
|
||||||
import { UploadDropzone } from '~/components/upload/UploadDropzone';
|
import { UploadDropzone } from '~/components/upload/UploadDropzone';
|
||||||
import { Dialog } from '~/constants/modal';
|
import { Dialog } from '~/constants/modal';
|
||||||
import { UploadSubject, UploadTarget } from '~/constants/uploads';
|
import { UploadSubject, UploadTarget } from '~/constants/uploads';
|
||||||
|
@ -13,6 +12,8 @@ import { useShowModal } from '~/hooks/modal/useShowModal';
|
||||||
import { IComment } from '~/types';
|
import { IComment } from '~/types';
|
||||||
import { UploaderContextProvider } from '~/utils/context/UploaderContextProvider';
|
import { UploaderContextProvider } from '~/utils/context/UploaderContextProvider';
|
||||||
|
|
||||||
|
import { CommentWrapper } from '../CommentWrapper';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
saveComment: (comment: IComment) => Promise<IComment | undefined>;
|
saveComment: (comment: IComment) => Promise<IComment | undefined>;
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@ import { FC } from 'react';
|
||||||
|
|
||||||
import { observer } from 'mobx-react-lite';
|
import { observer } from 'mobx-react-lite';
|
||||||
|
|
||||||
import { CommentForm } from '~/components/comment/CommentForm';
|
import { CommentForm } from '~/components/common/CommentForm';
|
||||||
import { UploadDropzone } from '~/components/upload/UploadDropzone';
|
import { UploadDropzone } from '~/components/upload/UploadDropzone';
|
||||||
import { UploadSubject, UploadTarget } from '~/constants/uploads';
|
import { UploadSubject, UploadTarget } from '~/constants/uploads';
|
||||||
import { useUploader } from '~/hooks/data/useUploader';
|
import { useUploader } from '~/hooks/data/useUploader';
|
|
@ -0,0 +1,10 @@
|
||||||
|
import { COMMENT_BLOCK_TYPES } from '~/constants/comment';
|
||||||
|
|
||||||
|
import { CommentEmbedBlock } from '../components/CommentEmbedBlock';
|
||||||
|
import { CommentTextBlock } from '../components/CommentTextBlock';
|
||||||
|
|
||||||
|
export const COMMENT_BLOCK_RENDERERS = {
|
||||||
|
[COMMENT_BLOCK_TYPES.TEXT]: CommentTextBlock,
|
||||||
|
[COMMENT_BLOCK_TYPES.MARK]: CommentTextBlock,
|
||||||
|
[COMMENT_BLOCK_TYPES.EMBED]: CommentEmbedBlock,
|
||||||
|
};
|
|
@ -12,17 +12,16 @@ import classnames from 'classnames';
|
||||||
|
|
||||||
import { Group } from '~/components/containers/Group';
|
import { Group } from '~/components/containers/Group';
|
||||||
import { AudioPlayer } from '~/components/media/AudioPlayer';
|
import { AudioPlayer } from '~/components/media/AudioPlayer';
|
||||||
import { COMMENT_BLOCK_RENDERERS } from '~/constants/comment';
|
|
||||||
import { UploadType } from '~/constants/uploads';
|
import { UploadType } from '~/constants/uploads';
|
||||||
import { IComment, IFile } from '~/types';
|
import { IComment, IFile } from '~/types';
|
||||||
import { formatCommentText, getPrettyDate } from '~/utils/dom';
|
import { formatCommentText, getPrettyDate } from '~/utils/dom';
|
||||||
import { append, assocPath, path, reduce } from '~/utils/ramda';
|
import { append, assocPath, path, reduce } from '~/utils/ramda';
|
||||||
|
|
||||||
import { CommentEditingForm } from '../CommentEditingForm';
|
import { CommentEditingForm } from './components/CommentEditingForm';
|
||||||
import { CommentImageGrid } from '../CommentImageGrid';
|
import { CommentImageGrid } from './components/CommentImageGrid';
|
||||||
import { CommentLike } from '../CommentLike';
|
import { CommentLike } from './components/CommentLike';
|
||||||
import { CommentMenu } from '../CommentMenu';
|
import { CommentMenu } from './components/CommentMenu';
|
||||||
|
import { COMMENT_BLOCK_RENDERERS } from './constants';
|
||||||
import styles from './styles.module.scss';
|
import styles from './styles.module.scss';
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
|
@ -3,14 +3,14 @@ import React, { FC, HTMLAttributes, memo } from 'react';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { parseISO } from 'date-fns';
|
import { parseISO } from 'date-fns';
|
||||||
|
|
||||||
import { CommentContent } from '~/components/comment/CommentContent';
|
|
||||||
import { CommentDistance } from '~/components/comment/CommentDistance';
|
|
||||||
import { CommentWrapper } from '~/components/containers/CommentWrapper';
|
|
||||||
import { NEW_COMMENT_CLASSNAME } from '~/constants/comment';
|
import { NEW_COMMENT_CLASSNAME } from '~/constants/comment';
|
||||||
|
import { CommentWrapper } from '~/containers/comments/CommentWrapper';
|
||||||
import { IComment, ICommentGroup, IFile } from '~/types';
|
import { IComment, ICommentGroup, IFile } from '~/types';
|
||||||
|
|
||||||
import { CommendDeleted } from '../../node/CommendDeleted';
|
import { CommendDeleted } from '../../../../../components/node/CommendDeleted';
|
||||||
|
|
||||||
|
import { CommentContent } from './components/CommentContent';
|
||||||
|
import { CommentDistance } from './components/CommentDistance';
|
||||||
import styles from './styles.module.scss';
|
import styles from './styles.module.scss';
|
||||||
|
|
||||||
type Props = HTMLAttributes<HTMLDivElement> & {
|
type Props = HTMLAttributes<HTMLDivElement> & {
|
|
@ -2,9 +2,9 @@ import React, { FC, useMemo } from 'react';
|
||||||
|
|
||||||
import { observer } from 'mobx-react-lite';
|
import { observer } from 'mobx-react-lite';
|
||||||
|
|
||||||
import { Comment } from '~/components/comment/Comment';
|
|
||||||
import { LoadMoreButton } from '~/components/input/LoadMoreButton';
|
import { LoadMoreButton } from '~/components/input/LoadMoreButton';
|
||||||
import { ANNOUNCE_USER_ID, BORIS_NODE_ID } from '~/constants/boris/constants';
|
import { ANNOUNCE_USER_ID, BORIS_NODE_ID } from '~/constants/boris/constants';
|
||||||
|
import { Comment } from '~/containers/comments/NodeComments/components/Comment';
|
||||||
import { useGrouppedComments } from '~/hooks/node/useGrouppedComments';
|
import { useGrouppedComments } from '~/hooks/node/useGrouppedComments';
|
||||||
import { ICommentGroup } from '~/types';
|
import { ICommentGroup } from '~/types';
|
||||||
import { useCommentContext } from '~/utils/context/CommentContextProvider';
|
import { useCommentContext } from '~/utils/context/CommentContextProvider';
|
|
@ -5,7 +5,7 @@ import isBefore from 'date-fns/isBefore';
|
||||||
import { observer } from 'mobx-react-lite';
|
import { observer } from 'mobx-react-lite';
|
||||||
|
|
||||||
import { Anchor } from '~/components/common/Anchor';
|
import { Anchor } from '~/components/common/Anchor';
|
||||||
import { Authorized } from '~/components/containers/Authorized';
|
import { Authorized } from '~/components/common/Authorized';
|
||||||
import { Filler } from '~/components/containers/Filler';
|
import { Filler } from '~/components/containers/Filler';
|
||||||
import { Button } from '~/components/input/Button';
|
import { Button } from '~/components/input/Button';
|
||||||
import { Logo } from '~/components/main/Logo';
|
import { Logo } from '~/components/main/Logo';
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import React, { FC } from 'react';
|
import React, { FC } from 'react';
|
||||||
|
|
||||||
import { Authorized } from '~/components/containers/Authorized';
|
import { Authorized } from '~/components/common/Authorized';
|
||||||
|
|
||||||
import { SubmitBarSSR } from './components/SubmitBar/ssr';
|
import { SubmitBarSSR } from './components/SubmitBar/ssr';
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,9 @@ import { NodeDeletedBadge } from '~/components/node/NodeDeletedBadge';
|
||||||
import { NodeNoComments } from '~/components/node/NodeNoComments';
|
import { NodeNoComments } from '~/components/node/NodeNoComments';
|
||||||
import { NodeRelatedBlock } from '~/components/node/NodeRelatedBlock';
|
import { NodeRelatedBlock } from '~/components/node/NodeRelatedBlock';
|
||||||
import { NodeTagsBlock } from '~/components/node/NodeTagsBlock';
|
import { NodeTagsBlock } from '~/components/node/NodeTagsBlock';
|
||||||
|
import { NodeCommentFormSSR } from '~/containers/comments/NodeCommentForm/ssr';
|
||||||
|
import { NodeComments } from '~/containers/comments/NodeComments';
|
||||||
import { NodeBacklinks } from '~/containers/node/NodeBacklinks';
|
import { NodeBacklinks } from '~/containers/node/NodeBacklinks';
|
||||||
import { NodeCommentFormSSR } from '~/containers/node/NodeCommentForm/ssr';
|
|
||||||
import { NodeComments } from '~/containers/node/NodeComments';
|
|
||||||
import { useNodeBlocks } from '~/hooks/node/useNodeBlocks';
|
import { useNodeBlocks } from '~/hooks/node/useNodeBlocks';
|
||||||
import { useCommentContext } from '~/utils/context/CommentContextProvider';
|
import { useCommentContext } from '~/utils/context/CommentContextProvider';
|
||||||
import { useNodeContext } from '~/utils/context/NodeContextProvider';
|
import { useNodeContext } from '~/utils/context/NodeContextProvider';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue