Skip to content

Commit

Permalink
Merge pull request #991 from parlemonde/commentary-game
Browse files Browse the repository at this point in the history
Commentary game
  • Loading branch information
nathan7594 authored Oct 1, 2024
2 parents fc12d48 + 177af22 commit 93c384e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 35 deletions.
7 changes: 4 additions & 3 deletions src/api/game/game.getOneGameById.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useQuery } from 'react-query';

import { serializeToQueryUrl } from 'src/utils';
import { axiosRequest } from 'src/utils/axiosRequest';
// import { GameType } from 'types/game.type';

type Input = {
selectedValue: string;
Expand All @@ -22,7 +21,9 @@ type Data = {
radio: string;
};

type DataUse = {
export type DataUse = {
phase: number;
type: number;
content: Data;
createDate: string;
id: number;
Expand All @@ -35,7 +36,7 @@ type GetOneGameByIdProps = {
subType: number;
id: number;
};
// TODO : remove specific mimic management after mimic is standard

export async function getOneGameById({ subType, id }: GetOneGameByIdProps) {
const path = `/standardGame/${id}${serializeToQueryUrl({
subType,
Expand Down
3 changes: 2 additions & 1 deletion src/components/activities/ActivityComments/CommentCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react';

import { Box, Button, CircularProgress, Paper } from '@mui/material';

import type { DataUse } from 'src/api/game/game.getOneGameById';
import { AvatarImg } from 'src/components/Avatar';
import { Flag } from 'src/components/Flag';
import { UserDisplayName } from 'src/components/UserDisplayName';
Expand All @@ -21,7 +22,7 @@ import { UserType } from 'types/user.type';
const TextEditor = dynamic(() => import('src/components/activities/content/editors/TextEditor'), { ssr: false });

interface CommentCardProps {
activity: Activity<AnyData>;
activity: Activity<AnyData> | DataUse;
comment: Comment;
user: User | null;
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/activities/ActivityComments/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ActivityCard } from '../ActivityCard';
import StoriesDataCardView from '../ActivityView/StoriesDataCardView';
import { AddComment } from './AddComment';
import { CommentCard } from './CommentCard';
import type { DataUse } from 'src/api/game/game.getOneGameById';
import { AvatarImg } from 'src/components/Avatar';
import { UserContext } from 'src/contexts/userContext';
import { useActivities } from 'src/services/useActivities';
Expand All @@ -15,7 +16,7 @@ import type { User } from 'types/user.type';
import { UserType } from 'types/user.type';

interface ActivityCommentsProps {
activity: Activity<AnyData>;
activity: Activity<AnyData> | DataUse;
usersMap: { [key: number]: User };
}
export const ActivityComments = ({ activity, usersMap }: ActivityCommentsProps) => {
Expand Down
40 changes: 10 additions & 30 deletions src/components/game/DisplayGameById.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import Link from 'next/link';
import { useRouter } from 'next/router';
import React, { useState, useCallback, useMemo, useContext } from 'react';

// import AccessTimeIcon from '@mui/icons-material/AccessTime';
// import ShuffleIcon from '@mui/icons-material/Shuffle';
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
import { Box, Button, Grid } from '@mui/material';

import { KeepRatio } from '../KeepRatio';
import { ActivityComments } from '../activities/ActivityComments';
import { useOneGameById } from 'src/api/game/game.getOneGameById';
import { AvatarImg } from 'src/components/Avatar';
import { Base } from 'src/components/Base';
Expand All @@ -28,6 +27,7 @@ import PelicoNeutre from 'src/svg/pelico/pelico_neutre.svg';
import { GameType } from 'types/game.type';
import type { Game } from 'types/game.type';
import type { GameResponse } from 'types/gameResponse.type';
import type { User } from 'types/user.type';
import { UserType } from 'types/user.type';

function shuffleArray(size: number) {
Expand Down Expand Up @@ -129,6 +129,13 @@ const DisplayGameById = ({ subType }: SubTypeProps) => {
const gameId = parseInt(String(id));
const { data: getOneGameById } = useOneGameById(subType, gameId || 0);

const usersMap = React.useMemo(() => {
return users.reduce<{ [key: number]: User }>((acc, user) => {
acc[user.id] = user;
return acc;
}, {});
}, [users]);

const TYPE_OF_GAME = {
[GameType.MIMIC]: 'mimique',
[GameType.MONEY]: 'objet',
Expand Down Expand Up @@ -180,7 +187,6 @@ const DisplayGameById = ({ subType }: SubTypeProps) => {
};

const getNextGame = useCallback(async () => {
// [1] Reset game.
setFound(false);
setGameResponses([]);
setTryCount(0);
Expand Down Expand Up @@ -250,7 +256,6 @@ const DisplayGameById = ({ subType }: SubTypeProps) => {
inputs.map((input) => {
if (input.response || input.response === false) {
if (getOneGameById.subType === GameType.MONEY) {
// Utilisation des templates de chaînes de caractères
const significationWithEuro = `${input.selectedValue} ${euro}`;
responses.push({ isSuccess: input.response, signification: significationWithEuro, value: input.response ? 0 : fakeSignificationIndex });
} else {
Expand Down Expand Up @@ -287,14 +292,6 @@ const DisplayGameById = ({ subType }: SubTypeProps) => {

const choices = React.useMemo(() => (playContent.responses.length > 0 ? shuffleArray(playContent.responses.length) : []), [playContent.responses]);

// const handleRadioButtonChange = (event: React.SyntheticEvent) => {
// const selected = (event as React.ChangeEvent<HTMLInputElement>).target.value;
// setSelectedValue(selected as RadioBoxValues);
// if (selected === RadioBoxValues.RANDOM) {
// getNextGame();
// }
// };

const handleClick = useCallback(
async (selection: string, isSuccess: boolean = false) => {
if (playContent.responses.length === 0) {
Expand Down Expand Up @@ -377,21 +374,6 @@ const DisplayGameById = ({ subType }: SubTypeProps) => {
)}
</div>
</div>
<Grid container spacing={1} style={{ flex: 1, justifyContent: 'space-around' }}>
{/* <RadioGroup row defaultValue={RadioBoxValues.NEW}>
{Object.keys(radioListComponentMapper).map((value: string, index: number) => {
return (
<RadioNextGame
key={index}
value={value as RadioBoxValues}
Icon={radioListComponentMapper[value as RadioBoxValues]}
onChange={handleRadioButtonChange}
checked={selectedValue === value}
/>
);
})}
</RadioGroup> */}
</Grid>
<Grid
container
border={1}
Expand Down Expand Up @@ -447,7 +429,6 @@ const DisplayGameById = ({ subType }: SubTypeProps) => {
signification={signification}
disabled={isDisabled}
isCorrect={isCorrect || (tryCount > 1 && isSuccess)}
// mimicOrigine={mimicOrigine}
/>
</div>
);
Expand Down Expand Up @@ -484,7 +465,7 @@ const DisplayGameById = ({ subType }: SubTypeProps) => {
{found && <p>C’est exact ! Vous avez trouvé {displayPhrasesByType.phraseDelamodal}.</p>}
</Grid>
</Grid>
<Grid>{/* <ActivityComments activity={activityComment} usersMap={{}} /> */}</Grid>
<Grid>{getOneGameById ? <ActivityComments activity={getOneGameById} usersMap={usersMap} /> : null}</Grid>
</Box>
<Modal
open={errorModalOpen}
Expand Down Expand Up @@ -521,7 +502,6 @@ const DisplayGameById = ({ subType }: SubTypeProps) => {
</Grid>
<Grid item xs={3} display="flex" justifyContent="flex-end">
<Button variant="outlined" color="primary" onClick={getNextGame}>
{/* <Button variant="outlined" color="primary"> */}
Jeu suivant
</Button>
</Grid>
Expand Down

0 comments on commit 93c384e

Please sign in to comment.