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-30 17:59:08 +09:00
|
|
|
const [data, setData] = useState({ hits: [] });
|
|
|
|
useEffect(() => {
|
|
|
|
const fetchData = async () => {
|
|
|
|
const result = await axios(
|
|
|
|
'/api/Spotify',
|
|
|
|
);
|
|
|
|
setData(result.data);
|
|
|
|
};
|
|
|
|
fetchData();
|
|
|
|
}, []);
|
|
|
|
if (data === 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-30 17:59:08 +09:00
|
|
|
if (data.isPlaying){
|
|
|
|
const status = data.artist + ' / ' + data.title
|
2021-06-14 12:36:18 +09:00
|
|
|
return <p>{t('listening', {listening: status})}</p>
|
2021-05-28 11:07:47 +09:00
|
|
|
}else{
|
2021-09-24 17:25:26 +09:00
|
|
|
return <></>
|
2021-05-28 11:07:47 +09:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|