From 265aad45223a6769513b1cc9e0230a805d281e33 Mon Sep 17 00:00:00 2001 From: Daniel McCrystal Date: Tue, 19 Aug 2025 22:19:24 -0400 Subject: [PATCH] checkpoint --- packages/client/src/components/Game.tsx | 32 +++++++++++++++++++++++-- packages/client/src/fn.ts | 4 ++++ packages/client/uno.config.ts | 10 ++++++++ packages/server/src/api.ts | 12 ++++++++-- 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/packages/client/src/components/Game.tsx b/packages/client/src/components/Game.tsx index de4e762..e02748f 100644 --- a/packages/client/src/components/Game.tsx +++ b/packages/client/src/components/Game.tsx @@ -1,10 +1,13 @@ import { Accessor, createContext, + createEffect, createResource, createSignal, For, onCleanup, + Resource, + ResourceReturn, Show, } from "solid-js"; import { @@ -16,16 +19,38 @@ import { import api from "../api"; import Hand from "./Hand"; import Pile from "./Pile"; +import { ApiType } from "../fn"; +import { createStore } from "solid-js/store"; export const GameContext = createContext<{ view: Accessor; submitAction: (action: Action) => Promise; }>(); +const [playerProfiles, setPlayerProfiles] = createStore< + Record< + string, + ReturnType>>[0] + > +>({}); + export default (props: { instanceId: string }) => { const [view, setView] = createSignal(); const [players, setPlayers] = createSignal([]); + createEffect(() => { + players().forEach((player) => { + if (!playerProfiles[player]) { + const [playerProfile] = createResource(() => + api.profile + .get({ query: { otherHumanKey: player } }) + .then((r) => r.data) + ); + setPlayerProfiles(player, playerProfile); + } + }); + }); + const ws = api.simple(props).subscribe(); onCleanup(() => ws.close()); ws.on("message", (evt) => { @@ -38,8 +63,11 @@ export default (props: { instanceId: string }) => { const Lobby = () => { return ( -
- {(player) =>

{player}

}
+
+ + + {(player) =>

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

} +
); }; diff --git a/packages/client/src/fn.ts b/packages/client/src/fn.ts index 62749df..fbbf4be 100644 --- a/packages/client/src/fn.ts +++ b/packages/client/src/fn.ts @@ -7,3 +7,7 @@ Array.prototype.thru = function (this: T[], fn: (arr: T[]) => S) { return fn(this); }; export const clone = (o: T): T => JSON.parse(JSON.stringify(o)); + +export type ApiType Promise<{ data: any }>> = Awaited< + ReturnType +>["data"]; diff --git a/packages/client/uno.config.ts b/packages/client/uno.config.ts index c662c0d..13f38da 100644 --- a/packages/client/uno.config.ts +++ b/packages/client/uno.config.ts @@ -31,6 +31,16 @@ export default defineConfig({ "margin-right": "auto", }, ], + [ + "tc", + { + top: 0, + left: 0, + right: 0, + "margin-left": "auto", + "margin-right": "auto", + }, + ], [ "center", diff --git a/packages/server/src/api.ts b/packages/server/src/api.ts index 5f1606a..f752284 100644 --- a/packages/server/src/api.ts +++ b/packages/server/src/api.ts @@ -36,8 +36,16 @@ const api = new Elysia({ prefix: "/api" }) }), } ) - .get("/profile", ({ humanKey }) => - db.human.findFirst({ where: { key: humanKey } }) + .get("/profile", ({ humanKey, query: { otherHumanKey } }) => + db.human + .findFirst({ where: { key: otherHumanKey ?? humanKey } }) + .then((human) => { + if (human == null) { + return null; + } + const { token, ...safeProfile } = human; + return safeProfile; + }) ) .get("/games", () => [{ key: "simple", name: "simple" }])