From 84e303c10635056b3f62ae1b24b56321b5a66e19 Mon Sep 17 00:00:00 2001 From: Shiva Date: Thu, 3 Aug 2023 17:20:27 +0530 Subject: [PATCH] Added loading for liked songs --- src/Context/LikedSongsContext.jsx | 5 ++++- src/Page/LikedSongs.jsx | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Context/LikedSongsContext.jsx b/src/Context/LikedSongsContext.jsx index c3772dc..b2451e3 100644 --- a/src/Context/LikedSongsContext.jsx +++ b/src/Context/LikedSongsContext.jsx @@ -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(); @@ -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); @@ -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 ( diff --git a/src/Page/LikedSongs.jsx b/src/Page/LikedSongs.jsx index be7bcf0..c821b1e 100644 --- a/src/Page/LikedSongs.jsx +++ b/src/Page/LikedSongs.jsx @@ -22,8 +22,8 @@ const LikedSongs = () => {
{loggedIn ? ( loading ? ( -
- +
+

Loading

) : error ? (

Error fetching liked songs: {error}