From 920a8adaa2e6faed117de93f1c80ed6644a4b8f8 Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Fri, 25 Oct 2019 10:54:46 +0700 Subject: [PATCH] fixed node related --- src/components/node/NodeRelated/index.tsx | 45 ++++++++----------- src/components/node/NodeRelated/styles.scss | 9 ---- src/components/node/NodeRelatedItem/index.tsx | 35 +++++++++++++++ .../node/NodeRelatedItem/styles.scss | 30 +++++++++++++ 4 files changed, 84 insertions(+), 35 deletions(-) create mode 100644 src/components/node/NodeRelatedItem/index.tsx create mode 100644 src/components/node/NodeRelatedItem/styles.scss diff --git a/src/components/node/NodeRelated/index.tsx b/src/components/node/NodeRelated/index.tsx index a24beee5..07c70da7 100644 --- a/src/components/node/NodeRelated/index.tsx +++ b/src/components/node/NodeRelated/index.tsx @@ -2,35 +2,28 @@ import React, { FC } from 'react'; import * as styles from './styles.scss'; import { Group } from '~/components/containers/Group'; import { INode } from '~/redux/types'; -import { getURL } from '~/utils/dom'; -import { withRouter, RouteComponentProps } from 'react-router'; -import { URLS } from '~/constants/urls'; +import { NodeRelatedItem } from '~/components/node/NodeRelatedItem'; -type IProps = RouteComponentProps & { +interface IProps { title: string; items: Partial[]; +} + +const NodeRelated: FC = ({ title, items }) => { + return ( + +
+
+
{title}
+
+
+
+ {items.map(item => ( + + ))} +
+ + ); }; -const NodeRelatedUnconnected: FC = ({ title, items, history }) => ( - -
-
-
{title}
-
-
-
- {items.map(item => ( -
history.push(URLS.NODE_URL(item.id))} - /> - ))} -
- -); - -const NodeRelated = withRouter(NodeRelatedUnconnected); - export { NodeRelated }; diff --git a/src/components/node/NodeRelated/styles.scss b/src/components/node/NodeRelated/styles.scss index 959fbce5..b0b43968 100644 --- a/src/components/node/NodeRelated/styles.scss +++ b/src/components/node/NodeRelated/styles.scss @@ -17,15 +17,6 @@ grid-template-columns: repeat(6, 1fr); } } - -.item { - background: lighten($content_bg, 2%) 50% 50% no-repeat; - background-size: cover; - padding-bottom: 100%; - border-radius: $cell_radius; - cursor: pointer; -} - .title { font: $font_14_semibold; text-transform: uppercase; diff --git a/src/components/node/NodeRelatedItem/index.tsx b/src/components/node/NodeRelatedItem/index.tsx new file mode 100644 index 00000000..09eec397 --- /dev/null +++ b/src/components/node/NodeRelatedItem/index.tsx @@ -0,0 +1,35 @@ +import React, { FC, memo, useCallback, useState } from 'react'; +import * as styles from './styles.scss'; +import classNames from 'classnames'; +import { INode } from '~/redux/types'; +import { URLS } from '~/constants/urls'; +import { RouteComponentProps, withRouter } from 'react-router'; +import { getURL } from '~/utils/dom'; + +type IProps = RouteComponentProps & { + item: Partial; +}; + +const NodeRelatedItemUnconnected: FC = memo(({ item, history }) => { + const [is_loaded, setIsLoaded] = useState(false); + const onClick = useCallback(() => history.push(URLS.NODE_URL(item.id)), [item, history]); + + return ( +
+
+ + loader setIsLoaded(true)} /> +
+ ); +}); + +const NodeRelatedItem = withRouter(NodeRelatedItemUnconnected); + +export { NodeRelatedItem }; diff --git a/src/components/node/NodeRelatedItem/styles.scss b/src/components/node/NodeRelatedItem/styles.scss new file mode 100644 index 00000000..d35af1e5 --- /dev/null +++ b/src/components/node/NodeRelatedItem/styles.scss @@ -0,0 +1,30 @@ +.item { + background: lighten($content_bg, 2%) 50% 50% no-repeat; + padding-bottom: 100%; + border-radius: $cell_radius; + cursor: pointer; + position: relative; + + img { + position: absolute; + width: 0; + height: 0; + opacity: 0; + } +} + +.thumb { + position: absolute; + width: 100%; + height: 100%; + border-radius: $cell_radius; + background: lighten($content_bg, 2%) 50% 50% no-repeat; + background-size: cover; + opacity: 0; + transition: opacity 0.5s; + will-change: opacity; + + .is_loaded & { + opacity: 1; + } +}