Skip to content
This repository was archived by the owner on Oct 30, 2023. It is now read-only.

Commit 612ec9a

Browse files
hugomrdiasdaviddias
authored andcommitted
feat: add new youtube component (#121)
1 parent 097543c commit 612ec9a

File tree

7 files changed

+93
-31
lines changed

7 files changed

+93
-31
lines changed

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"react-markdown": "3.3.4",
2929
"react-live": "^1.11.0",
3030
"react-onclickoutside": "^6.7.1",
31-
"react-player": "^1.6.4",
3231
"react-scroll-to-component": "^1.0.2",
3332
"react-slick": "~0.23.1",
3433
"react-toastify": "^4.1.0",

src/shared/components/carousel/carousel-videos-item/index.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Component } from 'react'
2-
import ReactPlayer from 'react-player'
32
import PropTypes from 'prop-types'
3+
import Youtube from 'shared/components/youtube'
44

55
import styles from './index.module.css'
66

@@ -10,21 +10,14 @@ class CarouselVideosItem extends Component {
1010

1111
return (
1212
<div className={ styles.videoItemContainer } onClick={ this.handleRemainingVideoClick }>
13-
<div className={ styles.videoPlaceholder }>
14-
<ReactPlayer
15-
className={ styles.reactPlayer }
16-
url={ link }
17-
width="100%"
18-
height="100%" />
19-
</div>
13+
<Youtube link={ link } blockPlay/>
2014
<p className={ styles.videoTitle }>{ title }</p>
2115
</div>
2216
)
2317
}
2418

2519
handleRemainingVideoClick = () => {
2620
const { index, onClick } = this.props
27-
2821
return onClick(index)
2922
}
3023
}

src/shared/components/publications-and-talks-section/videos-list/index.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component } from 'react'
2-
import ReactPlayer from 'react-player'
32
import PropTypes from 'prop-types'
43
import Carousel from 'shared/components/carousel'
4+
import Youtube from 'shared/components/youtube'
55

66
import styles from './index.module.css'
77

@@ -33,15 +33,9 @@ class VideosList extends Component {
3333
const { activeIndex } = this.state
3434
const { list } = this.props
3535
const activeVideo = list[activeIndex]
36-
3736
return (
3837
<div className={ styles.selectedVideo } ref={ this.handleAtiveVideoRef }>
39-
<ReactPlayer
40-
className={ styles.reactPlayer }
41-
url={ activeVideo.link }
42-
width="100%"
43-
height="100%"
44-
controls />
38+
<Youtube link={ activeVideo.link }/>
4539
</div>
4640
)
4741
}

src/shared/components/publications-and-talks-section/videos-list/index.module.css

-7
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@
1414
& .selectedVideo {
1515
position: relative;
1616
overflow: hidden;
17-
padding-top: var(--video-ratio);
1817
border-radius: var(--player-border-radius);
19-
20-
& .reactPlayer {
21-
position: absolute;
22-
top: 0;
23-
left: 0;
24-
}
2518
}
2619

2720
& .remainingVideosContainer {
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React, { Component } from 'react'
2+
import styles from './index.module.css'
3+
4+
class YoutubeEmbed extends Component {
5+
state = { clicked: false }
6+
render () {
7+
const id = this.props.link.split('v=')[1]
8+
return (
9+
<div onClick={ this.handleClick } className={ styles.youtubeEmbed } >
10+
{ !this.state.clicked && <div>
11+
<img src={ `https://i.ytimg.com/vi/${id}/hqdefault.jpg` }/>
12+
<div className={ styles.play }></div>
13+
</div> }
14+
{ this.state.clicked && <iframe
15+
src={ `https://www.youtube-nocookie.com/embed/${id}?autoplay=1` }
16+
frameBorder="0"
17+
allowFullScreen="1">
18+
</iframe> }
19+
</div>
20+
)
21+
}
22+
23+
handleClick = () => {
24+
if (this.props.blockPlay) {
25+
return
26+
}
27+
this.setState({ clicked: true })
28+
}
29+
}
30+
31+
export default YoutubeEmbed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
.youtubeEmbed {
2+
position: relative;
3+
width: 100%;
4+
5+
/* Use 75% for 4:3 videos */
6+
height: 0;
7+
overflow: hidden;
8+
padding-bottom: 56.23%;
9+
background: #000;
10+
}
11+
12+
.youtubeEmbed iframe {
13+
position: absolute;
14+
top: 0;
15+
left: 0;
16+
width: 100%;
17+
height: 100%;
18+
z-index: 100;
19+
background: transparent;
20+
}
21+
22+
.youtubeEmbed img {
23+
position: absolute;
24+
top: 0;
25+
right: 0;
26+
bottom: 0;
27+
left: 0;
28+
width: 100%;
29+
max-width: 100%;
30+
height: auto;
31+
margin: auto;
32+
display: block;
33+
border: none;
34+
cursor: pointer;
35+
transition: 0.4s all;
36+
}
37+
38+
.youtubeEmbed img:hover {
39+
filter: brightness(75%);
40+
}
41+
42+
.youtubeEmbed .play {
43+
position: absolute;
44+
top: 50%;
45+
left: 50%;
46+
width: 72px;
47+
height: 72px;
48+
margin-top: -36px;
49+
margin-left: -36px;
50+
background: url("//i.imgur.com/TxzC70f.png") no-repeat;
51+
cursor: pointer;
52+
}

src/shared/data/publications-and-talks/index.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
const publicationsAndTalks = [
22
{
3-
link: 'https://www.youtube-nocookie.com/watch?v=WK4PIGr3RB8',
3+
link: 'https://www.youtube.com/watch?v=WK4PIGr3RB8',
44
active: true,
55
title: 'Progress Report on the Decentralized Web, David Dias'
66
},
77
{
8-
link: 'https://www.youtube-nocookie.com/watch?v=2cmbm6iABsI',
8+
link: 'https://www.youtube.com/watch?v=2cmbm6iABsI',
99
title: 'IPFS on the Brave Browser, Alan Shaw'
1010
},
1111
{
12-
link: 'https://www.youtube-nocookie.com/watch?v=4VB66hJSvqM',
12+
link: 'https://www.youtube.com/watch?v=4VB66hJSvqM',
1313
title: 'CRDTs as the foundation for Distributed Web Apps, Pedro Teixeira'
1414
},
1515
{
16-
link: 'https://www.youtube-nocookie.com/watch?v=ZnfqbIVoq-s',
16+
link: 'https://www.youtube.com/watch?v=ZnfqbIVoq-s',
1717
title: 'A Regular JS Core Dev Call, join us!'
1818
},
1919
{
20-
link: 'https://www.youtube-nocookie.com/watch?v=-kdx8rJd8rQ',
20+
link: 'https://www.youtube.com/watch?v=-kdx8rJd8rQ',
2121
title: 'Tutorial: How to build an Collaborative Editing Application with IPFS using CRDT'
2222
},
2323
{
24-
link: 'https://www.youtube-nocookie.com/watch?v=Nv_Teb--1zg',
24+
link: 'https://www.youtube.com/watch?v=Nv_Teb--1zg',
2525
title: 'Tutorial: How to build an application with IPFS PubSub Room'
2626
}
2727
]

0 commit comments

Comments
 (0)