Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[M4] fix the bug token issue and add different ui for the current user #165

Merged
merged 4 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/components/views/Gameroom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,17 @@ const Gameroom = () => {
console.log("[onResponseReceived] receiptId",msg.receiptId)
console.log("[onResponseReceived] reqList:",requestLists.current)

// Check if the message indicates an invalid or expired token
if (msg.auth === false) {
showToast("Invalid or expired token, please login again!", "error");
sessionStorage.clear(); // Clear session storage
navigate("/login"); // Navigate to the login page

return; // Exit the function to avoid further processing
}

const index = requestLists.current.findIndex(item => item.receiptId === msg.receiptId);
if (index !== INDEX_NOT_FOUND) {
// Check if the message indicates an invalid or expired token
if (msg.auth === false) {
showToast("Invalid or expired token, please login again!", "error");
sessionStorage.clear(); // Clear session storage
navigate("/login"); // Navigate to the login page

return; // Exit the function to avoid further processing
}

const messageType = requestLists.current[index].type;
const success = msg.success;
let toastMessage;
Expand Down Expand Up @@ -700,6 +700,7 @@ const Gameroom = () => {
<BaseContainer className="gameroom basecontainer">
{/* <Header left="28vw" /> */}
<PlayerList
currentPlayerId={user.id}
playerStatus={playerLists}
sharedAudioList={sharedAudioList}
gameTheme={gameTheme.current}
Expand Down
29 changes: 20 additions & 9 deletions src/components/views/GameroomPlayerList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ type PlayerListProps = {
showReadyPopup: boolean;
gameOver: boolean;
globalVolume: number;
currentPlayerId: string;
}

export const PlayerList = (props:PlayerListProps) => {
const { playerStatus, sharedAudioList, gameTheme, currentRoomName, showReadyPopup, gameOver, globalVolume } = props;
const { playerStatus, sharedAudioList, gameTheme, currentRoomName, showReadyPopup, gameOver, globalVolume,currentPlayerId } = props;

return (
<div className="gameroom left-area">
Expand All @@ -47,9 +48,11 @@ export const PlayerList = (props:PlayerListProps) => {
if (hasRecording) {
_audioURL = sharedAudioList[playerInfo.user.id];
}
const currentUserName= (playerInfo.user.id === currentPlayerId) ? "(You)" : "";
const currentUserBgColor = (playerInfo.user.id === currentPlayerId) ? "rgb(255, 233, 158)" : "rgba(255, 243, 207, 1)";

return (
<div className="gameroom singlePlayerContainer" key={index}>
<div className="gameroom singlePlayerContainer" style={{ background: `${currentUserBgColor}` }} key={index}>
<span className="gameroom playerAvatar">
<i
className={"twa twa-" + playerInfo.user.avatar}
Expand All @@ -59,9 +62,12 @@ export const PlayerList = (props:PlayerListProps) => {
{!showReadyPopup && !gameOver && (
<>
<div className="gameroom secondcolumn">
<span className="gameroom playerName">
{playerInfo.user.name}
</span>
<div style={{display:"flex",flexDirection:"row"}}>
<span className="gameroom playerName">
{playerInfo.user.name}
</span>
<span style={{marginLeft:"0.5rem"}}>{currentUserName}</span>
</div>
<span className="gameroom secondRow">
<span className="gameroom scoreTitle">Score:</span>
<span className="gameroom playerScore">
Expand Down Expand Up @@ -93,9 +99,12 @@ export const PlayerList = (props:PlayerListProps) => {
{gameOver && (
<>
<div className="gameroom secondcolumn">
<span className="gameroom playerName">
{playerInfo.user.name}
</span>
<div style={{display:"flex",flexDirection:"row"}}>
<span className="gameroom playerName">
{playerInfo.user.name}
</span>
<span style={{marginLeft:"0.5rem"}}>{currentUserName}</span>
</div>
<span className="gameroom secondRow">
<span className="gameroom scoreTitle">Score:</span>
<span className="gameroom playerScore">
Expand All @@ -111,7 +120,9 @@ export const PlayerList = (props:PlayerListProps) => {
<span className="gameroom playerName">
{playerInfo.user.name}
</span>
<span className="gameroom secondRow"></span>
<span className="gameroom secondRow">
<span>{currentUserName}</span>
</span>
</div>
<div className="gameroom playerStatus">
{playerInfo.ready ? (
Expand Down
2 changes: 2 additions & 0 deletions src/components/views/RuleGuide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import "../../styles/views/RuleGuide.scss";
import { showToast} from "../../helpers/toastService";

const mockGameTheme = "FOOD";
const mockCurrentPlayer = "id1";
const mockRoomName = "GuideRoom";
const mockGlobalVolume = 0.5;
const MS_PER_SEC = 1000;
Expand Down Expand Up @@ -139,6 +140,7 @@ const RuleGuide = () => {
<BaseContainer className="gameroom basecontainer">
{/* <Header left="28vw" /> */}
<PlayerList
currentPlayerId={mockCurrentPlayer}
playerStatus={playerInfo}
sharedAudioList={mockSharedAudioList}
gameTheme={mockGameTheme}
Expand Down
Loading