-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3acf31
commit f1fa52e
Showing
13 changed files
with
161 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
title: Fun | ||
--- | ||
|
||
## Why not? | ||
|
||
I play a lot of Rocket League... this widget updates regularly with my latest time played according | ||
to Steam. | ||
|
||
<RocketLeague /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
--- | ||
title: Work | ||
title: Projects | ||
--- | ||
|
||
## Work | ||
## Projects | ||
|
||
A list of projects I've built in my free time. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { FC, useEffect, useState } from 'react'; | ||
import styles from './rocket-league.module.css'; | ||
|
||
interface ResponseData { | ||
minutes: number; | ||
} | ||
|
||
type State = | ||
| { | ||
status: 'loading'; | ||
} | ||
| { status: 'loaded'; data: ResponseData } | ||
| { status: 'error'; error: any }; | ||
|
||
const numberFormatter = new Intl.NumberFormat('en-US', { | ||
style: 'unit', | ||
unit: 'hour', | ||
unitDisplay: 'long', | ||
}); | ||
|
||
interface ContentProps { | ||
state: State; | ||
} | ||
|
||
const Content = ({ state }: ContentProps) => { | ||
if (state.status === 'loading') { | ||
return <div>...</div>; | ||
} | ||
|
||
if (state.status === 'error') { | ||
console.error(state.error); | ||
return <div>Something went wrong :(</div>; | ||
} | ||
|
||
if (state.status === 'loaded') { | ||
return ( | ||
<div> | ||
<div className={styles.label}>Time played</div> | ||
<div>{numberFormatter.format(state.data.minutes / 60)}</div> | ||
</div> | ||
); | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
export default function RocketLeague() { | ||
const [state, setState] = useState<State>({ | ||
status: 'loading', | ||
}); | ||
useEffect(() => { | ||
fetch('/api/rocket-league') | ||
.then((res) => { | ||
res | ||
.json() | ||
.then((data) => setState({ status: 'loaded', data })) | ||
.catch((error) => { | ||
setState({ status: 'error', error }); | ||
}); | ||
}) | ||
.catch((error) => { | ||
setState({ status: 'error', error }); | ||
}); | ||
}, []); | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<img className={styles.logo} src="/images/rocket-league.svg" /> | ||
<Content state={state} /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.container { | ||
font-size: 40px; | ||
padding: var(--theme-spacing-2) var(--theme-spacing-2); | ||
border: 2px solid var(--theme-primary); | ||
border-radius: var(--theme-roundness); | ||
width: fit-content; | ||
display: flex; | ||
align-items: center; | ||
gap: 1em; | ||
} | ||
|
||
.logo { | ||
width: 5em; | ||
} | ||
|
||
.label { | ||
font-size: 0.5em; | ||
font-weight: bold; | ||
opacity: 0.75; | ||
margin-bottom: -0.5em; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
|
||
const ROCKET_LEAGUE_APP_ID = 252950; | ||
|
||
async function getStats() { | ||
const key = process.env.STEAM_API_KEY; | ||
|
||
const request = encodeURIComponent( | ||
JSON.stringify({ | ||
steamid: process.env.STEAM_ACCOUNT_ID, | ||
appids_filter: [ROCKET_LEAGUE_APP_ID], | ||
}) | ||
); | ||
|
||
const response = await fetch( | ||
`https://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=${key}&format=json&input_json=${request}` | ||
); | ||
|
||
return await response.json(); | ||
} | ||
|
||
export default async function handler( | ||
_req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
const data = await getStats(); | ||
const game = data.response.games.find( | ||
(game: any) => game.appid === ROCKET_LEAGUE_APP_ID | ||
); | ||
|
||
// Cache for an hour across all users | ||
res.setHeader('Cache-Control', 'public, s-maxage=3600, must-revalidate'); | ||
res.status(200).json({ minutes: game.playtime_forever, time: Date.now() }); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f1fa52e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: