Skip to content

Commit

Permalink
feat(vil-610): can edit draft
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanJuz committed Oct 16, 2024
1 parent ec2cec5 commit 2c024ec
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 16 deletions.
10 changes: 6 additions & 4 deletions server/controllers/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ gameController.post({ path: '/standardGame', userType: UserType.TEACHER }, async
}

const data = req.body;
const { game1, game2, game3, userId, villageId, type, subType, selectedPhase, status, activityId } = data;
const { game1, game2, game3, userId, villageId, type, subType, selectedPhase, status, activityId, draftUrl } = data;

//save draft game each step
if (status && status === ActivityStatus.DRAFT) {
Expand All @@ -311,23 +311,23 @@ gameController.post({ path: '/standardGame', userType: UserType.TEACHER }, async
updateGameDraftIfExists(activityId, game1.data, game1.content);
return;
}
createGame(game1, userId, villageId, type, subType, selectedPhase, status);
createGame(game1, userId, villageId, type, subType, selectedPhase, status, draftUrl);
res.sendStatus(200);
return;
} else if (game2) {
if (activityId) {
updateGameDraftIfExists(activityId, game1.data, game1.content);
return;
}
createGame(game2, userId, villageId, type, subType, selectedPhase, status);
createGame(game2, userId, villageId, type, subType, selectedPhase, status, draftUrl);
res.sendStatus(200);
return;
} else if (game3) {
if (activityId) {
updateGameDraftIfExists(activityId, game1.data, game1.content);
return;
}
createGame(game3, userId, villageId, type, subType, selectedPhase, status);
createGame(game3, userId, villageId, type, subType, selectedPhase, status, draftUrl);
res.sendStatus(200);
return;
}
Expand All @@ -346,13 +346,15 @@ async function createGame(
subType: number,
selectedPhase: number,
status: number,
draftUrl: string,
) {
const activity = new Activity();
activity.type = type;
activity.subType = subType;
activity.status = status;
// TODO: Travailler sur le type de data
activity.data = data as unknown as AnyData;
activity.data.draftUrl = draftUrl;
activity.phase = selectedPhase;
activity.content = data;
activity.userId = userId;
Expand Down
11 changes: 5 additions & 6 deletions src/components/activities/ActivityCard/GameCard.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Button } from '@mui/material';

Check failure on line 1 in src/components/activities/ActivityCard/GameCard.tsx

View workflow job for this annotation

GitHub Actions / lint

There should be at least one empty line between import groups

Check failure on line 1 in src/components/activities/ActivityCard/GameCard.tsx

View workflow job for this annotation

GitHub Actions / lint

`@mui/material` import should occur after import of `react-player`
import Image from 'next/image';
import Link from 'next/link';
import router from 'next/router';
import React, { useState, useEffect } from 'react';
import ReactPlayer from 'react-player';

import { Button } from '@mui/material';

import { CommentIcon } from './CommentIcon';
import type { ActivityCardProps } from './activity-card.types';
import { useCountAllStandardGame } from 'src/api/game/game.getAllGames';
Expand Down Expand Up @@ -169,17 +168,17 @@ export const GameCard = ({ activity, isSelf, noButtons, isDraft, showEditButtons
<Link
href={
isDraft && activity.data.draftUrl
? `${activity.data.draftUrl}?activity-id=${activity.id}`
: `/creer-un-jeu/mimique/4?activity-id=${activity.id}`
? `${activity.data.draftUrl}?activity_id=${activity.id}`
: `/creer-un-jeu/mimique/4?activity_id=${activity.id}`
}
passHref
>
<Button
component="a"
href={
isDraft && activity.data.draftUrl
? `${activity.data.draftUrl}?activity-id=${activity.id}`
: `/creer-un-jeu/mimique/4?activity-id=${activity.id}`
? `${activity.data.draftUrl}?activity_id=${activity.id}`
: `/creer-un-jeu/mimique/4?activity_id=${activity.id}`
}
color="secondary"
variant="contained"
Expand Down
3 changes: 1 addition & 2 deletions src/contexts/activityContext.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Card, CircularProgress } from '@mui/material';

Check failure on line 1 in src/contexts/activityContext.tsx

View workflow job for this annotation

GitHub Actions / lint

There should be at least one empty line between import groups

Check failure on line 1 in src/contexts/activityContext.tsx

View workflow job for this annotation

GitHub Actions / lint

`@mui/material` import should occur after import of `react-query`
import { useRouter } from 'next/router';
import React from 'react';
import { useQueryClient } from 'react-query';

import { Card, CircularProgress } from '@mui/material';

import { UserContext } from './userContext';
import { VillageContext } from './villageContext';
import { Modal } from 'src/components/Modal';
Expand Down
3 changes: 1 addition & 2 deletions src/contexts/gameContext.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Card } from '@mui/material';

