Skip to content

Commit 846a17e

Browse files
committed
displayed all songs of playlist
1 parent 3f83c00 commit 846a17e

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

src/components/Header.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ export default function Header() {
4545

4646
<div className="flex items-center gap-6">
4747
<div className="flex items-center gap-3 py-2 pl-2 pr-4 rounded-full bg-background-secondary bg-opacity-70">
48-
{session?.user.image !== undefined ? (
49-
<User2 className="p-1 rounded-full bg-paper-400" />
50-
) : (
48+
{session?.user.image ? (
5149
<Image
5250
src={session?.user.picture as string}
5351
className="object-contain w-8 h-8 rounded-full"
5452
alt={session?.user?.name}
5553
height={32}
5654
width={32}
5755
/>
56+
) : (
57+
<User2 className="p-1 rounded-full bg-paper-400" />
5858
)}
5959
<span className="text-sm font-bold tracking-wide">
6060
{session?.user.name}

src/lib/actions.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,27 @@ export const getUserLikedArtists = async (
120120
return data.artists.items;
121121
};
122122

123+
type LikedSongs = { total: number; items: Track[] };
124+
123125
export const getUserLikedSongs = async (
124126
session: AuthSession
125-
): Promise<{ total: number; items: Track[] }> => {
127+
): Promise<LikedSongs> => {
126128
const data = await customGet(
127129
`https://api.spotify.com/v1/me/tracks?limit=50`,
128130
session
129131
);
132+
133+
const finalData = { total: data.total, items: data.items };
134+
let limit = 50;
135+
let currUrl = data.next;
136+
137+
while (currUrl !== null) {
138+
const nextData = await customGet(currUrl, session);
139+
finalData.items.push(...nextData.items);
140+
limit += 50;
141+
currUrl = nextData.next;
142+
}
143+
130144
return {
131145
total: data.total,
132146
items: data.items.map((item: any) => item.track),
@@ -147,10 +161,23 @@ export const getPlaylistById = async (
147161
session: AuthSession,
148162
playlistId: string
149163
): Promise<Playlist> => {
150-
return customGet(
164+
const data = await customGet(
151165
`https://api.spotify.com/v1/playlists/${playlistId}`,
152166
session
153167
);
168+
const playlist = data;
169+
170+
let limit = 50;
171+
let currUrl = data.tracks.next;
172+
173+
while (currUrl !== null) {
174+
const nextData = await customGet(currUrl, session);
175+
playlist.tracks.items.push(...nextData.items);
176+
limit += 50;
177+
currUrl = nextData.next;
178+
}
179+
180+
return playlist;
154181
};
155182

156183
export const getCategories = async (

0 commit comments

Comments
 (0)