Skip to content

Commit

Permalink
Further improvements on the "ready" functionality (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinejaussoin authored Oct 20, 2021
1 parent 99e581d commit 678739e
Show file tree
Hide file tree
Showing 21 changed files with 63 additions and 18 deletions.
2 changes: 2 additions & 0 deletions backend/src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,10 @@ export default (io: Server) => {
) => {
if (checkUser(userIds, socket)) {
const ready = await toggleReady(sessionId, userIds.userId);
const user = await getUser(userIds.userId);
sendToAll<WsUserReadyPayload>(socket, sessionId, RECEIVE_USER_READY, {
userId: userIds.userId,
name: user ? user.name : 'Somebody',
ready,
});
}
Expand Down
1 change: 1 addition & 0 deletions common/src/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface WsSaveTemplatePayload {
export interface WsUserReadyPayload {
userId: string;
ready: boolean;
name: string;
}

export type WsErrorType =
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/EditableLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const ViewMode = styled.span`
&:hover {
> svg {
color: ${colors.purple[500]};
cursor: pointer;
}
}
`;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/translations/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export default {
maxPostsReached: undefined,
iAmDone: undefined,
iAmNotDoneYet: undefined,
userIsReady: undefined,
},
GameMenu: {
board: undefined,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/translations/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export default {
maxPostsReached: undefined,
iAmDone: undefined,
iAmNotDoneYet: undefined,
userIsReady: undefined,
},
GameMenu: {
board: undefined,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export default {
maxPostsReached: `You have reached the maximum number of posts set by the moderator.`,
iAmDone: "I'm done!",
iAmNotDoneYet: "I'm not done yet...",
userIsReady: (user) => `${user} is ready!`,
},
GameMenu: {
board: 'Board',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/translations/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export default {
maxPostsReached: undefined,
iAmDone: undefined,
iAmNotDoneYet: undefined,
userIsReady: undefined,
},
GameMenu: {
board: undefined,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/translations/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export default {
maxPostsReached: `Vous avez atteint le nombre de posts maximum prévu par le modérateur.`,
iAmDone: "J'ai fini !",
iAmNotDoneYet: "Je n'ai pas encore fini...",
userIsReady: (user) => `${user} est prêt !`,
},
GameMenu: {
board: 'Board', // Si qqn à une suggestion de traduction...
Expand Down
1 change: 1 addition & 0 deletions frontend/src/translations/hu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export default {
maxPostsReached: undefined,
iAmDone: undefined,
iAmNotDoneYet: undefined,
userIsReady: undefined,
},
GameMenu: {
board: undefined,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/translations/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export default {
maxPostsReached: undefined,
iAmDone: undefined,
iAmNotDoneYet: undefined,
userIsReady: undefined,
},
GameMenu: {
board: 'Board',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/translations/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export default {
maxPostsReached: undefined,
iAmDone: undefined,
iAmNotDoneYet: undefined,
userIsReady: undefined,
},
GameMenu: {
board: undefined,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/translations/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export default {
maxPostsReached: undefined,
iAmDone: undefined,
iAmNotDoneYet: undefined,
userIsReady: undefined,
},
GameMenu: {
board: 'Bord',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/translations/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export default {
maxPostsReached: undefined,
iAmDone: undefined,
iAmNotDoneYet: undefined,
userIsReady: undefined,
},
GameMenu: {
board: undefined,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/translations/pt-br.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export default {
maxPostsReached: undefined,
iAmDone: undefined,
iAmNotDoneYet: undefined,
userIsReady: undefined,
},
GameMenu: {
board: undefined,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/translations/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export default {
maxPostsReached: undefined,
iAmDone: undefined,
iAmNotDoneYet: undefined,
userIsReady: undefined,
},
GameMenu: {
board: 'Записи',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/translations/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export interface Translation {
maxPostsReached?: string;
iAmDone?: string;
iAmNotDoneYet?: string;
userIsReady?: (userName: string) => string;
};
GameMenu: {
board?: string;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/translations/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export default {
maxPostsReached: undefined,
iAmDone: undefined,
iAmNotDoneYet: undefined,
userIsReady: undefined,
},
GameMenu: {
board: undefined,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/translations/zh-tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export default {
maxPostsReached: undefined,
iAmDone: undefined,
iAmNotDoneYet: undefined,
userIsReady: undefined,
},
GameMenu: {
board: undefined,
Expand Down
45 changes: 32 additions & 13 deletions frontend/src/views/game/Participants.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { Cancel, Check, CheckCircle } from '@mui/icons-material';
import { AvatarGroup, Badge, Button, colors } from '@mui/material';
import { Check, CheckCircle, Create } from '@mui/icons-material';
import {
AvatarGroup,
Badge,
Button,
colors,
IconButton,
useMediaQuery,
} from '@mui/material';
import CustomAvatar from '../../components/Avatar';
import useParticipants from './useParticipants';
import useSession from './useSession';
Expand All @@ -17,6 +24,7 @@ function Participants({ onReady }: ParticipantsProps) {
const user = useUser();
const { PostBoard: translations } = useTranslation();
const isUserReady = !!user && !!session && session.ready.includes(user.id);
const fullScreen = useMediaQuery('(min-width:600px)');
return (
<Container>
<AvatarGroup
Expand Down Expand Up @@ -46,19 +54,30 @@ function Participants({ onReady }: ParticipantsProps) {
);
})}
</AvatarGroup>
<Button
onClick={onReady}
variant="outlined"
endIcon={
isUserReady ? (
<Cancel htmlColor={colors.red[500]} />
{user && !fullScreen ? (
<IconButton onClick={onReady}>
{isUserReady ? (
<Create htmlColor={colors.orange[500]} />
) : (
<Check htmlColor={colors.green[500]} />
)
}
>
{isUserReady ? translations.iAmNotDoneYet : translations.iAmDone}
</Button>
)}
</IconButton>
) : null}
{user && fullScreen ? (
<Button
onClick={onReady}
variant="outlined"
endIcon={
isUserReady ? (
<Create htmlColor={colors.orange[500]} />
) : (
<Check htmlColor={colors.green[500]} />
)
}
>
{isUserReady ? translations.iAmNotDoneYet : translations.iAmDone}
</Button>
) : null}
</Container>
);
}
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/views/game/board/post/Post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,9 @@ const BlurOverlay = styled.div`
height: 100%;
background-color: rgba(255, 255, 255, 0.9);
z-index: 2;
@supports (backdrop-filter: blur(3px)) {
@supports (backdrop-filter: blur(3px)) or (-webkit-backdrop-filter: blur(3px)) {
background-color: rgba(255, 255, 255, 0.3);
-webkit-backdrop-filter: blur(3px);
backdrop-filter: blur(3px);
}
`;
Expand All @@ -422,7 +423,7 @@ const LabelContainer = styled.div<{ blurred: boolean }>`
content: '(hidden for now)';
}
@supports (backdrop-filter: blur(3px)) {
@supports (backdrop-filter: blur(3px)) or (-webkit-backdrop-filter: blur(3px)) {
> * {
display: block;
}
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/views/game/useGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,16 @@ const useGame = (sessionId: string) => {

socket.on(
Actions.RECEIVE_USER_READY,
({ userId, ready }: WsUserReadyPayload) => {
({ userId: readyUserId, ready, name }: WsUserReadyPayload) => {
if (debug) {
console.log('Receive user ready: ', userId);
console.log('Receive user ready: ', readyUserId);
}
userReady(readyUserId, ready);
if (userId !== readyUserId && ready) {
enqueueSnackbar(translations.PostBoard.userIsReady!(name), {
variant: 'success',
});
}
userReady(userId, ready);
}
);
}, [
Expand All @@ -405,6 +410,7 @@ const useGame = (sessionId: string) => {
enqueueSnackbar,
setUnauthorised,
userReady,
userId,
]);

const [previousParticipans, setPreviousParticipants] = useState(participants);
Expand Down

0 comments on commit 678739e

Please sign in to comment.