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

displaying node videos

This commit is contained in:
Fedor Katurov 2019-10-19 20:06:48 +07:00
parent f7c2f0e90f
commit 6917c465f3
4 changed files with 52 additions and 0 deletions

View file

@ -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<IProps> = ({ 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 (
<div className={styles.wrap}>
<iframe
width="560"
height="315"
src={`https://www.youtube.com/embed/${video}`}
frameBorder="0"
allowFullScreen
title="video"
/>
</div>
);
};
export { NodeVideoBlock };

View file

@ -0,0 +1,12 @@
.wrap {
padding-bottom: 56.25%;
position: relative;
iframe {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
}

View file

@ -6,6 +6,7 @@ export const ERRORS = {
FILES_REQUIRED: 'Files_Required', FILES_REQUIRED: 'Files_Required',
TEXT_REQUIRED: 'Text_Required', TEXT_REQUIRED: 'Text_Required',
UNKNOWN_NODE_TYPE: 'Unknown_Node_Type', UNKNOWN_NODE_TYPE: 'Unknown_Node_Type',
URL_INVALID: 'Url_Invalid',
}; };
export const ERROR_LITERAL = { export const ERROR_LITERAL = {
@ -16,4 +17,5 @@ export const ERROR_LITERAL = {
[ERRORS.FILES_REQUIRED]: 'Добавьте файлы', [ERRORS.FILES_REQUIRED]: 'Добавьте файлы',
[ERRORS.TEXT_REQUIRED]: 'Нужно немного текста', [ERRORS.TEXT_REQUIRED]: 'Нужно немного текста',
[ERRORS.UNKNOWN_NODE_TYPE]: 'Неизвестный тип поста', [ERRORS.UNKNOWN_NODE_TYPE]: 'Неизвестный тип поста',
[ERRORS.URL_INVALID]: 'Неизвестный адрес',
}; };

View file

@ -2,6 +2,7 @@ import { FC } from 'react';
import { INode, ValueOf, IComment } from '../types'; import { INode, ValueOf, IComment } from '../types';
import { NodeImageSlideBlock } from '~/components/node/NodeImageSlideBlock'; import { NodeImageSlideBlock } from '~/components/node/NodeImageSlideBlock';
import { NodeTextBlock } from '~/components/node/NodeTextBlock'; import { NodeTextBlock } from '~/components/node/NodeTextBlock';
import { NodeVideoBlock } from '~/components/node/NodeVideoBlock';
import { ImageEditor } from '~/components/editors/ImageEditor'; import { ImageEditor } from '~/components/editors/ImageEditor';
import { TextEditor } from '~/components/editors/TextEditor'; import { TextEditor } from '~/components/editors/TextEditor';
import { VideoEditor } from '~/components/editors/VideoEditor'; import { VideoEditor } from '~/components/editors/VideoEditor';
@ -66,6 +67,7 @@ type INodeComponents = Record<
export const NODE_COMPONENTS: INodeComponents = { export const NODE_COMPONENTS: INodeComponents = {
[NODE_TYPES.IMAGE]: NodeImageSlideBlock, [NODE_TYPES.IMAGE]: NodeImageSlideBlock,
[NODE_TYPES.VIDEO]: NodeVideoBlock,
}; };
export const NODE_INLINES: INodeComponents = { export const NODE_INLINES: INodeComponents = {