diff --git a/src/music-catalogue-ui/components/addAlbumToCatalogue.js b/src/music-catalogue-ui/components/addAlbumToCatalogue.js deleted file mode 100644 index 2a95334..0000000 --- a/src/music-catalogue-ui/components/addAlbumToCatalogue.js +++ /dev/null @@ -1,27 +0,0 @@ -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 ( - - ); -}; - -export default AddAlbumToWishList; diff --git a/src/music-catalogue-ui/components/addAlbumToWishList.js b/src/music-catalogue-ui/components/addAlbumToWishList.js deleted file mode 100644 index 9143085..0000000 --- a/src/music-catalogue-ui/components/addAlbumToWishList.js +++ /dev/null @@ -1,27 +0,0 @@ -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 ( - - ); -}; - -export default AddAlbumToWishList; diff --git a/src/music-catalogue-ui/components/albumRow.js b/src/music-catalogue-ui/components/albumRow.js index 93c1e48..253693f 100644 --- a/src/music-catalogue-ui/components/albumRow.js +++ b/src/music-catalogue-ui/components/albumRow.js @@ -1,7 +1,6 @@ import pages from "@/helpers/navigation"; -import DeleteAlbum from "./deleteAlbum"; -import AddAlbumToWishList from "./addAlbumToWishList"; -import AddAlbumToCatalogue from "./addAlbumToCatalogue"; +import DeleteAlbumActionIcon from "./deleteAlbumActionIcon"; +import AlbumWishListActionIcon from "./albumWishListActionIcon"; /** * Component to render a row containing the details of a single album @@ -36,7 +35,7 @@ const AlbumRow = ({ {album.released} - - {isWishList == false ? ( - - ) : ( - - )} + ); diff --git a/src/music-catalogue-ui/components/albumWishListActionIcon.js b/src/music-catalogue-ui/components/albumWishListActionIcon.js new file mode 100644 index 0000000..2195098 --- /dev/null +++ b/src/music-catalogue-ui/components/albumWishListActionIcon.js @@ -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 ; +}; + +export default AlbumWishListActionIcon; diff --git a/src/music-catalogue-ui/components/deleteAlbum.js b/src/music-catalogue-ui/components/deleteAlbumActionIcon.js similarity index 91% rename from src/music-catalogue-ui/components/deleteAlbum.js rename to src/music-catalogue-ui/components/deleteAlbumActionIcon.js index bfdc5d6..6135554 100644 --- a/src/music-catalogue-ui/components/deleteAlbum.js +++ b/src/music-catalogue-ui/components/deleteAlbumActionIcon.js @@ -3,7 +3,7 @@ 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 }) => { +const DeleteAlbumActionIcon = ({ album, isWishList, logout, setAlbums }) => { /* Callback to prompt for confirmation and delete an album */ const confirmDeleteAlbum = useCallback( async (e, album) => { @@ -40,4 +40,4 @@ const DeleteAlbum = ({ album, isWishList, logout, setAlbums }) => { ); }; -export default DeleteAlbum; +export default DeleteAlbumActionIcon;