-
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.
Merge pull request #58 from davewalker5/album-picker
Implemented album picker
- Loading branch information
Showing
15 changed files
with
241 additions
and
8 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM mcr.microsoft.com/dotnet/core/aspnet:latest | ||
COPY musiccatalogue.api-1.32.0.0 /opt/musiccatalogue.api | ||
COPY musiccatalogue.api-1.33.0.0 /opt/musiccatalogue.api | ||
WORKDIR /opt/musiccatalogue.api/bin | ||
ENTRYPOINT [ "./MusicCatalogue.Api" ] |
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
104 changes: 104 additions & 0 deletions
104
src/music-catalogue-ui/components/albums/albumPicker.js
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,104 @@ | ||
import React, { useCallback, useState } from "react"; | ||
import styles from "./albumPicker.module.css"; | ||
import { apiFetchRandomAlbum } from "@/helpers/api/apiAlbums"; | ||
import AlbumPickerAlbumRow from "./albumPickerAlbumRow"; | ||
import GenreSelector from "../genres/genreSelector"; | ||
import { apiFetchArtistById } from "@/helpers/api/apiArtists"; | ||
|
||
/** | ||
* Component to pick a random album, optionally for a specified genre | ||
* @param {*} logout | ||
* @returns | ||
*/ | ||
const AlbumPicker = ({ logout }) => { | ||
const [genre, setGenre] = useState(null); | ||
const [details, setDetails] = useState({ album: null, artist: null }); | ||
|
||
// Callback to request a random album from the API | ||
const pickAlbumCallback = useCallback( | ||
async (e) => { | ||
// Prevent the default action associated with the click event | ||
e.preventDefault(); | ||
|
||
// Request a random album, optionally filtering by the selected genre, and | ||
// retrieve the artist details | ||
const genreId = genre != null ? genre.id : null; | ||
const fetchedAlbum = await apiFetchRandomAlbum(genreId, logout); | ||
if (fetchedAlbum != null) { | ||
const fetchedArtist = await apiFetchArtistById( | ||
fetchedAlbum.artistId, | ||
logout | ||
); | ||
setDetails({ album: fetchedAlbum, artist: fetchedArtist }); | ||
} else { | ||
setDetails({ album: null, artist: null }); | ||
} | ||
}, | ||
[genre, logout] | ||
); | ||
|
||
return ( | ||
<> | ||
<div className="row mb-2 pageTitle"> | ||
<h5 className="themeFontColor text-center">Album Picker</h5> | ||
</div> | ||
<div className={styles.albumPickerFormContainer}> | ||
<form className={styles.albumPickerForm}> | ||
<div className="row" align="center"> | ||
<div className="mt-3"> | ||
<div className="d-inline-flex align-items-center"> | ||
<div className="col"> | ||
<label className={styles.albumPickerLabel}> | ||
Genre to pick from: | ||
</label> | ||
</div> | ||
<div className="col"> | ||
<div className={styles.alunmPickerGenreSelector}> | ||
<GenreSelector | ||
initialGenre={genre} | ||
genreChangedCallback={setGenre} | ||
/> | ||
</div> | ||
</div> | ||
<div className="col"> | ||
<button | ||
className="btn btn-primary" | ||
onClick={(e) => pickAlbumCallback(e)} | ||
> | ||
Pick | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
<table className="table table-hover"> | ||
<thead> | ||
<tr> | ||
<th>Artist</th> | ||
<th>Title</th> | ||
<th>Genre</th> | ||
<th>Released</th> | ||
<th>Purchased</th> | ||
<th>Price</th> | ||
<th>Retailer</th> | ||
</tr> | ||
</thead> | ||
{details.album != null && ( | ||
<tbody> | ||
{ | ||
<AlbumPickerAlbumRow | ||
key={details.album.id} | ||
album={details.album} | ||
artist={details.artist} | ||
/> | ||
} | ||
</tbody> | ||
)} | ||
</table> | ||
</> | ||
); | ||
}; | ||
|
||
export default AlbumPicker; |
22 changes: 22 additions & 0 deletions
22
src/music-catalogue-ui/components/albums/albumPicker.module.css
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,22 @@ | ||
.albumPickerFormContainer { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
.albumPickerForm { | ||
width: 100vw; | ||
padding-top: 20px; | ||
padding-bottom: 20px; | ||
} | ||
|
||
.albumPickerLabel { | ||
margin-right: 20px; | ||
font-size: 14px; | ||
font-weight: 600; | ||
color: rgb(34, 34, 34); | ||
} | ||
|
||
.alunmPickerGenreSelector { | ||
width: 200px; | ||
} |
39 changes: 39 additions & 0 deletions
39
src/music-catalogue-ui/components/albums/albumPickerAlbumRow.js
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,39 @@ | ||
import CurrencyFormatter from "../common/currencyFormatter"; | ||
import DateFormatter from "../common/dateFormatter"; | ||
|
||
/** | ||
* Component to render a row containing the details of a single album in a | ||
* genre | ||
* @param {*} album | ||
* @param {*} artist | ||
* @returns | ||
*/ | ||
const AlbumPickerAlbumRow = ({ album, artist }) => { | ||
const purchaseDate = new Date(album.purchased); | ||
|
||
return ( | ||
<tr> | ||
<td>{artist.name}</td> | ||
<td>{album.title}</td> | ||
<td>{album.genre.name}</td> | ||
{album.released > 0 ? <td>{album.released}</td> : <td />} | ||
{purchaseDate > 1900 ? ( | ||
<td> | ||
<DateFormatter value={album.purchased} /> | ||
</td> | ||
) : ( | ||
<td /> | ||
)} | ||
{album.price > 0 ? ( | ||
<td> | ||
<CurrencyFormatter value={album.price} /> | ||
</td> | ||
) : ( | ||
<td /> | ||
)} | ||
{album.retailer != null ? <td>{album.retailer.name}</td> : <td />} | ||
</tr> | ||
); | ||
}; | ||
|
||
export default AlbumPickerAlbumRow; |
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 |
---|---|---|
|
@@ -45,6 +45,6 @@ | |
text-align: center; | ||
} | ||
|
||
.genreSelector { | ||
.reportGenreSelector { | ||
width: 200px; | ||
} |
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