Skip to content

Commit c4863d9

Browse files
authored
Merge pull request #11740 from ethereum/youtube-lite-embed
Implement privacy-preserving react-lite-youtube-embed
2 parents 479049b + 4e04bf6 commit c4863d9

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"react-i18next": "^12.1.4",
7070
"react-icons": "^4.3.1",
7171
"react-instantsearch-dom": "^6.32.0",
72+
"react-lite-youtube-embed": "^2.4.0",
7273
"react-select": "^4.3.0",
7374
"recharts": "^2.1.9",
7475
"styled-system": "^5.1.5",

src/components/YouTube.tsx

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import React from "react"
2-
import { AspectRatio } from "@chakra-ui/react"
2+
import { Box } from "@chakra-ui/react"
3+
import LiteYouTubeEmbed from "react-lite-youtube-embed"
4+
import "react-lite-youtube-embed/dist/LiteYouTubeEmbed.css"
35

46
/**
57
* @param {id} ID of the YouTube video
@@ -11,32 +13,26 @@ import { AspectRatio } from "@chakra-ui/react"
1113
* @returns Embedded YouTube video component
1214
*/
1315

14-
export interface IProps {
16+
type YouTubeProps = {
1517
id: string
1618
start?: string
1719
title?: string
1820
}
1921

20-
const YouTube: React.FC<IProps> = ({ id, start = "0", title = "YouTube" }) => {
21-
const startQuery = parseInt(start) > 0 ? `?start=${start}` : ""
22-
const baseUrl = "https://www.youtube.com/embed/"
23-
const src = baseUrl + id + startQuery
22+
const YouTube = ({ id, start = "0", title = "YouTube" }: YouTubeProps) => {
23+
const params = new URLSearchParams()
24+
;+start > 0 && params.set("start", start)
2425
return (
25-
<AspectRatio as="figure" maxW="560px" ratio={16 / 9} my={8}>
26-
<iframe
27-
src={src}
28-
frameBorder="0"
26+
<Box as="figure" maxW={560} my={8}>
27+
<LiteYouTubeEmbed
28+
aspectHeight={9}
29+
aspectWidth={16}
30+
id={id}
2931
title={title}
30-
allow="
31-
accelerometer;
32-
autoplay;
33-
clipboard-write;
34-
encrypted-media;
35-
gyroscope;
36-
picture-in-picture"
37-
allowFullScreen
32+
params={params.toString()}
33+
noCookie
3834
/>
39-
</AspectRatio>
35+
</Box>
4036
)
4137
}
4238

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15634,6 +15634,11 @@ react-lifecycles-compat@^3.0.4:
1563415634
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"
1563515635
integrity sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA==
1563615636

15637+
react-lite-youtube-embed@^2.4.0:
15638+
version "2.4.0"
15639+
resolved "https://registry.yarnpkg.com/react-lite-youtube-embed/-/react-lite-youtube-embed-2.4.0.tgz#1f56a12be1061d50431444d52d836bd09a1283a2"
15640+
integrity sha512-Xo6cM1zPlROvvM97JkqQIoXstlQDaC4+DawmM7BB7Hh1cXrkBHEGq1iJlQxBTUWAUklmpcC7ph7qg7CztXtABQ==
15641+
1563715642
react-refresh@^0.11.0:
1563815643
version "0.11.0"
1563915644
resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.11.0.tgz#77198b944733f0f1f1a90e791de4541f9f074046"

0 commit comments

Comments
 (0)