-
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.
Add ability to move albums from the wish list to the catalogue and vi…
…ce versa
- Loading branch information
1 parent
35b3a23
commit 1e2aeff
Showing
6 changed files
with
175 additions
and
37 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,27 @@ | ||
import { useCallback } from "react"; | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { faRecordVinyl } from "@fortawesome/free-solid-svg-icons"; | ||
import { apiSetAlbumWishListFlag, apiFetchAlbumsByArtist } from "@/helpers/api"; | ||
|
||
const AddAlbumToWishList = ({ artistId, album, logout, setAlbums }) => { | ||
/* Callback to move an album from the wish list into the catalogue */ | ||
const moveAlbumToCatalogue = useCallback(async () => { | ||
// Move the album to the catalogue | ||
const result = await apiSetAlbumWishListFlag(album, false, logout); | ||
if (result) { | ||
// Successful, so refresh the album list | ||
const fetchedAlbums = await apiFetchAlbumsByArtist( | ||
artistId, | ||
true, | ||
logout | ||
); | ||
setAlbums(fetchedAlbums); | ||
} | ||
}, [album, artistId, logout, setAlbums]); | ||
|
||
return ( | ||
<FontAwesomeIcon icon={faRecordVinyl} onClick={moveAlbumToCatalogue} /> | ||
); | ||
}; | ||
|
||
export default AddAlbumToWishList; |
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,27 @@ | ||
import { useCallback } from "react"; | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { faHeartCirclePlus } from "@fortawesome/free-solid-svg-icons"; | ||
import { apiSetAlbumWishListFlag, apiFetchAlbumsByArtist } from "@/helpers/api"; | ||
|
||
const AddAlbumToWishList = ({ artistId, album, logout, setAlbums }) => { | ||
/* Callback to prompt for confirmation and delete an album */ | ||
const moveAlbumToWishList = useCallback(async () => { | ||
// Move the album to the wish list | ||
const result = await apiSetAlbumWishListFlag(album, true, logout); | ||
if (result) { | ||
// Successful, so refresh the album list | ||
const fetchedAlbums = await apiFetchAlbumsByArtist( | ||
artistId, | ||
false, | ||
logout | ||
); | ||
setAlbums(fetchedAlbums); | ||
} | ||
}, [album, artistId, logout, setAlbums]); | ||
|
||
return ( | ||
<FontAwesomeIcon icon={faHeartCirclePlus} onClick={moveAlbumToWishList} /> | ||
); | ||
}; | ||
|
||
export default AddAlbumToWishList; |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { useCallback } from "react"; | ||
import { apiDeleteAlbum, apiFetchAlbumsByArtist } from "@/helpers/api"; | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { faTrashAlt } from "@fortawesome/free-solid-svg-icons"; | ||
|
||
const DeleteAlbum = ({ album, isWishList, logout, setAlbums }) => { | ||
/* Callback to prompt for confirmation and delete an album */ | ||
const confirmDeleteAlbum = useCallback( | ||
async (e, album) => { | ||
// Prevent the default action associated with the click event | ||
e.preventDefault(); | ||
|
||
// Show a confirmation message and get the user response | ||
const message = `This will delete the album "${album.title}" - click OK to confirm`; | ||
const result = confirm(message); | ||
|
||
// If they've confirmed the deletion ... | ||
if (result) { | ||
// ... delete the album and confirm the API call was successful | ||
const result = await apiDeleteAlbum(album.id, logout); | ||
if (result) { | ||
// Successful, so refresh the album list | ||
const fetchedAlbums = await apiFetchAlbumsByArtist( | ||
artist.id, | ||
isWishList, | ||
logout | ||
); | ||
setAlbums(fetchedAlbums); | ||
} | ||
} | ||
}, | ||
[isWishList, logout, setAlbums] | ||
); | ||
|
||
return ( | ||
<FontAwesomeIcon | ||
icon={faTrashAlt} | ||
onClick={(e) => confirmDeleteAlbum(e, album)} | ||
/> | ||
); | ||
}; | ||
|
||
export default DeleteAlbum; |
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