From 6917c465f3a3b51e2b37c4ace1f722fd22e11cf8 Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Sat, 19 Oct 2019 20:06:48 +0700 Subject: [PATCH] displaying node videos --- src/components/node/NodeVideoBlock/index.tsx | 36 +++++++++++++++++++ .../node/NodeVideoBlock/styles.scss | 12 +++++++ src/constants/errors.ts | 2 ++ src/redux/node/constants.ts | 2 ++ 4 files changed, 52 insertions(+) create mode 100644 src/components/node/NodeVideoBlock/index.tsx create mode 100644 src/components/node/NodeVideoBlock/styles.scss diff --git a/src/components/node/NodeVideoBlock/index.tsx b/src/components/node/NodeVideoBlock/index.tsx new file mode 100644 index 00000000..0c250b4c --- /dev/null +++ b/src/components/node/NodeVideoBlock/index.tsx @@ -0,0 +1,36 @@ +import React, { FC, useMemo } from 'react'; +import { INode } from '~/redux/types'; +import * as styles from './styles.scss'; +import path from 'ramda/es/path'; + +interface IProps { + node: INode; +} + +const NodeVideoBlock: FC = ({ node }) => { + const video = useMemo(() => { + const url: string = path(['blocks', 0, 'url'], node); + const match = + url && + url.match( + /http(?:s?):\/\/(?:www\.)?youtu(?:be\.com\/watch\?v=|\.be\/)([\w\-\_]*)(&(amp;)?[\w\?=]*)?/ + ); + + return match && match[1]; + }, [node]); + + return ( +
+