From 2b14723d7b4e495a465049acec6838a6bbd907a8 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Wed, 22 Jul 2020 18:28:07 +0200 Subject: display transcript with custom renderer --- .../transcript/components/elementTypes.image.js | 47 ++++++++++++++++++++++ .../transcript/components/elementTypes.text.js | 35 ++++++++++++++++ .../transcript/components/elementTypes.video.js | 21 ++++++++++ .../views/viewer/transcript/components/index.js | 22 ++++++++++ 4 files changed, 125 insertions(+) create mode 100644 animism-align/frontend/app/views/viewer/transcript/components/elementTypes.image.js create mode 100644 animism-align/frontend/app/views/viewer/transcript/components/elementTypes.text.js create mode 100644 animism-align/frontend/app/views/viewer/transcript/components/elementTypes.video.js create mode 100644 animism-align/frontend/app/views/viewer/transcript/components/index.js (limited to 'animism-align/frontend/app/views/viewer/transcript/components') diff --git a/animism-align/frontend/app/views/viewer/transcript/components/elementTypes.image.js b/animism-align/frontend/app/views/viewer/transcript/components/elementTypes.image.js new file mode 100644 index 0000000..c2477ee --- /dev/null +++ b/animism-align/frontend/app/views/viewer/transcript/components/elementTypes.image.js @@ -0,0 +1,47 @@ +import React, { Component } from 'react' + +export const MediaCitation = ({ media }) => { + if (media.citation) { + return ( + + ) + } + console.log(media) + return ( + + {media.author} + {', '} + {media.pre_title} + {media.title} + {media.post_title} + {'. '} + {media.date && ( + ' ' + media.date + '.' + )} + {media.medium && ( + ' ' + media.medium + '.' + )} + {media.source && ( + ' ' + media.source.trim() + )} + + ) +} + +export const MediaImage = ({ paragraph, media, currentParagraph, currentAnnotation, onAnnotationClick, onDoubleClick }) => { + if (!media.lookup) return
+ const className = currentParagraph ? 'media image current' : 'media image' + const annotation = paragraph.annotations[0] + const item = media.lookup[annotation.settings.media_id] + if (!item) return
Media not found: {annotation.settings.media_id}
+ return ( +
onDoubleClick(e, paragraph)} + > + {"["} + + {"]"} +
+ ) +} diff --git a/animism-align/frontend/app/views/viewer/transcript/components/elementTypes.text.js b/animism-align/frontend/app/views/viewer/transcript/components/elementTypes.text.js new file mode 100644 index 0000000..c2ebcd7 --- /dev/null +++ b/animism-align/frontend/app/views/viewer/transcript/components/elementTypes.text.js @@ -0,0 +1,35 @@ +import React, { Component } from 'react' + +export const Paragraph = ({ paragraph, currentParagraph, currentAnnotation, onAnnotationClick, onDoubleClick }) => { + let className = paragraph.type + if (className !== 'paragraph') className += ' paragraph' + if (currentParagraph) className += ' current' + return ( +
onDoubleClick(e, paragraph)} + > + {paragraph.annotations.map(annotation => ( + onAnnotationClick(e, paragraph, annotation)} + dangerouslySetInnerHTML={{ __html: ' ' + annotation.text + ' ' }} + /> + ))} +
+ ) +} + +export const ParagraphHeader = ({ paragraph, currentParagraph, currentAnnotation, onAnnotationClick, onDoubleClick }) => { + let className = currentParagraph ? 'header current' : 'header' + const text = paragraph.annotations.map(annotation => annotation.text).join(' ') + return ( +
onDoubleClick(e, paragraph)} + > + {text} +
+ ) +} diff --git a/animism-align/frontend/app/views/viewer/transcript/components/elementTypes.video.js b/animism-align/frontend/app/views/viewer/transcript/components/elementTypes.video.js new file mode 100644 index 0000000..fe821eb --- /dev/null +++ b/animism-align/frontend/app/views/viewer/transcript/components/elementTypes.video.js @@ -0,0 +1,21 @@ +import React, { Component } from 'react' + +import { MediaCitation } from './elementTypes.image' + +export const MediaVideo = ({ paragraph, media, currentParagraph, currentAnnotation, onAnnotationClick, onDoubleClick }) => { + if (!media.lookup) return
+ const className = currentParagraph ? 'media current' : 'media' + const annotation = paragraph.annotations[0] + const item = media.lookup[annotation.settings.media_id] + if (!item) return
Media not found: {annotation.settings.media_id}
+ return ( +
onDoubleClick(e, paragraph)} + > + {"["} + + {"]"} +
+ ) +} diff --git a/animism-align/frontend/app/views/viewer/transcript/components/index.js b/animism-align/frontend/app/views/viewer/transcript/components/index.js new file mode 100644 index 0000000..45b7d41 --- /dev/null +++ b/animism-align/frontend/app/views/viewer/transcript/components/index.js @@ -0,0 +1,22 @@ +import React from 'react' + +import { + Paragraph, ParagraphHeader +} from './elementTypes.text' + +import { + MediaVideo +} from './elementTypes.video' + +import { + MediaImage +} from './elementTypes.image' + +export const transcriptElementLookup = { + paragraph: React.memo(Paragraph), + hidden: React.memo(Paragraph), + blockquote: React.memo(Paragraph), + header: React.memo(ParagraphHeader), + video: React.memo(MediaVideo), + image: React.memo(MediaImage), +} -- cgit v1.2.3-70-g09d2