Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Added loading for liked songs
Browse files Browse the repository at this point in the history
  • Loading branch information
ShivaBhattacharjee committed Aug 3, 2023
1 parent d034d4d commit 84e303c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/Context/LikedSongsContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const useLikedSongs = () => {

export const LikedSongsProvider = ({ children }) => {
const [likedSongs, setLikedSongs] = useState([]);
const [loading , setLoading] = useState(true)
const [error, setError] = useState('');
const { username } = useLoginContext();

Expand All @@ -20,6 +21,7 @@ export const LikedSongsProvider = ({ children }) => {
const response = await BackEndService.get(`/liked-songs/${username}?page=1`);
const data = response?.data;
setLikedSongs(data?.songs);
setLoading(false)
setError('');
} catch (error) {
console.error('Error fetching liked songs:', error);
Expand Down Expand Up @@ -62,7 +64,8 @@ export const LikedSongsProvider = ({ children }) => {
likedSongs: likedSongs,
error: error,
addSongToLikedSongs: addSongToLikedSongs,
deleteLikedSong: deleteLikedSong, // Expose the deleteLikedSong function in the context
deleteLikedSong: deleteLikedSong,
loading : loading
};

return (
Expand Down
4 changes: 2 additions & 2 deletions src/Page/LikedSongs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const LikedSongs = () => {
<div className={`lg:flex ${loggedIn && likedSongs.length !== 0 ?"grid":"flex"} grid-cols-3 items-center gap-1 flex-wrap p-2`}>
{loggedIn ? (
loading ? (
<div className='text-2xl font-bold fixed inset-0 w-full h-full flex place-items-center justify-center bg-[#2d1b69] -z-20 max-md:pr-0 pr-32 md:translate-x-1/4 md:pr-48 lg:translate-x-0'>
<LoadingSpinner/>
<div>
<h1 className='text-center'>Loading</h1>
</div>
) : error ? (
<p>Error fetching liked songs: {error}</p>
Expand Down

0 comments on commit 84e303c

Please sign in to comment.