Artist component (ongoing)
This commit is contained in:
parent
456fae63c9
commit
7c9139f2ee
5 changed files with 897 additions and 6 deletions
17
src/components/Artist.jsx
Normal file
17
src/components/Artist.jsx
Normal file
|
@ -0,0 +1,17 @@
|
|||
import React from 'react'
|
||||
|
||||
function Artist({ props }) {
|
||||
return (
|
||||
<div className='artist'>
|
||||
{props.images.length > 0 && (
|
||||
<img src={props.images[0].url} style={{height:150}} />
|
||||
)}
|
||||
<p>{props.name}</p>
|
||||
<p>Popularity: {Math.floor(props.popularity/20)}</p>
|
||||
<p>Followers: {props.followers.total}</p>
|
||||
<p>Id: {props.id}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Artist
|
|
@ -1,17 +1,31 @@
|
|||
import React, { useState, useEffect } from 'react'
|
||||
import SpotifyWebApi from 'spotify-web-api-js'
|
||||
import Artist from '../components/Artist'
|
||||
import './ArtistSearch.scss'
|
||||
|
||||
const spotifyApi = new SpotifyWebApi()
|
||||
|
||||
function ArtistSearch() {
|
||||
let [token, setToken] = useState(null)
|
||||
let [search, setSearch] = useState(null)
|
||||
let [artists, setArtists] = useState(null)
|
||||
|
||||
useEffect(() => {
|
||||
const search = window.location.search
|
||||
const params = new URLSearchParams(search)
|
||||
setToken(params.get('access_token'))
|
||||
const token = params.get('access_token')
|
||||
|
||||
spotifyApi.setAccessToken(token)
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
console.log(search)
|
||||
if (search && search.length > 4) {
|
||||
spotifyApi.searchArtists(search)
|
||||
.then(function(data) {
|
||||
setArtists(data.artists.items)
|
||||
}, function(err) {
|
||||
console.error(err);
|
||||
})
|
||||
}
|
||||
}, [search])
|
||||
|
||||
const handleChange = e => {
|
||||
|
@ -23,6 +37,19 @@ function ArtistSearch() {
|
|||
<h1>Artist search</h1>
|
||||
|
||||
<input placeholder='Search for an artist' onChange={handleChange} />
|
||||
|
||||
{artists && (
|
||||
<div className='artists'>
|
||||
<ul className='list'>
|
||||
{artists.map((artist, index) => (
|
||||
<li className='list-item' key={index}>
|
||||
<Artist props={artist} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
16
src/views/ArtistSearch.scss
Normal file
16
src/views/ArtistSearch.scss
Normal file
|
@ -0,0 +1,16 @@
|
|||
.artist-search {
|
||||
h1 {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
ul {
|
||||
list-style-type: none;
|
||||
max-width: 60em;
|
||||
margin: auto;
|
||||
padding: 0;
|
||||
|
||||
li {
|
||||
display: inline-block;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue