0
0
mirror of https://github.com/yude-jp/yude.jp synced 2024-12-22 12:10:11 +09:00

Update variables

This commit is contained in:
yude 2021-05-28 11:55:00 +09:00
parent 8b3a484d08
commit 622d43554f
Signed by: yude
GPG Key ID: EB0FE5D925C4A968
4 changed files with 13 additions and 17 deletions

View File

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

View File

@ -8,10 +8,7 @@ const App = () => {
.then((r) => r.json())
.then((j) => setStatus(j.members[0].status))
}, []);
if (status === undefined){
console.log("[Discord API] オンライン状態を取得できませんでした。 / Failed to retrieve online status.")
return <div></div>
}else{
if (status === "online") {
return <div className="font-bold text-gray-700 rounded-full bg-green-500 flex w-5 h-5 items-center justify-center"></div>
}else{
@ -26,6 +23,5 @@ const App = () => {
}
}
};
}
export default App;

View File

@ -7,21 +7,21 @@ function App () {
const router = useRouter()
const { locale, locales, defaultLocale, pathname } = router
const { t, lang } = useTranslation("common")
const [data, setData] = useState({ hits: [] });
const [dataSpotify, setDataSpotify] = useState({ hits: [] });
useEffect(async () => {
const result = await axios(
'/api/Spotify',
);
setData(result.data);
setDataSpotify(result.dataSpotify);
}, []);
if (data === undefined){
if (dataSpotify === undefined){
console.log("[Spotify Web API] データの取得に失敗しました。 / Failed to retrieve data.")
return <p></p>
}else{
if (data.isPlaying){
const status = data.artist + ' / ' + data.title
if (dataSpotify.isPlaying){
const status = dataSpotify.artist + ' / ' + dataSpotify.title
const listening = t('listening', {listening: status})
return <p>{listening}</p>
}else{

View File

@ -55,9 +55,11 @@ export default function About(props) {
/>
<p className="text-4xl subpixel-antialiased">yude</p>
<div>
<DiscordPlaying />
<Spotify />
</div>
</div>
</div>
{