-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeaturedVideo.tsx
More file actions
80 lines (76 loc) · 2.27 KB
/
FeaturedVideo.tsx
File metadata and controls
80 lines (76 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { IonFabButton, IonIcon } from "@ionic/react";
import {
arrowBack,
arrowForward,
chevronCollapseOutline,
chevronForward,
} from "ionicons/icons";
import React, { useEffect, useState } from "react";
function FeaturedVideo() {
const [videos, setVideos] = useState<string[]>([]);
const token = import.meta.env.VITE_STRAPY_TOKEN;
const [index, setIndex] = useState(0);
useEffect(() => {
fetch(
`${import.meta.env.VITE_STRAPI_URL}/api/main-page-videos?populate=*`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
}
)
.then((res) => res.json())
.then((resp) => {
const data = resp.data;
const urls = data.map((video: any) => video.attributes.url);
const embedUrls: string[] = urls.map((video: string) =>
video.replace("watch?v=", "embed/")
);
setVideos(embedUrls);
console.log(videos);
});
}, []);
return (
<div>
<div className="flex justify-center">
<iframe
src={videos[index]}
title="Featured Videos"
allowFullScreen={true}
className="mx-0 rounded-lg w-10/12 md:w-9/12 lg:w-8/12 xl:w-6/12 2xl:w-5/12 mx-auto h-72 md:h-96"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; fullscreen;"
></iframe>
</div>
<div className="w-10/12 md:w-9/12 lg:w-8/12 xl:w-6/12 2xl:w-5/12 mx-auto flex justify-between">
{/* <IonFabButton
className="-mt-16 ml-2"
style={{ "--background": "orangered" }}
>
<IonIcon
icon={arrowBack}
onClick={() => {
console.log(index);
setIndex(index === 0 ? videos.length - 1 : index - 1);
}}
/>
</IonFabButton> */}
<div></div>
<IonFabButton
className="-mt-16 mr-2"
style={{ "--background": "orangered" }}
>
<IonIcon
icon={arrowForward}
onClick={() => {
console.log(index);
setIndex(index === videos.length - 1 ? 0 : index + 1);
}}
/>
</IonFabButton>
</div>
</div>
);
}
export default FeaturedVideo;