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

refactored component errors

This commit is contained in:
Fedor Katurov 2021-03-03 17:54:58 +07:00
parent 7031084b09
commit d4c2e7ee09
79 changed files with 573 additions and 462 deletions

View file

@ -119,7 +119,7 @@ const Cell: FC<IProps> = ({
}
}, [title]);
const cellText = useMemo(() => formatCellText(text), [text]);
const cellText = useMemo(() => formatCellText(text || ''), [text]);
return (
<div className={classNames(styles.cell, styles[(flow && flow.display) || 'single'])} ref={ref}>

View file

@ -13,16 +13,22 @@ type IProps = Partial<IFlowState> & {
onChangeCellView: typeof flowSetCellView;
};
export const FlowGrid: FC<IProps> = ({ user, nodes, onSelect, onChangeCellView }) => (
<Fragment>
{nodes.map(node => (
<Cell
key={node.id}
node={node}
onSelect={onSelect}
can_edit={canEditNode(node, user)}
onChangeCellView={onChangeCellView}
/>
))}
</Fragment>
);
export const FlowGrid: FC<IProps> = ({ user, nodes, onSelect, onChangeCellView }) => {
if (!nodes) {
return null;
}
return (
<Fragment>
{nodes.map(node => (
<Cell
key={node.id}
node={node}
onSelect={onSelect}
can_edit={canEditNode(node, user)}
onChangeCellView={onChangeCellView}
/>
))}
</Fragment>
);
};

View file

@ -7,7 +7,7 @@ import { getURL } from '~/utils/dom';
import { withRouter, RouteComponentProps, useHistory } from 'react-router';
import { URLS, PRESETS } from '~/constants/urls';
import { Icon } from '~/components/input/Icon';
import { INode } from "~/redux/types";
import { INode } from '~/redux/types';
type IProps = RouteComponentProps & {
heroes: IFlowState['heroes'];
@ -18,46 +18,54 @@ const FlowHeroUnconnected: FC<IProps> = ({ heroes }) => {
const [limit, setLimit] = useState(6);
const [current, setCurrent] = useState(0);
const [loaded, setLoaded] = useState<Partial<INode>[]>([]);
const timer = useRef(null)
const timer = useRef<any>(null);
const history = useHistory();
const onLoad = useCallback((i: number) => {
setLoaded([...loaded, heroes[i]])
}, [heroes, loaded, setLoaded])
const onLoad = useCallback(
(i: number) => {
setLoaded([...loaded, heroes[i]]);
},
[heroes, loaded, setLoaded]
);
const items = Math.min(heroes.length, limit)
const items = Math.min(heroes.length, limit);
const title = useMemo(() => {
return loaded[current]?.title || '';
}, [loaded, current, heroes]);
const onNext = useCallback(() => {
if (heroes.length > limit) setLimit(limit + 1)
setCurrent(current < items - 1 ? current + 1 : 0)
}, [current, items, limit, heroes.length])
const onPrev = useCallback(() => setCurrent(current > 0 ? current - 1 : items - 1), [current, items])
if (heroes.length > limit) setLimit(limit + 1);
setCurrent(current < items - 1 ? current + 1 : 0);
}, [current, items, limit, heroes.length]);
const onPrev = useCallback(() => setCurrent(current > 0 ? current - 1 : items - 1), [
current,
items,
]);
const goToNode = useCallback(() => {
history.push(URLS.NODE_URL(loaded[current].id))
history.push(URLS.NODE_URL(loaded[current].id));
}, [current, loaded]);
useEffect(() => {
timer.current = setTimeout(onNext, 5000)
return () => clearTimeout(timer.current)
}, [current, timer.current])
timer.current = setTimeout(onNext, 5000);
return () => clearTimeout(timer.current);
}, [current, timer.current]);
useEffect(() => {
if (loaded.length === 1) onNext()
}, [loaded])
if (loaded.length === 1) onNext();
}, [loaded]);
return (
<div className={styles.wrap}>
<div className={styles.loaders}>
{
heroes.slice(0, items).map((hero, i) => (
<img src={getURL({ url: hero.thumbnail }, preset)} key={hero.id} onLoad={() => onLoad(i)} />
))
}
{heroes.slice(0, items).map((hero, i) => (
<img
src={getURL({ url: hero.thumbnail }, preset)}
key={hero.id}
onLoad={() => onLoad(i)}
/>
))}
</div>
{loaded.length > 0 && (
@ -87,10 +95,7 @@ const FlowHeroUnconnected: FC<IProps> = ({ heroes }) => {
key={hero.id}
onClick={goToNode}
>
<img
src={getURL({ url: hero.thumbnail }, preset)}
alt={hero.thumbnail}
/>
<img src={getURL({ url: hero.thumbnail }, preset)} alt={hero.thumbnail} />
</div>
))}
</div>