Skip to content

Commit

Permalink
feat: render video block
Browse files Browse the repository at this point in the history
  • Loading branch information
aalemayhu committed Oct 8, 2022
1 parent c378ad1 commit 4a27d8e
Showing 1 changed file with 36 additions and 33 deletions.
69 changes: 36 additions & 33 deletions src/lib/notion/helpers/renderFront.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 `<img src='${getImageUrl(block)}' />`;
}

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 `<img src='${getImageUrl(block)}' />`;
}
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 '';
}

0 comments on commit 4a27d8e

Please sign in to comment.