-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjj.text
56 lines (47 loc) · 1.89 KB
/
jj.text
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
import { useEffect, useState } from 'react';
import Data from '../src/data.json'
import './App.css';
function App() {
const getMusic = JSON.parse(localStorage.getItem('music'))
const [data, setData] = useState(null)
const [downloadMusic, setDownloadMusic] = useState([])
useEffect(() => {
fetch('https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=20&q=mrbean&type=video&key=AIzaSyAKCuU-AdzF8oFYHtcecCOn3xIKm3RL1Uo')
.then(response => response.json())
.then(json => setData(json))
// setData(Data)
// setData(Data)
}, [])
const handleDownload = (itemId) => {
setDownloadMusic(prev => [...prev, itemId])
localStorage.setItem('music', JSON.stringify(downloadMusic))
}
return (
<>
<div className="grid sm:grid-cols-2 lg:grid-cols-3 gap-2 p-4">
{data?.items?.map((item, index) => {
return <div className='rounded-2xl' key={item.id.videoId}>
{/* <img className='w-80 rounded-lg' src={item.snippet.thumbnails.high.url}/> */}
<iframe className='rounded-2xl' title='hello' width="100%" height="315"
src={`https://www.youtube.com/embed/${item.id.videoId}`}>
</iframe>
<p>{item.snippet.channelTitle}</p>
<button onClick={() => handleDownload(item.id.videoId)}>Download</button>
</div>
})}
</div>
<p>Downloaded Music</p>
<div>
{getMusic.map(music => {
return <div className='rounded-lg' key={music}>
{/* <img className='w-80 rounded-lg' src={item.snippet.thumbnails.high.url}/> */}
<iframe title='hello' width="650" height="315"
src={`https://www.youtube.com/embed/${music}`}>
</iframe>
<p>{music}</p>
{/* <button onClick={() => handleDownload(item.id.videoId)}>Download</button> */}
</div>
})}
</div>
</>
);