Check failure on line 1 in src/contexts/gameContext.tsx

View workflow job for this annotation

GitHub Actions / lint

There should be at least one empty line between import groups

Check failure on line 1 in src/contexts/gameContext.tsx

View workflow job for this annotation

GitHub Actions / lint

`@mui/material` import should occur after import of `react`
import type { ReactNode } from 'react';
import React, { createContext, useContext, useState } from 'react';
import { Card } from '@mui/material';

import { postGameDataMonneyOrExpression } from 'src/api/game/game.post';
import { GAME_FIELDS_CONFIG } from 'src/config/games/game';
import { primaryColor } from 'src/styles/variables.const';

import type { inputType, StepsTypes, GameDataMonneyOrExpression } from 'types/game.type';
import { GameType } from 'types/game.type';

Expand Down
1 change: 1 addition & 0 deletions src/pages/creer-un-jeu/mimique/1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const MimiqueStep1 = () => {
},
selectedPhase: selectedPhase,
status: ActivityStatus.DRAFT,
draftUrl: window.location.pathname,
};
saveDraftGrame(data);
router.push('/creer-un-jeu/mimique/2');
Expand Down
1 change: 1 addition & 0 deletions src/pages/creer-un-jeu/mimique/2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const MimiqueStep2 = () => {
},
selectedPhase: selectedPhase,
status: ActivityStatus.DRAFT,
draftUrl: window.location.pathname,
};
saveDraftGrame(data);
router.push('/creer-un-jeu/mimique/3');
Expand Down
1 change: 1 addition & 0 deletions src/pages/creer-un-jeu/mimique/3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const MimiqueStep3 = () => {
},
selectedPhase: selectedPhase,
status: ActivityStatus.DRAFT,
draftUrl: window.location.pathname,
};
saveDraftGrame(data);
router.push('/creer-un-jeu/mimique/4');
Expand Down
3 changes: 1 addition & 2 deletions src/pages/creer-un-jeu/mimique/4.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Button, Tooltip, Backdrop, CircularProgress } from '@mui/material';

Check failure on line 1 in src/pages/creer-un-jeu/mimique/4.tsx

View workflow job for this annotation

GitHub Actions / lint

There should be at least one empty line between import groups

Check failure on line 1 in src/pages/creer-un-jeu/mimique/4.tsx

View workflow job for this annotation

GitHub Actions / lint

`@mui/material` import should occur after import of `react`
import { useRouter } from 'next/router';
import React, { useContext } from 'react';

import { Button, Tooltip, Backdrop, CircularProgress } from '@mui/material';

import { postGameDataMonneyOrExpression } from 'src/api/game/game.post';
import { Base } from 'src/components/Base';
import { PageLayout } from 'src/components/PageLayout';
Expand Down
1 change: 1 addition & 0 deletions types/game.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export type GameDataMonneyOrExpression = {
game3?: GameDataStep;
selectedPhase: number;
status?: number;
draftUrl?: string;
};
export type DataForPlayed = {
game: StepsTypes;
Expand Down

0 comments on commit 2c024ec

Please sign in to comment.