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

37 lines
897 B
JavaScript
Raw Normal View History

2021-12-11 18:55:57 +09:00
// React
2021-05-28 11:43:00 +09:00
import React, { useState, useEffect } from 'react';
2021-12-11 18:55:57 +09:00
// Data fetching
2021-05-28 11:43:00 +09:00
import axios from 'axios';
2021-12-11 18:55:57 +09:00
// i18n
import { useTranslation, useLanguageQuery } from 'next-export-i18n';
2021-05-28 11:07:47 +09:00
2021-05-28 11:43:00 +09:00
function App () {
2021-12-11 18:55:57 +09:00
const { t } = useTranslation();
const [query] = useLanguageQuery();
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;