update game module to new endpoint
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
|
|
||||||
type GameObject = {
|
type GameObject = {
|
||||||
gameextrainfo?: string;
|
game: string;
|
||||||
gameid?: string;
|
startedOn: number;
|
||||||
|
finishedAt?: number;
|
||||||
|
finished: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function GameComponent() {
|
export default function GameComponent() {
|
||||||
@@ -11,10 +13,12 @@ export default function GameComponent() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchGame() {
|
async function fetchGame() {
|
||||||
const response = await fetch("https://api.alexav.gg/v4/social/steam");
|
const response = await fetch(
|
||||||
|
"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.gameextrainfo) {
|
if (data.data && data.data.game) {
|
||||||
setGame(data.data as GameObject);
|
setGame(data.data as GameObject);
|
||||||
} else setFailedFetch(true);
|
} else setFailedFetch(true);
|
||||||
} else setFailedFetch(true);
|
} else setFailedFetch(true);
|
||||||
@@ -27,6 +31,23 @@ export default function GameComponent() {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
if (game) {
|
if (game) {
|
||||||
|
const dateOrTime = () => {
|
||||||
|
if (game.finished && game.finishedAt) {
|
||||||
|
const currentDate = new Date();
|
||||||
|
const finishedDate = new Date(game.finishedAt);
|
||||||
|
|
||||||
|
if (
|
||||||
|
currentDate.toLocaleDateString() === finishedDate.toLocaleDateString()
|
||||||
|
) {
|
||||||
|
return `last played ${game.game} at ${finishedDate.toLocaleTimeString()}`;
|
||||||
|
} else {
|
||||||
|
return `last played ${game.game} on ${finishedDate.toLocaleDateString()}`;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return `playing ${game.game}`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex align-middle">
|
<div className="flex align-middle">
|
||||||
<a
|
<a
|
||||||
@@ -34,7 +55,7 @@ export default function GameComponent() {
|
|||||||
href={`https://medal.tv/u/alexav`}
|
href={`https://medal.tv/u/alexav`}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
>
|
>
|
||||||
<h1 className="lowercase">playing {game.gameextrainfo}</h1>
|
<h1 className="lowercase">{dateOrTime()}</h1>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user