Skip to content

Commit

Permalink
Merge pull request #13 from Qazaq-Genius/get-songlist-from-api
Browse files Browse the repository at this point in the history
show all songs from api
  • Loading branch information
ABJ-Samuel authored Jun 19, 2023
2 parents 7c1cb6c + 843cd3d commit 4f0d3fb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
15 changes: 12 additions & 3 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,18 @@ const khyay = localFont({ src: '../../styles/Khyay-Regular.ttf' })


export async function getStaticProps() {
const { data: songData1 } = await axios.get(lyricsApi + '/song/50000001');
const { data: songData2 } = await axios.get(lyricsApi + '/song/50000002');
const songData = [songData1, songData2];
//the API gives an Array back looking like this [50000001,50000002,50000003]
const { data: songList } = await axios.get(lyricsApi + '/songs');

//we need to get the data for each song from /song/[id] and put it into an songData array
const songData = await Promise.all(
songList.map(async (songId: any) => {
const { data: song } = await axios.get(lyricsApi + `/song/${songId}`);
return song;
}
)
);

return {
props: {
songData,
Expand Down
23 changes: 12 additions & 11 deletions src/pages/song/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ const lyricsApi = process.env.LYRICS_API_HOST;


export async function getStaticPaths() {
const songs = (await axios.get(lyricsApi + '/songs')).data;
const paths = songs.map((song: any) => ({
params: {
id: song.id.toString(),
},
}));
return {
paths,
fallback: "blocking", // generate a new page if the user visits a page that doesn't exist
};
}
const songs = (await axios.get(lyricsApi + '/songs')).data;
const paths = songs.map((id: any) => ({
params: {
id: id.toString(),
},
}));
return {
paths,
// generate a new page if the user visits a page that doesn't exist
fallback: "blocking",
};
}

export async function getStaticProps({ params }: any) {
const { data: songData } = await axios.get(lyricsApi + '/song/' + params.id);
Expand Down

0 comments on commit 4f0d3fb

Please sign in to comment.