Skip to content

Commit

Permalink
Queue names
Browse files Browse the repository at this point in the history
Allow users to choose their name that shows up in queue

To do:
make ui look good
  • Loading branch information
ymmot239 committed Nov 22, 2024
1 parent 636c577 commit ad509f1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/client/setup/setup-base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function SetupBase(props: SetupBaseProps): JSX.Element {
canEscapeKeyClose={false}
canOutsideClickClose={false}
usePortal={false}
enforceFocus={false}
>
<DialogBody>{props.children}</DialogBody>
<DialogFooter minimal actions={props.actions} />
Expand Down
20 changes: 19 additions & 1 deletion src/client/setup/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ function getMessageHandler(setQueue: Dispatch<string[]>): MessageHandler {
*/
export function Sidebar(): JSX.Element {
const [queue, setQueue] = useState<string[]>([]);
const [name, setName] = useState<string>(
"player " + Math.floor(Math.random() * 2000),
);

const sendMessage = useSocket(getMessageHandler(setQueue));

Expand Down Expand Up @@ -56,11 +59,26 @@ export function Sidebar(): JSX.Element {
return <li key={data}>{data}</li>;
})}
</ul>
<label
style={{
position: "absolute",
bottom: "40px",
margin: "5px",
}}
>
Name:
<input
style={{ width: "90%" }}
value={name}
onChange={(e) => setName(e.target.value)}
/>
</label>
<Button
minimal
type="submit"
style={{ position: "absolute", bottom: "10px" }}
onClick={async () => {
sendMessage(new JoinQueue("yay" + Math.random() * 100));
sendMessage(new JoinQueue(name));
}}
>
Join queue
Expand Down
2 changes: 1 addition & 1 deletion src/server/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const websocketHandler: WebsocketRequestHandler = (ws, req) => {
socketManager.sendToAll(new UpdateQueue([...names.values()]));
socketManager.sendToAll(new GameStartedMessage());
}
}, 2000);
}, 5000);
});

ws.on("message", (data) => {
Expand Down

0 comments on commit ad509f1

Please sign in to comment.