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

removed almost all node sagas

This commit is contained in:
Fedor Katurov 2022-01-02 20:44:41 +07:00
parent f76a5a4798
commit 168ba8cc04
30 changed files with 268 additions and 448 deletions

View file

@ -16,24 +16,28 @@ const BorisComments: FC<IProps> = () => {
const {
isLoading,
comments,
onSaveComment,
onLoadMoreComments,
onDeleteComment,
onShowImageModal,
count,
hasMore,
} = useCommentContext();
const { node } = useNodeContext();
return (
<>
<Group className={styles.grid}>
{user.is_user && <NodeCommentForm isBefore nodeId={node.id} />}
{user.is_user && (
<NodeCommentForm user={user} nodeId={node.id} saveComment={onSaveComment} />
)}
{isLoading ? (
<NodeNoComments is_loading count={7} />
) : (
<CommentContextProvider
onSaveComment={onSaveComment}
comments={comments}
count={count}
hasMore={hasMore}
onDeleteComment={onDeleteComment}
onLoadMoreComments={onLoadMoreComments}
onShowImageModal={onShowImageModal}

View file

@ -4,7 +4,7 @@ import { useHistory, useRouteMatch } from 'react-router';
import { ModalWrapper } from '~/components/dialogs/ModalWrapper';
import { LoaderCircle } from '~/components/input/LoaderCircle';
import styles from './styles.module.scss';
import { useGetNode } from '~/hooks/node/useGetNode';
import { useLoadNode } from '~/hooks/node/useLoadNode';
import { useUpdateNode } from '~/hooks/node/useUpdateNode';
import { INode } from '~/redux/types';
@ -24,7 +24,7 @@ const EditorEditDialog: FC = () => {
history.replace(backUrl);
}, [backUrl, history]);
const { node, isLoading } = useGetNode(parseInt(id, 10));
const { node, isLoading } = useLoadNode(parseInt(id, 10));
const updateNode = useUpdateNode(parseInt(id, 10));
const onSubmit = useCallback(

View file

@ -21,9 +21,9 @@ interface IProps {
}
const NodeBottomBlock: FC<IProps> = ({ commentsOrder }) => {
const { is_user: isUser } = useUserContext();
const user = useUserContext();
const { node, isLoading } = useNodeContext();
const { comments, isLoading: isLoadingComments } = useCommentContext();
const { comments, isLoading: isLoadingComments, onSaveComment } = useCommentContext();
const { related, isLoading: isLoadingRelated } = useNodeRelatedContext();
const { inline } = useNodeBlocks(node, isLoading);
@ -44,7 +44,9 @@ const NodeBottomBlock: FC<IProps> = ({ commentsOrder }) => {
<NodeComments order={commentsOrder} />
)}
{isUser && !isLoading && <NodeCommentForm nodeId={node.id} />}
{user.is_user && !isLoading && (
<NodeCommentForm nodeId={node.id} saveComment={onSaveComment} user={user} />
)}
</Group>
<div className={styles.panel}>

View file

@ -21,27 +21,24 @@ const NodeComments: FC<IProps> = memo(({ order }) => {
const {
comments,
count,
hasMore,
lastSeenCurrent,
onLoadMoreComments,
onDeleteComment,
onShowImageModal,
onSaveComment,
} = useCommentContext();
const left = useMemo(() => Math.max(0, count - comments.length), [comments, count]);
const groupped: ICommentGroup[] = useGrouppedComments(comments, order, lastSeenCurrent);
const more = useMemo(
() =>
left > 0 && (
hasMore && (
<div className={styles.more} onClick={onLoadMoreComments}>
Показать ещё{' '}
{plural(Math.min(left, COMMENTS_DISPLAY), 'комментарий', 'комментария', 'комментариев')}
{left > COMMENTS_DISPLAY ? ` из ${left} оставшихся` : ''}
Показать ещё комментарии
</div>
),
[left, onLoadMoreComments]
[hasMore, onLoadMoreComments]
);
if (!node?.id) {
@ -61,6 +58,7 @@ const NodeComments: FC<IProps> = memo(({ order }) => {
onDelete={onDeleteComment}
onShowImageModal={onShowImageModal}
isSame={group.user.id === user.id}
saveComment={onSaveComment}
/>
))}

View file

@ -41,7 +41,7 @@ const ProfileLayoutUnconnected: FC<IProps> = ({ history, nodeSetCoverImage }) =>
<Grid className={styles.content}>
<div className={styles.comments}>
<CommentForm nodeId={0} />
<CommentForm nodeId={0} saveComment={async () => console.log()} />
<NodeNoComments is_loading={false} />
</div>
</Grid>