diff --git a/server/controllers/mediatheque.ts b/server/controllers/mediatheque.ts index a84d729e8..ad24e2a73 100644 --- a/server/controllers/mediatheque.ts +++ b/server/controllers/mediatheque.ts @@ -40,38 +40,7 @@ mediathequeController.post({ path: '' }, async (req: Request, res: Response) => }), ); }); - const activities = await subQueryBuilder.getMany(); - res.send(activities); - } catch (error) { - console.error('Error fetching media data:', error); - res.status(500).send({ error: 'Internal Server Error' }); - } -}); - -mediathequeController.post({ path: '/pelico' }, async (req: Request, res: Response) => { - try { - const filters: Array = req.body.filters || []; - - if (!Array.isArray(filters)) { - return res.status(400).send({ error: 'Invalid filters format' }); - } - - const subQueryBuilderUser = AppDataSource.getRepository(User) - .createQueryBuilder('user') - .where('user.type = :superAdmin', { superAdmin: 0 }) - .orWhere('user.type = :admin', { admin: 1 }) - .orWhere('user.type = :mediator', { mediator: 2 }); - - const users = await subQueryBuilderUser.getMany(); - - const usersId: number[] = users.map((user) => user.id); - - const subQueryBuilderActivity = AppDataSource.getRepository(Activity) - .createQueryBuilder('activity') - .where('activity.userId IN (:...usersId)', { usersId }); - - const activities = await subQueryBuilderActivity.getMany(); - + const activities = await subQueryBuilder.andWhere('activity.status = :status', { status: 0 }).getMany(); res.send(activities); } catch (error) { console.error('Error fetching media data:', error); diff --git a/src/components/admin/mediatheque/CardMediatheque.tsx b/src/components/admin/mediatheque/CardMediatheque.tsx index eeb37d9a3..7b89f3772 100644 --- a/src/components/admin/mediatheque/CardMediatheque.tsx +++ b/src/components/admin/mediatheque/CardMediatheque.tsx @@ -12,7 +12,6 @@ export default function MediaCard({ page }: { page: number }) { const { allFiltered } = useContext(MediathequeContext); const slicedData = allFiltered?.slice(page, page + 6); -console.log(slicedData) return (
diff --git a/src/contexts/mediathequeContext.tsx b/src/contexts/mediathequeContext.tsx index f2aa200ff..731224a36 100644 --- a/src/contexts/mediathequeContext.tsx +++ b/src/contexts/mediathequeContext.tsx @@ -31,46 +31,74 @@ export const MediathequeProvider: React.FC = ({ childr const [dataToUse, setDataToUse] = useState([]); useEffect(() => { - const activitiesMediaFinder = usersData?.map( - ({ - id, - content, - subType, - type, - villageId, - userId, - user, - village, - }: { - id: number; - content: object; - subType: number; - type: number; - villageId: number; - userId: number; - user: object; - village: object; - }) => { - const result = { id, subType, type, villageId, userId, content: [], user, village }; - if (content.game) { - content.game.map(({ inputs }) => - inputs.map((input: { type: number; selectedValue: string }) => { - if (input.type === 3 || input.type === 4) { - result.content.push({ type: input.type === 3 ? 'image' : 'video', value: input.selectedValue }); - } - }), - ); - } else { - content.map(({ type, value }: { type: string; value: string }) => { - const wantedTypes = ['image', 'video', 'sound']; - if (wantedTypes.includes(type)) { - result.content.push({ type, value }); + const activitiesMediaFinder = usersData + ?.filter(({ type }: { type: number }) => ![3, 5, 11].includes(type)) + .map( + ({ + id, + content, + subType, + type, + villageId, + userId, + user, + village, + data, + }: { + id: number; + content: object; + subType: number; + type: number; + villageId: number; + userId: number; + user: object; + village: object; + data: object; + }) => { + const result = { id, subType, type, villageId, userId, content: [], user, village }; + if (type === 8 || type === 12 || type === 13 || type === 14) { + if (type === 8) { + result.content.push({ type: 'image', value: data.mascotteImage }); + } + if (type === 12) { + result.content.push({ type: 'sound', value: data.verseFinalMixUrl }); + result.content.push({ type: 'sound', value: data.verseMixUrl }); + result.content.push({ type: 'sound', value: data.verseMixWithIntroUrl }); + result.content.push({ type: 'sound', value: data.verseMixWithVocalsUrl }); } - }); - } - return result; - }, - ); + if (type === 13 || type === 14) { + const properties = ['odd', 'object', 'place', 'tale']; + + properties.forEach((prop) => { + if (prop === 'tale') { + result.content.push({ type: 'image', value: data[prop].imageStory }); + } else { + result.content.push({ type: 'image', value: data[prop].imageUrl }); + } + }); + } + } + if (content.game) { + content.game.map(({ inputs }) => + inputs.map((input: { type: number; selectedValue: string }) => { + if (input.type === 3 || input.type === 4) { + result.content.push({ type: input.type === 3 ? 'image' : 'video', value: input.selectedValue }); + } + }), + ); + } else { + content.map(({ type, value }: { type: string; value: string }) => { + const wantedTypes = ['image', 'video', 'sound']; + if (wantedTypes.includes(type)) { + result.content.push({ type, value }); + } + }); + } + return result; + }, + ); + + console.log('activitiesMediaFinder', activitiesMediaFinder); const activitiesWithMediaOnly = activitiesMediaFinder?.filter((a) => a.content.length > 0); const activitiesFromPelico = activitiesWithMediaOnly?.filter((a) => [0, 1, 2].includes(a.user.type)); @@ -93,6 +121,8 @@ export const MediathequeProvider: React.FC = ({ childr [filters, dataToUse, useAdminData], ); + console.log('data to use = ', dataToUse); + return {children}; }; diff --git a/src/pages/admin/newportal/medialibrary/index.tsx b/src/pages/admin/newportal/medialibrary/index.tsx index db49e225f..76aa23b1f 100644 --- a/src/pages/admin/newportal/medialibrary/index.tsx +++ b/src/pages/admin/newportal/medialibrary/index.tsx @@ -35,9 +35,7 @@ const Mediatheque = () => { const { setFilters, allFiltered, setUseAdminData } = useContext(MediathequeContext); const [page, setPage] = useState(0); const [updateFiltersKey, setUpdateFiltersKey] = useState(0); - const [isChecked, setIsChecked] = useState(false); // État de la case à cocher - - // Explication : Dans React, lorsque la valeur de la clé (key) d'un composant change, React considère que ce composant est un composant différent de celui qui était rendu précédemment avec la même clé. En conséquence, React déclenche un rechargement complet du composant avec la nouvelle clé. + const [isChecked, setIsChecked] = useState(false); const handleResetFilters = () => { setUseAdminData(false);