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

30 lines
816 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-30 17:59:08 +09:00
const [data, setData] = useState({ hits: [] });
useEffect(() => {
const fetchData = async () => {
const result = await axios(
2021-12-11 06:58:32 +09:00
'https://vercel-spotify-api.vercel.app/api/Spotify',
2021-05-30 17:59:08 +09:00
);
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{
2021-09-24 17:25:26 +09:00
return <></>
2021-05-28 11:07:47 +09:00
}
};
}
export default App;