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

optimized node layout rerenders

This commit is contained in:
Fedor Katurov 2019-10-23 10:18:41 +07:00
parent 16af90fd50
commit 948817e8fc
7 changed files with 2954 additions and 2933 deletions

5624
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -104,6 +104,7 @@
"sass-loader": "^7.3.1", "sass-loader": "^7.3.1",
"sass-resources-loader": "^2.0.0", "sass-resources-loader": "^2.0.0",
"scrypt": "^6.0.3", "scrypt": "^6.0.3",
"sticky-sidebar": "^3.3.1",
"throttle-debounce": "^2.1.0", "throttle-debounce": "^2.1.0",
"tslint": "^5.20.0", "tslint": "^5.20.0",
"tslint-config-airbnb": "^5.11.2", "tslint-config-airbnb": "^5.11.2",

View file

@ -1,5 +1,5 @@
import classnames from 'classnames'; import classnames from 'classnames';
import React, { ButtonHTMLAttributes, DetailedHTMLProps, FC, createElement } from 'react'; import React, { ButtonHTMLAttributes, DetailedHTMLProps, FC, createElement, memo } from 'react';
import * as styles from './styles.scss'; import * as styles from './styles.scss';
import { Icon } from '~/components/input/Icon'; import { Icon } from '~/components/input/Icon';
import { IIcon } from '~/redux/types'; import { IIcon } from '~/redux/types';
@ -22,7 +22,8 @@ type IButtonProps = DetailedHTMLProps<
iconOnly?: boolean; iconOnly?: boolean;
}; };
const Button: FC<IButtonProps> = ({ const Button: FC<IButtonProps> = memo(
({
className = '', className = '',
size = 'normal', size = 'normal',
iconLeft, iconLeft,
@ -62,6 +63,7 @@ const Button: FC<IButtonProps> = ({
title ? <span>{title}</span> : children || null, title ? <span>{title}</span> : children || null,
iconRight && <Icon icon={iconRight} size={20} key={2} />, iconRight && <Icon icon={iconRight} size={20} key={2} />,
] ]
)
); );
export { Button }; export { Button };

View file

@ -1,4 +1,4 @@
import React, { FC, useMemo } from 'react'; import React, { FC, useMemo, memo } from 'react';
import { Comment } from '../Comment'; import { Comment } from '../Comment';
import { Filler } from '~/components/containers/Filler'; import { Filler } from '~/components/containers/Filler';
@ -10,7 +10,7 @@ interface IProps {
comments?: IComment[]; comments?: IComment[];
} }
const NodeComments: FC<IProps> = ({ comments }) => { const NodeComments: FC<IProps> = memo(({ comments }) => {
const groupped: ICommentGroup[] = useMemo(() => comments.reduce(groupCommentsByUser, []), [ const groupped: ICommentGroup[] = useMemo(() => comments.reduce(groupCommentsByUser, []), [
comments, comments,
]); ]);
@ -24,6 +24,6 @@ const NodeComments: FC<IProps> = ({ comments }) => {
<Filler /> <Filler />
</div> </div>
); );
}; });
export { NodeComments }; export { NodeComments };

View file

@ -1,4 +1,4 @@
import React, { FC, useCallback, useEffect, useRef, useState } from 'react'; import React, { FC, useCallback, useEffect, useRef, useState, memo } from 'react';
import * as styles from './styles.scss'; import * as styles from './styles.scss';
import { INode } from '~/redux/types'; import { INode } from '~/redux/types';
import { createPortal } from 'react-dom'; import { createPortal } from 'react-dom';
@ -14,7 +14,7 @@ interface IProps {
onLike: () => void; onLike: () => void;
} }
const NodePanel: FC<IProps> = ({ node, layout, can_edit, can_like, onEdit, onLike }) => { const NodePanel: FC<IProps> = memo(({ node, layout, can_edit, can_like, onEdit, onLike }) => {
const [stack, setStack] = useState(false); const [stack, setStack] = useState(false);
const ref = useRef(null); const ref = useRef(null);
@ -64,6 +64,6 @@ const NodePanel: FC<IProps> = ({ node, layout, can_edit, can_like, onEdit, onLik
)} )}
</div> </div>
); );
}; });
export { NodePanel }; export { NodePanel };

View file

@ -1,4 +1,4 @@
import React, { FC } from 'react'; import React, { FC, memo } from 'react';
import { Tags } from '../Tags'; import { Tags } from '../Tags';
import { ITag } from '~/redux/types'; import { ITag } from '~/redux/types';
@ -8,8 +8,8 @@ interface IProps {
onChange?: (tags: string[]) => void; onChange?: (tags: string[]) => void;
} }
const NodeTags: FC<IProps> = ({ is_editable, tags, onChange }) => ( const NodeTags: FC<IProps> = memo(({ is_editable, tags, onChange }) => (
<Tags tags={tags} is_editable={is_editable} onTagsChange={onChange} /> <Tags tags={tags} is_editable={is_editable} onTagsChange={onChange} />
); ));
export { NodeTags }; export { NodeTags };

View file

@ -1,4 +1,4 @@
import React, { FC, createElement, useEffect, useCallback, useState, useMemo } from 'react'; import React, { FC, createElement, useEffect, useCallback, useState, useMemo, memo } from 'react';
import { RouteComponentProps } from 'react-router'; import { RouteComponentProps } from 'react-router';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { canEditNode, canLikeNode } from '~/utils/node'; import { canEditNode, canLikeNode } from '~/utils/node';
@ -35,7 +35,8 @@ type IProps = ReturnType<typeof mapStateToProps> &
typeof mapDispatchToProps & typeof mapDispatchToProps &
RouteComponentProps<{ id: string }> & {}; RouteComponentProps<{ id: string }> & {};
const NodeLayoutUnconnected: FC<IProps> = ({ const NodeLayoutUnconnected: FC<IProps> = memo(
({
match: { match: {
params: { id }, params: { id },
}, },
@ -125,7 +126,8 @@ const NodeLayoutUnconnected: FC<IProps> = ({
</Group> </Group>
</Card> </Card>
); );
}; }
);
const NodeLayout = connect( const NodeLayout = connect(
mapStateToProps, mapStateToProps,