From 7d8ac0db76516153a0ad8f97101aaad092c85c18 Mon Sep 17 00:00:00 2001 From: Daniel McCrystal Date: Thu, 21 Aug 2025 00:27:58 -0400 Subject: [PATCH] around the table --- packages/client/src/api.ts | 3 ++ packages/client/src/app.tsx | 1 - packages/client/src/components/Table.tsx | 57 +++++++++++++++++------- packages/server/src/api.ts | 13 ++++-- 4 files changed, 54 insertions(+), 20 deletions(-) diff --git a/packages/client/src/api.ts b/packages/client/src/api.ts index c881bd8..251f18b 100644 --- a/packages/client/src/api.ts +++ b/packages/client/src/api.ts @@ -1,3 +1,4 @@ +import { createResource } from "solid-js"; import { type Api } from "../../server/src/api"; import { treaty } from "@elysiajs/eden"; @@ -8,3 +9,5 @@ const { api } = treaty( } ); export default api; + +export const [me] = createResource(() => api.whoami.post().then((r) => r.data)); diff --git a/packages/client/src/app.tsx b/packages/client/src/app.tsx index a29522c..8e0637b 100644 --- a/packages/client/src/app.tsx +++ b/packages/client/src/app.tsx @@ -35,7 +35,6 @@ const Profile = () => { }; const App = () => { - api.whoami.post(); return ( ( diff --git a/packages/client/src/components/Table.tsx b/packages/client/src/components/Table.tsx index 66857b7..daf69cd 100644 --- a/packages/client/src/components/Table.tsx +++ b/packages/client/src/components/Table.tsx @@ -17,7 +17,7 @@ import { vGameState, PlayerView, } from "../../../server/src/games/simple"; -import api from "../api"; +import api, { me } from "../api"; import Hand from "./Hand"; import Pile from "./Pile"; import { ApiType } from "../fn"; @@ -66,23 +66,48 @@ export default (props: { tableKey: string }) => { }); }); - const Lobby = () => { - return ( -
- - - {(player) => ( -

- {playerProfiles[player]?.()?.name} -

- )} -
-
- ); - }; return ( - }> +
+ p != me())}> + {(player, i) => { + const verticalOffset = () => { + const N = players().length - 1; + const x = Math.abs((2 * i() + 1) / (N * 2) - 0.5); + const y = Math.sqrt(1 - x * x); + return 1 - y; + }; + return ( +
+

+ {playerProfiles[player]?.()?.name} +

+
+ ); + }} +
+
+
+ +
+ +
+
+
+
diff --git a/packages/server/src/api.ts b/packages/server/src/api.ts index d7b1d81..bbb78a8 100644 --- a/packages/server/src/api.ts +++ b/packages/server/src/api.ts @@ -7,17 +7,24 @@ import { liveTable } from "./table"; const api = new Elysia({ prefix: "/api" }) .post("/whoami", async ({ cookie: { token } }) => { + let human; if (token.value == null) { - const newHuman = await db.human.create({ + human = await db.human.create({ data: {}, }); token.set({ - value: newHuman.token, + value: human.token, expires: dayjs().add(1, "year").toDate(), httpOnly: true, }); + } else { + human = await db.human.findUniqueOrThrow({ + where: { + token: token.value, + }, + }); } - return token.value; + return human.key; }) .use(human) .post(