0
0
mirror of https://github.com/yude-jp/yude.jp synced 2024-12-23 12:40:11 +09:00
yude.jp/pages/components/Spotify.js

33 lines
921 B
JavaScript
Raw Normal View History

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
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){
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{
return <p></p>
}
};
}
export default App;