Skip to content

Commit 3b183e3

Browse files
committed
fix: un-necessary client side call for spotify api removed
1 parent 4721b1b commit 3b183e3

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

components/Footer/index.tsx

-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
1-
import SpotifyLogo from '../Spotify/SpotifySvg';
21
import Line from '../Line';
32
import { LinkComponent } from '../Typography';
4-
import { useEffect } from 'react';
53
import NowPlaying from '../Spotify/NowPlaying';
64

75
export default function Footer() {
8-
useEffect(() => {
9-
fetch('/api/fetchCurrentPlayingSong')
10-
.then((response) => response.json())
11-
.then((response) => {
12-
console.log(response);
13-
});
14-
}, []);
15-
166
return (
177
<footer className="Footer mt-12">
188
<Line />

constants/apiMap.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const apiMap = {
22
SPOTIFY_GET_CURRENT_PLAYING_TRACK:
33
'https://api.spotify.com/v1/me/player/currently-playing',
44
SPOTIFY_ACCESS_TOKEN: 'https://accounts.spotify.com/api/token',
5+
SPOTIFY_TOP_TRACKS_ENDPOINT: 'https://api.spotify.com/v1/me/top/tracks',
56
};
67

78
export default apiMap;

pages/about.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,13 @@ export default function AboutPage() {
1717
</>
1818
);
1919
}
20+
21+
// export async function getServerSideProps() {
22+
// const res = await getTopTracks();
23+
// const tracks = await res.json();
24+
// return {
25+
// props: {
26+
// tracks: tracks.items,
27+
// },
28+
// };
29+
// }

pages/blog/[slug].tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import SeoManager from '../../components/SeoManager/SeoManager';
77
import { getAllPosts, getPostBySlug } from '../../utils/index';
88
import { blogFrontMatter } from '../../types/blogfrontMatter';
99

10-
function BlogPosts(props: {source: any, frontMatter: blogFrontMatter }) {
10+
function BlogPosts(props: { source: any; frontMatter: blogFrontMatter }) {
1111
return (
1212
<>
1313
<SeoManager
@@ -29,8 +29,8 @@ export function getStaticPaths() {
2929
}));
3030
return {
3131
paths,
32-
fallback: false
33-
}
32+
fallback: false,
33+
};
3434
}
3535

3636
export async function getStaticProps(pageData) {

utils/spotify.ts

+10
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,13 @@ export const getNowPlaying = async () => {
3333
},
3434
});
3535
};
36+
37+
export const getTopTracks = async () => {
38+
const { access_token } = await getAccessToken();
39+
40+
return fetch(apiMap.SPOTIFY_TOP_TRACKS_ENDPOINT, {
41+
headers: {
42+
Authorization: `Bearer ${access_token}`,
43+
},
44+
});
45+
};

0 commit comments

Comments
 (0)