-
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.
Refactor album wish list management components
- Loading branch information
1 parent
1e2aeff
commit 383a506
Showing
5 changed files
with
49 additions
and
75 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
37 changes: 37 additions & 0 deletions
37
src/music-catalogue-ui/components/albumWishListActionIcon.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,37 @@ | ||
import { useCallback } from "react"; | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { | ||
faHeartCirclePlus, | ||
faRecordVinyl, | ||
} from "@fortawesome/free-solid-svg-icons"; | ||
import { apiSetAlbumWishListFlag, apiFetchAlbumsByArtist } from "@/helpers/api"; | ||
|
||
const AlbumWishListActionIcon = ({ | ||
artistId, | ||
album, | ||
isWishList, | ||
logout, | ||
setAlbums, | ||
}) => { | ||
// Set the icon depending on the direction in which the album will move | ||
const icon = isWishList ? faRecordVinyl : faHeartCirclePlus; | ||
|
||
/* Callback to move an album between the wish list and catalogue */ | ||
const setAlbumWishListFlag = useCallback(async () => { | ||
// Move the album to the wish list | ||
const result = await apiSetAlbumWishListFlag(album, !isWishList, logout); | ||
if (result) { | ||
// Successful, so refresh the album list | ||
const fetchedAlbums = await apiFetchAlbumsByArtist( | ||
artistId, | ||
isWishList, | ||
logout | ||
); | ||
setAlbums(fetchedAlbums); | ||
} | ||
}, [artistId, album, isWishList, logout, setAlbums]); | ||
|
||
return <FontAwesomeIcon icon={icon} onClick={setAlbumWishListFlag} />; | ||
}; | ||
|
||
export default AlbumWishListActionIcon; |
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