Skip to content

Commit

Permalink
Implement display room capacity and how much empty seats left #141
Browse files Browse the repository at this point in the history
  • Loading branch information
Haaaan1 committed May 12, 2024
1 parent 29abd2c commit c873683
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
48 changes: 34 additions & 14 deletions src/components/views/Lobby.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -450,25 +450,45 @@ const Lobby = () => {
}, [navigate, showToast]);

const renderRoomLists = () => {
return rooms.map((Room) => (
<div className="room-container" key={Room.roomId} onClick={handleRoomClick(Room)}>
<div className="room-players">
{Room.roomPlayersList?.map((user, index) => (
<div className="player" key={index}>
<i className={"twa twa-" + user.avatar} style={{ fontSize: "3.8rem" }} />
return rooms.map((Room) => {
const playerSlots = [];

// 生成玩家头像或空白框,总数等于房间最大玩家数
for (let i = 0; i < Room.roomMaxNum; i++) {
if (i < Room.roomPlayersList.length) {
const user = Room.roomPlayersList[i];
playerSlots.push(
<div className="player" key={i}>
<i className={`twa twa-${user.avatar}`} style={{ fontSize: "3.8rem" }} />
<div className="name">{user.userName}</div>
</div>
))}
</div>
<div className="room-header">
<div style={{ fontWeight: "bold" }}>{Room.roomName}</div>
<div>{Room.theme}</div>
<span className={`room-status ${Room.status === "INGAME" ? "in-game" : Room.status === "WAITING" ? "waiting" : "game-over"}`}>
);
} else {
// 空白框
playerSlots.push(
<div className="player" key={i}>

</div>
);
}
}

return (
<div className="room-container" key={Room.roomId} onClick={handleRoomClick(Room)}>
<div className="room-players">
{playerSlots}
</div>
<div className="room-header">
<div style={{ fontWeight: "bold" }}>{Room.roomName}</div>
<div>{Room.theme}</div>
<span
className={`room-status ${Room.status === "INGAME" ? "in-game" : Room.status === "WAITING" ? "waiting" : "game-over"}`}>
{Room.status}
</span>
</div>
</div>
</div>
));
)
});
};

if (user === null) {
Expand Down
10 changes: 7 additions & 3 deletions src/styles/views/Lobby.scss
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@
margin-left: 10px;
text-align: center;
.player-avatar {
width: 40px;
height: 40px;
width: 60.8px;
height: 60.8px;
border-radius: 50%;
background-color: #D9D9D9; // Default background color
}
Expand Down Expand Up @@ -233,14 +233,18 @@
}
}
.player {
background: rgba(217, 217, 217, 1);
border-radius: 20px;
width: 85px;
height: 85px;
&.container {
margin: 0.5em 0;
width: 20em;
padding: 10px;
border-radius: $borderRadius;
display: flex;
align-items: center;
background: lighten($background, 5);
background: gray;
}
&.status {
font-weight: 600;
Expand Down

0 comments on commit c873683

Please sign in to comment.