-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
139 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { gql, useQuery } from '@apollo/client' | ||
import React from 'react' | ||
|
||
import { P } from '../StyledUtils/Text' | ||
import { LoadingFrame } from '../Utils' | ||
import Message from '../Utils/Message' | ||
import { connect } from 'react-redux' | ||
import styled, { css } from 'styled-components' | ||
|
||
const captionsQuery = gql` | ||
query VideoCaptionsQuery($videoId: ID!) { | ||
video(hashId: $videoId) { | ||
id | ||
captions { | ||
text | ||
start | ||
duration | ||
} | ||
} | ||
} | ||
` | ||
|
||
const CaptionText = styled.span` | ||
color: #000; | ||
transition: | ||
color 0.3s, | ||
text-shadow 0.3s; | ||
${({ $isCurrent, $isPlaying, $isPast }) => { | ||
if ($isPlaying) { | ||
if ($isCurrent) { | ||
return css` | ||
text-shadow: #9f9f9f 1px 1px 0px; | ||
color: #000; | ||
` | ||
} else if (!$isPast) { | ||
return css` | ||
color: #999; | ||
` | ||
} | ||
} | ||
}} | ||
` | ||
|
||
const CaptionsExtractor = ({ videoId, playbackPosition, statements }) => { | ||
const { data, loading, error } = useQuery(captionsQuery, { variables: { videoId } }) | ||
|
||
// TODO watch only selection inside the captions container | ||
React.useEffect(() => { | ||
// Watch for selection changes | ||
const eventListener = (e) => { | ||
console.log('selectionchange') | ||
} | ||
|
||
document.addEventListener('selectionchange', eventListener) | ||
return () => { | ||
document.removeEventListener('selectionchange', eventListener) | ||
} | ||
}, []) | ||
|
||
if (loading) { | ||
return <LoadingFrame title="Loading captions" /> | ||
} else if (error) { | ||
// eslint-disable-next-line no-console | ||
console.error(error) | ||
return <Message type="danger">Error loading captions</Message> | ||
} else if (!data.video.captions?.length) { | ||
return <Message type="info">No captions available</Message> | ||
} | ||
|
||
return ( | ||
<P fontSize="20px" lineHeight="1.5"> | ||
{data.video.captions.map((caption, index) => { | ||
return ( | ||
<React.Fragment key={index}> | ||
<CaptionText | ||
$isPlaying={Boolean(playbackPosition)} | ||
$isPast={playbackPosition > caption.start + caption.duration} | ||
$isCurrent={ | ||
playbackPosition >= caption.start && | ||
playbackPosition <= caption.start + caption.duration | ||
} | ||
> | ||
{caption.text} | ||
</CaptionText>{' '} | ||
</React.Fragment> | ||
) | ||
})} | ||
</P> | ||
) | ||
} | ||
|
||
export default connect((state) => ({ | ||
statements: state.VideoDebate.statements.data, | ||
playbackPosition: state.VideoDebate.video.playback.position, | ||
}))(CaptionsExtractor) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters