1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 04:46:40 +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

@ -1,16 +1,16 @@
import React, { FC, memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
import styles from "./styles.module.scss";
import classNames from "classnames";
import { INode } from "~/redux/types";
import { PRESETS, URLS } from "~/constants/urls";
import { RouteComponentProps, withRouter } from "react-router";
import { getURL, stringToColour } from "~/utils/dom";
import React, { FC, memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import styles from './styles.module.scss';
import classNames from 'classnames';
import { INode } from '~/redux/types';
import { PRESETS, URLS } from '~/constants/urls';
import { RouteComponentProps, withRouter } from 'react-router';
import { getURL, stringToColour } from '~/utils/dom';
type IProps = RouteComponentProps & {
item: Partial<INode>;
};
type CellSize = 'small' | 'medium' | 'large'
type CellSize = 'small' | 'medium' | 'large';
const getTitleLetters = (title: string): string => {
const words = (title && title.split(' ')) || [];
@ -43,17 +43,21 @@ const NodeRelatedItemUnconnected: FC<IProps> = memo(({ item, history }) => {
useEffect(() => {
if (!ref.current) return;
const cb = () => setWidth(ref.current.getBoundingClientRect().width)
const cb = () => setWidth(ref.current!.getBoundingClientRect().width);
window.addEventListener('resize', cb);
cb();
return () => window.removeEventListener('resize', cb);
}, [ref.current])
}, [ref.current]);
const size = useMemo<CellSize>(() => {
if (width > 90) return 'large';
if (width > 76) return 'medium';
return 'small';
}, [width])
}, [width]);
return (
<div