0
0
mirror of https://github.com/yude-jp/yude.jp synced 2024-12-22 12:10:11 +09:00

Add Spotify #NowPlaying

This commit is contained in:
yude 2021-05-28 11:07:47 +09:00
parent dc8ccde80c
commit ebf88ba96b
Signed by: yude
GPG Key ID: EB0FE5D925C4A968
2 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,30 @@
import React from "react";
import useTranslation from 'next-translate/useTranslation'
import { useRouter } from 'next/router'
import useRequest from '../lib/useRequest'
const App = () => {
const router = useRouter()
const { locale, locales, defaultLocale, pathname } = router
const { t, lang } = useTranslation("common")
const [isPlaying, setIsPlaying] = React.useState(0);
const { data } = useRequest({
url: '/api/Spotify'
})
if (data === undefined){
console.log("Spotify Web API: データの取得に失敗しました。 / Failed to retrieve data.")
return <p></p>
}else{
if (data.isPlaying === "true"){
const status = data.artist + ' - ' + data.title
const listening = t('listening', {listening: status})
return <p>{listening}</p>
}else{
return <p></p>
}
};
}
export default App;

View File

@ -8,6 +8,7 @@ import Image from 'next/image'
import DiscordStatus from './components/DiscordStatus'
import { useRouter } from 'next/router'
import DiscordPlaying from './components/DiscordPlaying'
import Spotify from './components/Spotify'
export default function About(props) {
const router = useRouter()
@ -55,6 +56,7 @@ export default function About(props) {
<p className="text-4xl subpixel-antialiased">yude</p>
<DiscordPlaying />
<Spotify />
</div>
</div>