2021-05-28 11:43:00 +09:00
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
|
import axios from 'axios';
|
2021-05-28 11:07:47 +09:00
|
|
|
import useTranslation from 'next-translate/useTranslation'
|
|
|
|
import { useRouter } from 'next/router'
|
|
|
|
|
2021-05-28 11:43:00 +09:00
|
|
|
function App () {
|
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:55:00 +09:00
|
|
|
const [dataSpotify, setDataSpotify] = useState({ hits: [] });
|
2021-05-28 11:43:00 +09:00
|
|
|
useEffect(async () => {
|
|
|
|
const result = await axios(
|
|
|
|
'/api/Spotify',
|
|
|
|
);
|
|
|
|
|
2021-05-28 11:55:00 +09:00
|
|
|
setDataSpotify(result.dataSpotify);
|
2021-05-28 11:43:00 +09:00
|
|
|
}, []);
|
2021-05-28 11:26:28 +09:00
|
|
|
|
2021-05-28 11:55:00 +09:00
|
|
|
if (dataSpotify === undefined){
|
2021-05-28 11:36:45 +09:00
|
|
|
console.log("[Spotify Web API] データの取得に失敗しました。 / Failed to retrieve data.")
|
2021-05-28 11:07:47 +09:00
|
|
|
return <p></p>
|
|
|
|
}else{
|
2021-05-28 11:55:00 +09:00
|
|
|
if (dataSpotify.isPlaying){
|
|
|
|
const status = dataSpotify.artist + ' / ' + dataSpotify.title
|
2021-05-28 11:07:47 +09:00
|
|
|
const listening = t('listening', {listening: status})
|
|
|
|
return <p>{listening}</p>
|
|
|
|
}else{
|
|
|
|
return <p></p>
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|