Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display text transcripts #92

Merged
merged 4 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Render plain text transcripts
  • Loading branch information
Dananji committed Aug 26, 2021
commit afa701bdf888686c01cc6f3d9a11b379b1f1b237
10 changes: 5 additions & 5 deletions src/components/IIIFPlayer/IIIFPlayer.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ import './IIIFPlayer.scss';
<StructuredNavigation />
<Transcript
transcripts={[
{
title: 'Transcript 2',
data: transcript_2,
url: 'https://dlib.indiana.edu/iiif_av/iiif-player-samples/transcripts/lunchroom_2.json',
},
{
title: 'Transcript 1',
data: transcript_1,
url: 'https://dlib.indiana.edu/iiif_av/iiif-player-samples/transcripts/lunchroom_1.json',
},
{
title: 'Transcript in WebVTT',
data: null,
url: 'https://dlib.indiana.edu/iiif_av/lunchroom_manners/lunchroom_manners.vtt',
},
{
title: 'Transcript 3 with a really really really long long long name',
data: transcript_1,
Expand Down
1 change: 0 additions & 1 deletion src/components/MediaPlayer/MediaPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ const MediaPlayer = () => {
bigPlayButton: false,
controls: true,
fluid: true,
muted: true,
controlBar: {
// Define and order control bar controls
// See https://docs.videojs.com/tutorial-components.html for options of what
Expand Down
11 changes: 7 additions & 4 deletions src/components/Transcript/Transcript.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ const Transcript = ({ transcripts }) => {

return (
<div
className={`irmp--transcript_nav ${
transcriptRef.current ? '' : 'static'
}`}
className="irmp--transcript_nav"
data-testid="transcript_nav"
key={transcriptTitle}
onMouseOver={() => handleMouseOver(true)}
Expand All @@ -175,7 +173,12 @@ const Transcript = ({ transcripts }) => {
transcriptData={transcripts}
/>
</div>
<div className="transcript_content" ref={transcriptContainerRef}>
<div
className={`transcript_content ${
transcriptRef.current ? '' : 'static'
}`}
ref={transcriptContainerRef}
>
{transcriptRef.current ? (
timedText
) : (
Expand Down
12 changes: 6 additions & 6 deletions src/components/Transcript/Transcript.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@

.irmp--transcript_nav {
max-height: 30em;
overflow-y: auto;
font-size: 0.85em;
padding: 10px;
div.active {
background-color: $primaryLight;
}

div.transcript_content {
height: 30em;
height: 25em;
overflow-y: auto;
}

div.transcript_content.static {
overflow-y: unset;
}

div.transcript_menu {
position: sticky;
top: 0;
}

iframe.transcript_gdoc-viewer {
width: 100%;
width: -moz-available; /* WebKit-based browsers will ignore this. */
Expand All @@ -27,10 +31,6 @@
}
}

.irmp--transcript_nav.static {
overflow-y: visible;
}

div.irmp--transcript_item {
display: flex;
margin: 10px 10px 10px 10px;
Expand Down
26 changes: 9 additions & 17 deletions src/components/Transcript/TranscriptMenu/TranscriptDownloader.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
import React from 'react';

// Handled file types for downloads
const validFileExtensions = ['doc', 'docx', 'json', 'js', 'srt', 'txt', 'vtt'];

const TranscriptDownloader = ({ fileUrl, fileName }) => {
const handleDownload = (e) => {
e.preventDefault();
const extension = fileUrl.split('.').reverse()[0];
// If unhandled file type use .doc
const fileExtension = validFileExtensions.includes(extension)
? extension
: 'doc';
fetch(fileUrl)
.then((response) => {
// console.log(response);
response.blob().then((blob) => {
console.log(blob);
let url = window.URL.createObjectURL(blob);
console.log(url);
let a = document.createElement('a');
a.href = url;
a.download = fileName;
a.download = `${fileName}.${fileExtension}`;
a.click();
});
})
.catch((error) => {
console.log(error);
});

// fetch(fileUrl, { responseType: 'blob' })
// .then((response) => {
// const json = JSON.stringify(response.data);
// const blob = new Blob([response.data], {
// type: 'application/json',
// });
// const link = document.createElement('a');
// link.href = URL.createObjectURL(blob);
// link.download = fileName;
// link.click();
// URL.revokeObjectURL(link.href);
// })
// .catch((error) => console.error(error));
};

return (
Expand Down
1 change: 0 additions & 1 deletion src/services/utility-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ export function timeToS(time) {
let minutesInS = minutes ? parseInt(minutes) * 60 : 0;
let secondsNum = seconds === '' ? 0.0 : parseFloat(seconds);
let timeSeconds = hoursInS + minutesInS + secondsNum;
// console.log('in: ', time, ' | out: ', timeSeconds);
return timeSeconds;
}