mirror of
https://github.com/yude-jp/yude.jp
synced 2025-12-16 20:54:17 +09:00
Add Spotify #NowPlaying
This commit is contained in:
30
pages/components/Spotify.js
Normal file
30
pages/components/Spotify.js
Normal 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;
|
||||
Reference in New Issue
Block a user