Skip to content

Commit f6f1a40

Browse files
committed
web: Render logs for all games
1 parent 7d08f6c commit f6f1a40

6 files changed

Lines changed: 112 additions & 9 deletions

File tree

package-lock.json

Lines changed: 79 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"ps-client": "^5.1.0",
3636
"react": "^18.2.0",
3737
"react-dom": "^18.2.0",
38+
"react-json-tree": "^0.20.0",
3839
"sheets-parser": "^1.1.1",
3940
"tailwindcss": "^4.0.8",
4041
"ts-loader": "^9.5.2",

src/types/web.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import type { Request, Response } from 'express';
1+
import type { NextFunction, Request, Response } from 'express';
22
import type { ReactElement } from 'react';
33

44
export type UIRouteHandler = (
55
req: Request,
6-
res: { [key in keyof Response as key extends 'render' ? never : key]: Response[key] } & { render: Render; getBundle: GetBundle }
6+
res: { [key in keyof Response as key extends 'render' ? never : key]: Response[key] } & { render: Render; getBundle: GetBundle },
7+
next: NextFunction
78
) => void;
89

910
// Note: This isn't the actual type that's imported, but since we override render to support JSX...
1011
export type APIRoute = {
11-
handler: (req: Request, res: Response) => void;
12+
handler: (req: Request, res: Response, next: NextFunction) => void;
1213
verb?: 'get' | 'post';
1314
};
1415

src/web/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ if (IS_ENABLED.WEB) {
1818
Promise.resolve(connection)
1919
.then(() => loadStatic(app))
2020
.then(() => loadAPI(app))
21-
.then(() => loadUI(app))
2221
.then(() => loadBundles(app))
22+
.then(() => loadUI(app))
2323
.then(() => app.listen(port, () => Logger.log(`Web is running!`)));
2424
}
2525

src/web/react/pages/[game].tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { createRoot } from 'react-dom/client';
2+
import { JSONTree } from 'react-json-tree';
3+
4+
import { Error } from '@/web/react/components/error';
5+
6+
const container = document.getElementById('react-root')!;
7+
const root = createRoot(container);
8+
9+
const splitPath = window.location.pathname.split('/');
10+
const game = splitPath.at(-2)!;
11+
const gameId = splitPath.at(-1)!;
12+
13+
fetch(`/api/${game}/${gameId}`)
14+
.then(res => res.json())
15+
.then(data => {
16+
root.render(<JSONTree data={data} shouldExpandNodeInitially={() => true} />);
17+
})
18+
.catch(err => root.render(<Error err={err} />));

src/web/ui/[game]/[gameId].tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Games } from '@/ps/games';
2+
3+
import type { UIRouteHandler } from '@/types/web';
4+
5+
export const handler: UIRouteHandler = (req, res, next) => {
6+
const { game: gameType } = req.params as { game: string; gameId: string };
7+
if (!Object.keys(Games).includes(gameType)) return next();
8+
res.getBundle(gameType, `${gameType.charAt(0).toUpperCase() + gameType.substring(1)} Replay`);
9+
};

0 commit comments

Comments
 (0)