prisma experiment

This commit is contained in:
2025-08-08 23:31:07 -04:00
parent 96df75972a
commit a7e339a8ce
2 changed files with 22 additions and 6 deletions

View File

@@ -10,31 +10,33 @@ export const GameContext = createContext<{
}>(); }>();
export default (props: { instanceId: number }) => { export default (props: { instanceId: number }) => {
const [gameState, { refetch }] = createResource(() => const [gameState, { refetch, mutate }] = createResource(() =>
api api
.gameState({ gameId: props.instanceId.toString() }) .gameState({ gameId: props.instanceId.toString() })
.get() .get()
.then((res) => res.data as GameState) .then((res) => res.data as GameState)
); );
const setGameState = (state: GameState) => const setGameState = (state: GameState) => {
api mutate(state);
return api
.gameState({ gameId: props.instanceId.toString() }) .gameState({ gameId: props.instanceId.toString() })
.put({ .put({
gameState: state, gameState: state,
}) })
.then(refetch); .then(refetch);
};
return ( return (
<GameContext.Provider value={{ gameState, setGameState }}> <GameContext.Provider value={{ gameState, setGameState }}>
<Show when={gameState() != undefined}> <Show when={gameState.latest != undefined}>
<div <div
class="full column center" class="full column center"
style={{ "row-gap": "20px", "font-size": "32px" }} style={{ "row-gap": "20px", "font-size": "32px" }}
> >
<div class="full center"> <div class="full center">
<Pile <Pile
pile={gameState()!.deck} pile={gameState.latest!.deck}
style={{ cursor: "pointer" }} style={{ cursor: "pointer" }}
onClick={() => { onClick={() => {
const [drawn, ...rest] = gameState()!.deck; const [drawn, ...rest] = gameState()!.deck;
@@ -45,7 +47,7 @@ export default (props: { instanceId: number }) => {
}} }}
/> />
</div> </div>
<Hand hand={gameState()!.hand} /> <Hand hand={gameState.latest!.hand} />
</div> </div>
</Show> </Show>
</GameContext.Provider> </GameContext.Provider>

View File

@@ -1,7 +1,21 @@
import { prisma } from "./db/db"; import { prisma } from "./db/db";
import { Elysia, t } from "elysia"; import { Elysia, t } from "elysia";
import { Prisma } from "@prisma/client";
const api = new Elysia({ prefix: "/api" }) const api = new Elysia({ prefix: "/api" })
// [wip]
.group("/prisma", (app) =>
app
.post("/game", ({ body }: { body: Prisma.GameFindManyArgs }) =>
prisma.game.findMany(body)
)
.post(
"/instance",
({ body }: { body: Prisma.InstanceFindManyArgs }) =>
prisma.instance.findMany(body)
)
)
.get("/games", () => prisma.game.findMany()) .get("/games", () => prisma.game.findMany())
.get("/instances", ({ query: { game } }) => .get("/instances", ({ query: { game } }) =>