-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
58a3f08
commit 33feb05
Showing
10 changed files
with
143 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import useAlbums from "@/hooks/useAlbums"; | ||
import statuses from "@/helpers/status"; | ||
import AlbumRow from "./albumRow"; | ||
import StatusIndicator from "./statusIndicator"; | ||
|
||
const AlbumList = ({ artist, navigate }) => { | ||
const { albums, setAlbums, currentStatus } = useAlbums(artist.id); | ||
|
||
if (currentStatus !== statuses.loaded) | ||
return <StatusIndicator currentStatus={currentStatus} />; | ||
|
||
return ( | ||
<> | ||
<div className="row mb-2"> | ||
<h5 className="themeFontColor text-center">Albums</h5> | ||
</div> | ||
<table className="table table-hover"> | ||
<thead> | ||
<tr> | ||
<th>Album Title</th> | ||
<th>Artist</th> | ||
<th>Genre</th> | ||
<th>Released</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{albums.map((a) => ( | ||
<AlbumRow key={a.id} artist={artist} album={a} navgate={navigate} /> | ||
))} | ||
</tbody> | ||
</table> | ||
</> | ||
); | ||
}; | ||
|
||
export default AlbumList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import pages from "@/helpers/navigation"; | ||
|
||
const AlbumRow = ({ artist, album, navigate }) => { | ||
return ( | ||
<tr onClick={() => navigate(pages.tracks, album)}> | ||
<td>{artist.name}</td> | ||
<td>{album.title}</td> | ||
<td>{album.genre}</td> | ||
<td>{album.released}</td> | ||
</tr> | ||
); | ||
}; | ||
|
||
export default AlbumRow; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// This file is temporary, pending implementation of user login | ||
const username = "a-user"; | ||
const password = "the-password"; | ||
const baseUrl = "http://host:port"; | ||
const username = "dave"; | ||
const password = "password"; | ||
const baseUrl = "http://localhost:8098"; | ||
|
||
export { baseUrl, username, password }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import statuses from "@/helpers/status"; | ||
import { useState, useEffect } from "react"; | ||
import { apiFetchAlbumsByArtist } from "@/helpers/api"; | ||
|
||
const useAlbums = (artistId) => { | ||
// Current list of albums and the method to change it | ||
const [albums, setAlbums] = useState([]); | ||
|
||
// Current status indicator and the method to change it, defaults to "loading" | ||
const [currentStatus, setCurrentStatus] = useState(statuses.isLoading); | ||
|
||
useEffect(() => { | ||
const fetchAlbums = async (artistId) => { | ||
// Set the "loading" indicator | ||
setCurrentStatus(statuses.isLoading); | ||
|
||
try { | ||
// Get a list of albums via the service, store it in state and clear the | ||
// loading status | ||
var fetchedAlbums = await apiFetchAlbumsByArtist(artistId); | ||
setAlbums(fetchedAlbums); | ||
setCurrentStatus(statuses.loaded); | ||
} catch { | ||
setCurrentStatus(statuses.hasErrored); | ||
} | ||
}; | ||
|
||
fetchAlbums(artistId); | ||
}, []); | ||
|
||
return { albums, setAlbums, currentStatus }; | ||
}; | ||
|
||
export default useAlbums; |