From 4a27d8eccea6792432567391bdf40cb3b80fee13 Mon Sep 17 00:00:00 2001 From: Alexander Alemayhu Date: Sat, 8 Oct 2022 22:01:05 +0200 Subject: [PATCH] feat: render video block --- src/lib/notion/helpers/renderFront.tsx | 69 ++++++++++++++------------ 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/src/lib/notion/helpers/renderFront.tsx b/src/lib/notion/helpers/renderFront.tsx index 5204ae6ac..78c02d65d 100644 --- a/src/lib/notion/helpers/renderFront.tsx +++ b/src/lib/notion/helpers/renderFront.tsx @@ -5,12 +5,10 @@ import BlockHandler from '../BlockHandler'; import { BlockHeading } from '../blocks/BlockHeadings'; import FrontFlashcard from '../blocks/FrontFlashcard'; import BlockColumn from '../blocks/lists/BlockColumn'; +import { BlockVideo } from '../blocks/media/BlockVideo'; import getColumn from './getColumn'; import { getImageUrl } from './getImageUrl'; -import isColumnList from './isColumnList'; import isHeading from './isHeading'; -import { isImage } from './isImage'; -import isToggle from './isToggle'; import renderTextChildren from './renderTextChildren'; export default async function renderFront( @@ -22,35 +20,40 @@ export default async function renderFront( if (isHeading(block)) { return BlockHeading(type, block, handler); } - - if (isColumnList(block)) { - const firstColumn = await getColumn(block.id, handler, 0); - if (firstColumn) { - return BlockColumn(firstColumn, handler); - } - } - - // Do not add the images in default mode - if (handler.settings.learnMode && isImage(block)) { - return ``; - } - - if (isToggle(block)) { - // @ts-ignore - const { toggle } = block; - if (toggle && toggle.text?.length > 0) { - return renderTextChildren(toggle.text, handler.settings); - } - } - try { - // @ts-ignore - return FrontFlashcard(block[type], handler); - } catch (error) { - captureException(error); - return `Unsupported block type in front: ${type}\n${JSON.stringify( - block, - null, - 4 - )}`; + switch (type) { + case 'column_list': + const firstColumn = await getColumn(block.id, handler, 0); + if (firstColumn) { + return BlockColumn(firstColumn, handler); + } + break; + case 'image': + // Do not add the images in default mode + if (handler.settings.learnMode) { + return ``; + } + break; + case 'toggle': + // @ts-ignore + const { toggle } = block; + if (toggle && toggle.text?.length > 0) { + return renderTextChildren(toggle.text, handler.settings); + } + break; + case 'video': + return BlockVideo(block, handler); + default: + try { + // @ts-ignore + return FrontFlashcard(block[type], handler); + } catch (error) { + captureException(error); + return `Unsupported block type in front: ${type}\n${JSON.stringify( + block, + null, + 4 + )}`; + } } + return ''; }