use game endpoint instead
This commit is contained in:
@@ -1,35 +1,31 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import ProjectComponent from '../ProjectComponent';
|
import ProjectComponent from '../ProjectComponent';
|
||||||
|
|
||||||
type SteamAPIResponse = {
|
type GameAPIResponse = {
|
||||||
data: GameItem[]
|
data: GameData
|
||||||
}
|
}
|
||||||
type GameItem = {
|
type GameData = {
|
||||||
appid: number,
|
|
||||||
name: string,
|
name: string,
|
||||||
playtime_forever: number,
|
location: string,
|
||||||
img_icon_url: string,
|
startedOn: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function RecentGame() {
|
export default function RecentGame() {
|
||||||
const [ data, setData ] = useState<GameItem[]>();
|
const [ data, setData ] = useState<GameData>();
|
||||||
const [ errorState, setErrorState ] = useState<string>("");
|
const [ errorState, setErrorState ] = useState<string>("");
|
||||||
const [ loading, setLoading ] = useState<boolean>(true);
|
const [ loading, setLoading ] = useState<boolean>(true);
|
||||||
|
|
||||||
const translateToAppStorePage = (appId: number) => {
|
const getTime = (time: number) => {
|
||||||
return "https://store.steampowered.com/app/" + appId
|
const date = new Date(time*1000);
|
||||||
}
|
return `${date.toLocaleDateString()} at ${date.toLocaleTimeString()}`
|
||||||
const buildMediaUrl = (appId: number, hash: string) => {
|
|
||||||
return "https://media.steampowered.com/steamcommunity/public/images/apps/" + appId + "/" + hash + ".jpg"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch("https://api.alexav.gg/v4/social/steam", {
|
fetch("https://api.alexav.gg/v4/game", {
|
||||||
method: "get"
|
method: "get"
|
||||||
})
|
})
|
||||||
.then(async (res) => {
|
.then(async (res) => {
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const data = await res.json() as SteamAPIResponse
|
const data = await res.json() as GameAPIResponse
|
||||||
setData(data.data);
|
setData(data.data);
|
||||||
} else {
|
} else {
|
||||||
setErrorState("Failed to load! :(")
|
setErrorState("Failed to load! :(")
|
||||||
@@ -45,11 +41,11 @@ export default function RecentGame() {
|
|||||||
if (!loading && data) {
|
if (!loading && data) {
|
||||||
return (
|
return (
|
||||||
<ProjectComponent
|
<ProjectComponent
|
||||||
url={translateToAppStorePage(data[0].appid)}
|
url={"https://medal.tv/u/alexav"}
|
||||||
header={"Games I'm playing"}
|
header={"Games I'm playing"}
|
||||||
projectHeader={data[0].name}
|
projectHeader={data.name}
|
||||||
projectSubheader={`${data[0].playtime_forever / 60}h played`}
|
projectSubheader={`Started at ${getTime(data.startedOn)}`}
|
||||||
projectImage={buildMediaUrl(data[0].appid, data[0].img_icon_url)}
|
projectImage={"https://storage.alexav.gg/content/933d5523-5e20-4040-9fe9-b73552eac8ab.png"}
|
||||||
projectImageSize={"40"}
|
projectImageSize={"40"}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user