diff --git a/src/components/Album.jsx b/src/components/Album.jsx
new file mode 100644
index 0000000..387015f
--- /dev/null
+++ b/src/components/Album.jsx
@@ -0,0 +1,30 @@
+import React, { useState, useEffect } from 'react'
+import './Artist.scss'
+
+function Album({ props, callback }) {
+ let [rate, setRate] = useState([])
+
+ const openAlbums = () => {
+ callback(props.id)
+ }
+
+ return (
+
+
+ {props.images.length > 0 && (
+

+ )}
+
+
+
+
+
+ )
+}
+
+export default Album
diff --git a/src/components/Artist.jsx b/src/components/Artist.jsx
index 180fc95..ebc98fd 100644
--- a/src/components/Artist.jsx
+++ b/src/components/Artist.jsx
@@ -1,5 +1,4 @@
import React, { useState, useEffect } from 'react'
-// import Star from './Star.jsx'
import './Artist.scss'
const star = (
diff --git a/src/components/Router.jsx b/src/components/Router.jsx
index d9126b4..dcba90d 100644
--- a/src/components/Router.jsx
+++ b/src/components/Router.jsx
@@ -12,7 +12,10 @@ history.listen(() => {
export default function Router() {
let [artistId, setArtistId] = useState(null)
let [searchTerm, setSearchTerm] = useState(null)
+ let [spotifyToken, setSpotifyToken] = useState(null)
+ // Callbacks
+
let idCallback = id => {
setArtistId(id)
}
@@ -21,18 +24,30 @@ export default function Router() {
setSearchTerm(term)
}
+ let tokenCallback = token => {
+ setSpotifyToken(token)
+ }
+
+ // Objects to be passed as props
+
let artistProps = {
idCb: idCallback,
searchCb: termCallback,
+ tokenCb: tokenCallback,
searchTerm: searchTerm
}
+ let albumProps = {
+ id: artistId,
+ token: spotifyToken
+ }
+
return (
} />
} />
- } />
+ } />
)
diff --git a/src/components/Star.jsx b/src/components/Star.jsx
deleted file mode 100644
index a2d06ef..0000000
--- a/src/components/Star.jsx
+++ /dev/null
@@ -1,14 +0,0 @@
-import React from 'react'
-
-function Star() {
- return (
-
- )
-}
-
-export default Star
diff --git a/src/views/Albums.jsx b/src/views/Albums.jsx
index 0534428..af123d1 100644
--- a/src/views/Albums.jsx
+++ b/src/views/Albums.jsx
@@ -1,11 +1,43 @@
-import React from 'react'
+import React, { useState, useEffect } from 'react'
+import SpotifyWebApi from 'spotify-web-api-js'
+import Album from '../components/Album'
+import './ArtistSearch.scss'
+
+const spotifyApi = new SpotifyWebApi()
function Albums({ props }) {
+ let [albums, setAlbums] = useState([])
+
+ spotifyApi.setAccessToken(props.token)
+
+ useEffect(() => {
+ spotifyApi.getArtistAlbums(props.id)
+ .then(function(data) {
+ setAlbums(data.items)
+ }, function(err) {
+ console.error(err)
+ })
+ }, [props])
+
+ const detailsCallback = id => {
+ console.log('Navigate to', id)
+ }
+
return (
Albums
-
{props}
+ {albums && (
+
+
+ {albums.map((album, index) => (
+ -
+
+
+ ))}
+
+
+ )}
)
}
diff --git a/src/views/ArtistSearch.jsx b/src/views/ArtistSearch.jsx
index c1b0a9a..f4ecd03 100644
--- a/src/views/ArtistSearch.jsx
+++ b/src/views/ArtistSearch.jsx
@@ -9,15 +9,19 @@ const spotifyApi = new SpotifyWebApi()
function ArtistSearch({ props }) {
let [search, setSearch] = useState(null)
let [artists, setArtists] = useState(null)
+ let [token, setToken] = useState(null)
+ // Retrieve access token from url
useEffect(() => {
const search = window.location.search
const params = new URLSearchParams(search)
const token = params.get('access_token')
+ setToken(token)
spotifyApi.setAccessToken(token)
}, [])
+ // Search artists
useEffect(() => {
if (search && search.length > 4) {
spotifyApi.searchArtists(search)
@@ -29,15 +33,23 @@ function ArtistSearch({ props }) {
}
}, [search])
+ // Load search term from props
useEffect(() => {
setSearch(props.searchTerm)
}, [props.searchTerm])
+ // Save token in Router state
+ useEffect(() => {
+ props.tokenCb(token)
+ }, [props, token])
+
+ // Save search term
const handleChange = e => {
setSearch(e.currentTarget.value)
props.searchCb(e.currentTarget.value)
}
+ // Save artist id in Router state
const albumsCallback = id => {
props.idCb(id)
history.push('/albums')