update game component
This commit is contained in:
@@ -1,10 +1,8 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
|
|
||||||
type GameObject = {
|
type GameObject = {
|
||||||
name: string;
|
gameextrainfo?: string;
|
||||||
location: string;
|
gameid?: string;
|
||||||
startedOn: number;
|
|
||||||
finished: boolean;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function GameComponent() {
|
export default function GameComponent() {
|
||||||
@@ -13,14 +11,12 @@ export default function GameComponent() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchGame() {
|
async function fetchGame() {
|
||||||
const response = await fetch(
|
const response = await fetch("https://api.alexav.gg/v4/social/steam");
|
||||||
"https://api.alexav.gg/v4/tracker/latestGame"
|
|
||||||
);
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (data.data && data.data.length <= 0) {
|
if (data.data && data.data.gameextrainfo) {
|
||||||
setFailedFetch(true);
|
setGame(data.data as GameObject);
|
||||||
} else setGame(data.data as GameObject);
|
} else setFailedFetch(true);
|
||||||
} else setFailedFetch(true);
|
} else setFailedFetch(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,9 +34,7 @@ export default function GameComponent() {
|
|||||||
href={`https://medal.tv/u/alexav`}
|
href={`https://medal.tv/u/alexav`}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
>
|
>
|
||||||
<h1 className="lowercase">
|
<h1 className="lowercase">playing {game.gameextrainfo}</h1>
|
||||||
{!game.finished ? "playing" : "last played"} {game.name}
|
|
||||||
</h1>
|
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -48,7 +42,7 @@ export default function GameComponent() {
|
|||||||
if (failedFetch) {
|
if (failedFetch) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<p>failed to get game :(</p>
|
<p>not playing anything</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export default function TVComponent() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchMusic() {
|
async function fetchMusic() {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
"https://api.alexav.gg/v4/tracker/items?type=tv&sort=desc"
|
"https://api.alexav.gg/v4/tracker/items?type=tv&sort=desc&limit=1"
|
||||||
);
|
);
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|||||||
Reference in New Issue
Block a user