0
0
mirror of https://github.com/yude-jp/yude.jp synced 2024-06-09 23:36:01 +09:00
yude.jp/pages/components/Spotify.js

35 lines
1.0 KiB
JavaScript
Raw Normal View History

2021-05-28 11:07:47 +09:00
import React from "react";
import useTranslation from 'next-translate/useTranslation'
import { useRouter } from 'next/router'
const url = '/api/Spotify';
2021-05-28 11:07:47 +09:00
function App ({data}) {
2021-05-28 11:07:47 +09:00
const router = useRouter()
const { locale, locales, defaultLocale, pathname } = router
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.")
2021-05-28 11:07:47 +09:00
return <p></p>
}else{
if (data.isPlaying === "true"){
const status = data.artist + ' - ' + data.title
const listening = t('listening', {listening: status})
return <p>{listening}</p>
console.log("[Spotify Web API] Listening: " + status)
2021-05-28 11:07:47 +09:00
}else{
return <p></p>
console.log("[Spotify Web API] Nothing listening")
2021-05-28 11:07:47 +09:00
}
};
}
export async function getServerSideProps() {
// Fetch data from external API
const res = await fetch("/api/Spotify")
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;