-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Spotify now playing song in about section.
- Loading branch information
1 parent
14c52a0
commit 0846d71
Showing
10 changed files
with
370 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ dist-ssr | |
*.njsproj | ||
*.sln | ||
*.sw? | ||
.env |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import * as React from "react"; | ||
import type { AuthProps } from "../types/spotify"; | ||
import type { GetNowPlayingResponse } from "../services/spotify"; | ||
import { | ||
Stack, | ||
Box, | ||
Typography, | ||
Card, | ||
CardContent, | ||
CardMedia, | ||
} from "@mui/material"; | ||
import { getNowPlaying } from "../services/spotify"; | ||
|
||
export default function SpotifyNowPlaying({ | ||
clientId, | ||
clientSecret, | ||
refreshToken, | ||
}: AuthProps) { | ||
const [loading, setLoading] = React.useState(true); | ||
const [nowPlayingData, setNowPlayingData] = | ||
React.useState<GetNowPlayingResponse | null>(null); | ||
|
||
React.useEffect(() => { | ||
getNowPlaying({ clientId, clientSecret, refreshToken }) | ||
.then((response) => { | ||
setNowPlayingData(response); | ||
setLoading(false); | ||
}) | ||
.catch((error) => { | ||
console.error("Error fetching now playing data:", error); | ||
}); | ||
}, [clientId, clientSecret, refreshToken]); | ||
|
||
return ( | ||
<> | ||
{loading ? ( | ||
<Typography>Loading...</Typography> | ||
) : nowPlayingData && nowPlayingData?.is_playing ? ( | ||
<Card | ||
sx={{ | ||
display: "flex", | ||
maxHeight: 70, | ||
justifyContent: "space-between", | ||
maxWidth: ["fit-content", 300], | ||
backgroundColor: "black", | ||
color: "white", | ||
}} | ||
> | ||
<Stack flexDirection="column" alignItems="baseline"> | ||
<CardContent sx={{ padding: 1.5 }}> | ||
<Typography fontSize={["0.7rem", "1rem"]}> | ||
{nowPlayingData.item.name} | ||
</Typography> | ||
<Typography | ||
variant="subtitle1" | ||
component="div" | ||
fontSize={["0.7rem", "1rem"]} | ||
> | ||
{nowPlayingData.item?.artists | ||
.map((_artist) => _artist.name) | ||
.join(",")} | ||
</Typography> | ||
</CardContent> | ||
</Stack> | ||
<Box maxWidth={70}> | ||
<CardMedia | ||
component="img" | ||
sx={{ width: "100%" }} | ||
image={nowPlayingData.item?.album.images[0].url} | ||
alt={nowPlayingData.item.name} | ||
/> | ||
</Box> | ||
</Card> | ||
) : ( | ||
<Typography>You're offline.</Typography> | ||
)} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { default as Navigation } from "./Navigation"; | ||
export { default as SpotifyNowPlaying } from "./SpotifyNowPlaying"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const TOKEN_ENDPOINT = "https://accounts.spotify.com/api/token"; | ||
export const NOW_PLAYING_ENDPOINT = | ||
"https://api.spotify.com/v1/me/player/currently-playing"; | ||
|
||
export const CLIENT_ID = import.meta.env.VITE_APP_SPOTIFY_CLIENT_ID; | ||
export const CLIENT_SECRET = import.meta.env.VITE_APP_SPOTIFY_CLIENT_SECRET; | ||
export const REFRESH_TOKEN = import.meta.env.VITE_APP_SPOTIFY_REFRESH_TOKEN; |
Oops, something went wrong.