2021-05-28 11:07:47 +09:00
|
|
|
import React from "react";
|
|
|
|
import useTranslation from 'next-translate/useTranslation'
|
|
|
|
import { useRouter } from 'next/router'
|
2021-05-28 11:26:28 +09:00
|
|
|
const url = '/api/Spotify';
|
2021-05-28 11:07:47 +09:00
|
|
|
|
2021-05-28 11:26:28 +09:00
|
|
|
function App ({data}) {
|
2021-05-28 11:07:47 +09:00
|
|
|
const router = useRouter()
|
|
|
|
const { locale, locales, defaultLocale, pathname } = router
|
2021-05-28 11:26:28 +09:00
|
|
|
const { t, lang } = useTranslation("common")
|
|
|
|
|
2021-05-28 11:07:47 +09:00
|
|
|
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>
|
2021-05-28 11:33:22 +09:00
|
|
|
console.log("[Spotify Web API] Listening: " + status)
|
2021-05-28 11:07:47 +09:00
|
|
|
}else{
|
|
|
|
return <p></p>
|
2021-05-28 11:33:22 +09:00
|
|
|
console.log("[Spotify Web API] Nothing listening")
|
2021-05-28 11:07:47 +09:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-28 11:26:28 +09:00
|
|
|
export async function getServerSideProps() {
|
|
|
|
// Fetch data from external API
|
2021-05-28 11:33:22 +09:00
|
|
|
const res = await fetch("/api/Spotify")
|
2021-05-28 11:26:28 +09:00
|
|
|
const data = await res.json()
|
|
|
|
// Pass data to the page via props
|
|
|
|
return { props: { data } }
|
|
|
|
}
|
|
|
|
|
2021-05-28 11:07:47 +09:00
|
|
|
export default App;
|