-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
12 changed files
with
692 additions
and
83 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 @@ | ||
import { z } from "zod" | ||
|
||
export const User = z.object({ | ||
username: z.string(), | ||
id: z.number(), | ||
}) | ||
|
||
export type User = z.infer<typeof User> | ||
|
||
export const Game = z.object({ | ||
id: z.number(), | ||
players: z.array(User), | ||
}) | ||
|
||
export type Game = z.infer<typeof Game> | ||
|
||
export const GamesResponse = z.object({ | ||
games: z.array(Game), | ||
}) | ||
|
||
export type GamesResponse = z.infer<typeof GamesResponse> |
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,20 @@ | ||
import { useRouteError, isRouteErrorResponse } from "react-router-dom" | ||
|
||
export default function ErrorPage() { | ||
const error = useRouteError() | ||
console.error(error) | ||
|
||
if (isRouteErrorResponse(error)) { | ||
return ( | ||
<div> | ||
<h1>Oops!</h1> | ||
<p>Sorry, an unexpected error has occurred.</p> | ||
<p> | ||
<i>{error.statusText || error.data?.message}</i> | ||
</p> | ||
</div> | ||
) | ||
} else { | ||
return <div>Oops</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,13 @@ | ||
import "primereact/resources/themes/lara-light-indigo/theme.css" //theme | ||
import "primereact/resources/primereact.min.css" //core css | ||
import "primeicons/primeicons.css" //icons | ||
import "primeflex/primeflex.css" // flex | ||
import { Outlet } from "react-router-dom" | ||
|
||
export default function Layout() { | ||
return ( | ||
<> | ||
<Outlet /> | ||
</> | ||
) | ||
} |
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,24 @@ | ||
import { Helmet } from "react-helmet-async" | ||
import { Game } from "./entities" | ||
import GameService from "./services/games.service" | ||
import { useLoaderData } from "react-router-dom" | ||
|
||
export async function loader(): Promise<Game[]> { | ||
let gs = new GameService() | ||
return await gs.getAll() | ||
} | ||
|
||
export function Lobby() { | ||
let games = useLoaderData() as Game[] | ||
|
||
return ( | ||
<> | ||
<Helmet> | ||
<title>Game Lobby - Hitster</title> | ||
</Helmet> | ||
{games.length | ||
? "Voilla, we found some games!" | ||
: "Nope, no games..."} | ||
</> | ||
) | ||
} |
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 @@ | ||
import { GamesResponse, Game } from "../entities" | ||
|
||
export default class GameService { | ||
async getAll(): Promise<Game[]> { | ||
let res = await fetch("/api/games/", { | ||
method: "GET", | ||
}) | ||
return GamesResponse.parse(await res.json()).games | ||
} | ||
} |
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,7 +1,15 @@ | ||
import { defineConfig } from "vite" | ||
import checker from "vite-plugin-checker" | ||
import viteTsconfigPaths from "vite-tsconfig-paths" | ||
import react from "@vitejs/plugin-react-swc" | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [react()], | ||
plugins: [ | ||
react(), | ||
viteTsconfigPaths(), | ||
checker({ | ||
typescript: true, | ||
}), | ||
], | ||
}) |