mirror of
https://github.com/yude-jp/yude.jp
synced 2024-12-22 20:20:09 +09:00
Change data retrieving method
This commit is contained in:
parent
3dd345c10f
commit
48fc60bd07
@ -7,22 +7,24 @@ function App (){
|
|||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { locale, locales, defaultLocale, pathname } = router
|
const { locale, locales, defaultLocale, pathname } = router
|
||||||
const { t, lang } = useTranslation("common")
|
const { t, lang } = useTranslation("common")
|
||||||
const [dataPlaying, setDataPlaying] = useState({ hits: [] });
|
const [data, setData] = useState({ hits: [] });
|
||||||
useEffect(async () => {
|
useEffect(() => {
|
||||||
|
const fetchData = async () => {
|
||||||
const result = await axios(
|
const result = await axios(
|
||||||
'https://discord.com/api/guilds/723409709306216498/widget.json',
|
'https://discord.com/api/guilds/723409709306216498/widget.json',
|
||||||
);
|
);
|
||||||
|
setData(result.data);
|
||||||
setDataPlaying(result.dataPlaying);
|
};
|
||||||
|
fetchData();
|
||||||
}, []);
|
}, []);
|
||||||
if (dataPlaying === undefined){
|
if (data === undefined){
|
||||||
console.log("[Discord API] データの取得に失敗しました。 / Failed to retrieve data.")
|
console.log("[Discord API] データの取得に失敗しました。 / Failed to retrieve data.")
|
||||||
return <p></p>
|
return <p></p>
|
||||||
}else{
|
}else{
|
||||||
const str = JSON.stringify(dataPlaying)
|
const str = JSON.stringify(data)
|
||||||
|
|
||||||
if (str.indexOf("game") !== -1){
|
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>
|
return <p>{yes_playing}</p>
|
||||||
}else{
|
}else{
|
||||||
return <p></p>
|
return <p></p>
|
||||||
|
@ -8,7 +8,6 @@ export default function Minecraft(props) {
|
|||||||
const { locale, locales, defaultLocale, pathname } = router
|
const { locale, locales, defaultLocale, pathname } = router
|
||||||
const { t, lang } = useTranslation("minecraft")
|
const { t, lang } = useTranslation("minecraft")
|
||||||
|
|
||||||
const [dataMinecraft, setDataMinecraft] = useState({ hits: [] });
|
|
||||||
const [data, setData] = useState({ hits: [] });
|
const [data, setData] = useState({ hits: [] });
|
||||||
const fail = t('minecraft:fail')
|
const fail = t('minecraft:fail')
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -7,21 +7,22 @@ function App () {
|
|||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { locale, locales, defaultLocale, pathname } = router
|
const { locale, locales, defaultLocale, pathname } = router
|
||||||
const { t, lang } = useTranslation("common")
|
const { t, lang } = useTranslation("common")
|
||||||
const [dataSpotify, setDataSpotify] = useState({ hits: [] });
|
const [data, setData] = useState({ hits: [] });
|
||||||
useEffect(async () => {
|
useEffect(() => {
|
||||||
|
const fetchData = async () => {
|
||||||
const result = await axios(
|
const result = await axios(
|
||||||
'/api/Spotify',
|
'/api/Spotify',
|
||||||
);
|
);
|
||||||
|
setData(result.data);
|
||||||
setDataSpotify(result.dataSpotify);
|
};
|
||||||
|
fetchData();
|
||||||
}, []);
|
}, []);
|
||||||
|
if (data === undefined){
|
||||||
if (dataSpotify === undefined){
|
|
||||||
console.log("[Spotify Web API] データの取得に失敗しました。 / Failed to retrieve data.")
|
console.log("[Spotify Web API] データの取得に失敗しました。 / Failed to retrieve data.")
|
||||||
return <p></p>
|
return <p></p>
|
||||||
}else{
|
}else{
|
||||||
if (dataSpotify.isPlaying){
|
if (data.isPlaying){
|
||||||
const status = dataSpotify.artist + ' / ' + dataSpotify.title
|
const status = data.artist + ' / ' + data.title
|
||||||
const listening = t('listening', {listening: status})
|
const listening = t('listening', {listening: status})
|
||||||
return <p>{listening}</p>
|
return <p>{listening}</p>
|
||||||
}else{
|
}else{
|
||||||
|
Loading…
Reference in New Issue
Block a user