Skip to content

Commit

Permalink
rename /work to /projects, add /fun
Browse files Browse the repository at this point in the history
  • Loading branch information
blake-mealey committed Feb 12, 2022
1 parent c3acf31 commit f1fa52e
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# secrets
.env

# dependencies
/node_modules
/.pnp
Expand Down
10 changes: 10 additions & 0 deletions _pages/fun.mdx
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 />
2 changes: 1 addition & 1 deletion _pages/home.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Hi! I'm Blake Mealey, and this is my little corner of the internet.

What's on this site:

- [~/work](/work): A list of projects I've built in my free
- [~/projects](/projects): A list of projects I've built in my free
time
- [~/posts](/posts): A collection of my thoughts

Expand Down
4 changes: 2 additions & 2 deletions _pages/work.mdx → _pages/projects.mdx
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.

Expand Down
5 changes: 4 additions & 1 deletion components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@ const Layout: NextPage<LayoutProps> = ({ children, slug, meta }) => {
<Link href="/home">home</Link>
</li>
<li>
<Link href="/work">work</Link>
<Link href="/projects">projects</Link>
</li>
<li>
<Link href="/posts">posts</Link>
</li>
<li>
<Link href="/fun">fun</Link>
</li>
</ul>
</nav>

Expand Down
2 changes: 2 additions & 0 deletions components/MdxRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Link from 'next/link';
import createHeadingComponent from './createHeadingComponent';
import Shortcut from './Shortcut';
import Image from 'next/image';
import RocketLeague from './RocketLeague';

const shortcodes = {
Shortcut,
Expand All @@ -19,6 +20,7 @@ const shortcodes = {
h4: createHeadingComponent('h4'),
h5: createHeadingComponent('h5'),
h6: createHeadingComponent('h6'),
RocketLeague,
};

const MdxRenderer = function ({ source }: { source: any }) {
Expand Down
72 changes: 72 additions & 0 deletions components/RocketLeague.tsx
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>
);
}
21 changes: 21 additions & 0 deletions components/rocket-league.module.css
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;
}
6 changes: 6 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ module.exports = {
destination: '/home',
permanent: true,
},
{
source: '/work',
destination: '/projects',
// Not totally sure that we want this to be permanent - maybe we want to have something else at /work in the future?
permanent: false,
},
];
},
};
2 changes: 1 addition & 1 deletion pages/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const getStaticProps: GetStaticProps<PageProps> = async ({ params }) => {

export const getStaticPaths: GetStaticPaths = async () => {
return {
paths: ['/home', '/work'],
paths: ['/home', '/projects', '/fun'],
fallback: false,
};
};
Expand Down
34 changes: 34 additions & 0 deletions pages/api/rocket-league.ts
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() });
}
1 change: 1 addition & 0 deletions public/images/rocket-league.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,13 @@ h1 {

a {
color: var(--theme-secondary);
&:hover {
opacity: var(--theme-hover-opacity);
}
transition: opacity 0.2s ease-in-out;
}

a:hover {
opacity: var(--theme-hover-opacity);
}

main h1,
main h2,
main h3,
Expand Down

1 comment on commit f1fa52e

@vercel
Copy link

@vercel vercel bot commented on f1fa52e Feb 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.