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

Change data retrieving method

This commit is contained in:
yude 2021-05-30 17:59:08 +09:00
parent 3dd345c10f
commit 48fc60bd07
Signed by: yude
GPG Key ID: EB0FE5D925C4A968
3 changed files with 26 additions and 24 deletions

View File

@ -7,22 +7,24 @@ function App (){
const router = useRouter()
const { locale, locales, defaultLocale, pathname } = router
const { t, lang } = useTranslation("common")
const [dataPlaying, setDataPlaying] = useState({ hits: [] });
useEffect(async () => {
const result = await axios(
'https://discord.com/api/guilds/723409709306216498/widget.json',
);
setDataPlaying(result.dataPlaying);
}, []);
if (dataPlaying === undefined){
const [data, setData] = useState({ hits: [] });
useEffect(() => {
const fetchData = async () => {
const result = await axios(
'https://discord.com/api/guilds/723409709306216498/widget.json',
);
setData(result.data);
};
fetchData();
}, []);
if (data === undefined){
console.log("[Discord API] データの取得に失敗しました。 / Failed to retrieve data.")
return <p></p>
}else{
const str = JSON.stringify(dataPlaying)
const str = JSON.stringify(data)
if (str.indexOf("game") !== -1){
const yes_playing = t('yes_playing', {playing: dataPlaying.members[0].game.name})
const yes_playing = t('yes_playing', {playing: data.members[0].game.name})
return <p>{yes_playing}</p>
}else{
return <p></p>

View File

@ -8,7 +8,6 @@ export default function Minecraft(props) {
const { locale, locales, defaultLocale, pathname } = router
const { t, lang } = useTranslation("minecraft")
const [dataMinecraft, setDataMinecraft] = useState({ hits: [] });
const [data, setData] = useState({ hits: [] });
const fail = t('minecraft:fail')
useEffect(() => {

View File

@ -7,21 +7,22 @@ function App () {
const router = useRouter()
const { locale, locales, defaultLocale, pathname } = router
const { t, lang } = useTranslation("common")
const [dataSpotify, setDataSpotify] = useState({ hits: [] });
useEffect(async () => {
const result = await axios(
'/api/Spotify',
);
setDataSpotify(result.dataSpotify);
}, []);
if (dataSpotify === undefined){
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.")
return <p></p>
}else{
if (dataSpotify.isPlaying){
const status = dataSpotify.artist + ' / ' + dataSpotify.title
if (data.isPlaying){
const status = data.artist + ' / ' + data.title
const listening = t('listening', {listening: status})
return <p>{listening}</p>
}else{