Skip to content

Commit

Permalink
voila
Browse files Browse the repository at this point in the history
  • Loading branch information
Neo-Ryo committed May 31, 2024
1 parent a48078e commit 1a521d1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/pages/activite/[id].tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Link from 'next/link';
import { useRouter } from 'next/router';
import React from 'react';
import React, { useContext } from 'react';

import ChevronRightIcon from '@mui/icons-material/ChevronRight';

Expand All @@ -10,6 +10,7 @@ import { RightNavigation } from 'src/components/accueil/RightNavigation';
import { ActivityComments } from 'src/components/activities/ActivityComments';
import { ActivityView } from 'src/components/activities/ActivityView';
import { UserContext } from 'src/contexts/userContext';
import { VillageContext } from 'src/contexts/villageContext';
import { useActivity } from 'src/services/useActivity';
import { useVillageUsers } from 'src/services/useVillageUsers';
import HomeIcon from 'src/svg/navigation/home-icon.svg';
Expand All @@ -35,13 +36,20 @@ const titles: Record<number, (activity: ActivityInterface<AnyData>) => string> =
};

const Activity = () => {
const { village } = useContext(VillageContext);
const router = useRouter();
const activityId = React.useMemo(() => parseInt(getQueryString(router.query.id), 10) ?? null, [router]);
const { user } = React.useContext(UserContext);
const { activity } = useActivity(activityId);
const { users } = useVillageUsers();
const isAnswer = activity && isEnigme(activity) && 'reponse' in router.query;

React.useEffect(() => {
if (activity && village && activity?.villageId !== village?.id) {
router.push('/');
}
}, [village, activity, router]);

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

0 comments on commit 1a521d1

Please sign in to comment.