Skip to content

Commit

Permalink
Feature/Filtre activités et thèmes/VIL11-VIL112
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-pages committed Apr 9, 2024
1 parent f7c42d3 commit 27379df
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/components/admin/mediatheque/Filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type FilterProps = {
placeholder: string;
};

const FilterMultipleChoice = ({ labels, placeholder }: FilterProps) => {
const Filters = ({ labels, placeholder }: FilterProps) => {
const theme = useTheme();
const [labelName, setLabelName] = React.useState<string[]>([]);

Expand Down Expand Up @@ -74,4 +74,4 @@ const FilterMultipleChoice = ({ labels, placeholder }: FilterProps) => {
);
};

export default FilterMultipleChoice;
export default Filters;
120 changes: 120 additions & 0 deletions src/components/admin/mediatheque/FiltersActivities.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/* eslint-disable prettier/prettier */
import React from 'react';

import FormControl from '@mui/material/FormControl';
import MenuItem from '@mui/material/MenuItem';
import OutlinedInput from '@mui/material/OutlinedInput';
import type { SelectChangeEvent } from '@mui/material/Select';
import Select from '@mui/material/Select';
import { useTheme } from '@mui/material/styles';
import type { Theme } from '@mui/material/styles';

import {
activitiesLabel,
themeOfDefi,
themeOfEnigme,
themeOfIndiceCulturel,
themeOfIndiceSymbolique,
themeOfJeux,
} from 'src/config/mediatheque/dataFilters';

const ITEM_HEIGHT = 48;
const ITEM_PADDING_TOP = 8;
const MenuProps = {
PaperProps: {
style: {
maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP,
width: 250,
},
},
};

function getStyles(label: string, labelName: readonly string[], theme: Theme) {
return {
fontWeight: labelName.indexOf(label) === -1 ? theme.typography.fontWeightRegular : theme.typography.fontWeightMedium,
};
}

const subThemesMap: { [key: string]: string[] } = {
'Indice culturel': themeOfIndiceCulturel,
'Indice symbolique': themeOfIndiceSymbolique,
'Défis': themeOfDefi,
'Jeux': themeOfJeux,
'Enigme': themeOfEnigme,
};

export default function FiltersActivities() {
const theme = useTheme();
const [labelNameActivity, setLabelNameActivity] = React.useState<string[]>([]);
const [labelNameSubTheme, setLabelNameSubTheme] = React.useState<string[]>([]);

const handleChangeLabelActivity = (event: SelectChangeEvent<typeof labelNameActivity>) => {
const {
target: { value },
} = event;
setLabelNameActivity(typeof value === 'string' ? value.split(',') : value);
setLabelNameSubTheme([]);
};

const subThemes = labelNameActivity.map((activity) => subThemesMap[activity] || []).flat();

return (
<>
<div>
{/* Filtre pour activités */}
<FormControl sx={{ m: 1, width: 140 }} size="small">
<Select
multiple
displayEmpty
value={labelNameActivity}
onChange={handleChangeLabelActivity}
input={<OutlinedInput />}
renderValue={(selected) => {
if (selected.length === 0) {
return <em>Activités</em>;
}
return selected.join(', ');
}}
MenuProps={MenuProps}
inputProps={{ 'aria-label': 'Label' }}
>
{activitiesLabel.map((label: string, index: number) => (
<MenuItem key={index} value={label} style={getStyles(label, labelNameActivity, theme)}>
{label}
</MenuItem>
))}
</Select>
</FormControl>
</div>
{/* Filtres pour sous thème d'une activité */}
<div>
<FormControl sx={{ m: 1, width: 140 }} size="small">
<Select
multiple
displayEmpty
value={labelNameSubTheme}
onChange={(event) => setLabelNameSubTheme(event.target.value as string[])}
input={<OutlinedInput />}
renderValue={(selected) => {
if (selected.length === 0) {
return <em>Thèmes</em>;
}
return selected.join(', ');
}}
MenuProps={MenuProps}
inputProps={{ 'aria-label': 'Label' }}
>
<MenuItem disabled value="">
<em>{subThemes.length ? 'Thèmes' : 'Pas de thématiques'}</em>
</MenuItem>
{subThemes.map((label: string, index: number) => (
<MenuItem key={index} value={label} style={getStyles(label, labelNameSubTheme, theme)}>
{label}
</MenuItem>
))}
</Select>
</FormControl>
</div>
</>
);
}
12 changes: 6 additions & 6 deletions src/components/admin/mediatheque/ModalFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import Button from '@mui/material/Button';
import IconButton from '@mui/material/IconButton';
import Modal from '@mui/material/Modal';

import FiltersActivities from './FiltersActivities';
import CheckboxAdmin from 'src/components/admin/mediatheque/CheckboxAdmin';
import FilterMultipleChoice from 'src/components/admin/mediatheque/Filter';
import Filters from 'src/components/admin/mediatheque/Filter';
import { activitiesLabel } from 'src/config/mediatheque/dataFilters';

const styleModal = {
Expand All @@ -33,11 +34,10 @@ const ModalFilter = () => {
<Button onClick={handleOpen}>Filtres</Button>
<Modal open={open} onClose={handleClose} aria-labelledby="modal-modal-title" aria-describedby="modal-modal-description">
<Box sx={styleModal}>
<FilterMultipleChoice labels={activitiesLabel} placeholder="Activités" />
<FilterMultipleChoice labels={activitiesLabel} placeholder="Thèmes" />
<FilterMultipleChoice labels={activitiesLabel} placeholder="VM" />
<FilterMultipleChoice labels={activitiesLabel} placeholder="Pays" />
<FilterMultipleChoice labels={activitiesLabel} placeholder="Classes" />
<FiltersActivities />
<Filters labels={activitiesLabel} placeholder="VM" />
<Filters labels={activitiesLabel} placeholder="Pays" />
<Filters labels={activitiesLabel} placeholder="Classes" />
<div style={{ display: 'flex', justifyContent: 'center' }}>
<CheckboxAdmin />
<IconButton aria-label="delete" color="primary">
Expand Down
50 changes: 39 additions & 11 deletions src/config/mediatheque/dataFilters.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,45 @@
export const activitiesLabel = [
'Présentation',
'Enigme',
'Défi',
'Question',
'Jeux',
'Contenu libre',
'Indice',
'Symbole',
'Indice culturel',
'Indice symbolique',
'Mascotte',
'Reportage',
'Reaction',
'Défis',
'Jeux',
'Symbole',
'Réaction',
'Enigme',
'Hymne',
'Couplet ?',
'Histoire',
'Couplet',
'Inventer une histoire',
'Réinventer une histoire',
];

export const themeOfIndiceCulturel = [
'Paysages',
'Arts',
'Lieux de vies',
'Langues',
'Flore et faune',
'Loisirs et jeux',
'Cuisines',
'Traditions',
'Autre',
];

export const themeOfIndiceSymbolique = [
'Drapeau',
'Emblème',
'Fleur nationale',
'Devise',
'Hymne',
'Animal national',
'Figure symbolique',
'Monnaie',
'Autre',
];

export const themeOfDefi = ['Culinaire', 'Linguistique', 'Ecologique', 'Autre'];

export const themeOfJeux = ['Jeu des expressions', 'Jeu de la monnaie', 'Jeu des expressions'];

export const themeOfEnigme = ['Evement mystère', 'Lieu mystère', 'Objet mystère', 'Personnalité mystère', 'autre'];
28 changes: 22 additions & 6 deletions src/pages/admin/newportal/medialibrary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import IconButton from '@mui/material/IconButton';

import { useGetMediatheque } from 'src/api/mediatheque/mediatheque.get';
import CheckboxAdmin from 'src/components/admin/mediatheque/CheckboxAdmin';
import FilterMultipleChoice from 'src/components/admin/mediatheque/Filter';
import Filters from 'src/components/admin/mediatheque/Filter';
import FiltersActivities from 'src/components/admin/mediatheque/FiltersActivities';
import ModalFilter from 'src/components/admin/mediatheque/ModalFilter';
import { activitiesLabel } from 'src/config/mediatheque/dataFilters';
import type { Filter } from 'types/mediatheque.type';
Expand All @@ -40,11 +41,26 @@ const Mediatheque = () => {
<h1 className="title-for-mediatheque">Médiathèque d&apos;1Village</h1>
<div className="desktop-view">
<div style={{ display: 'flex' }}>
<FilterMultipleChoice labels={activitiesLabel} placeholder="Activités" />
<FilterMultipleChoice labels={activitiesLabel} placeholder="Thèmes" />
<FilterMultipleChoice labels={activitiesLabel} placeholder="VM" />
<FilterMultipleChoice labels={activitiesLabel} placeholder="Pays" />
<FilterMultipleChoice labels={activitiesLabel} placeholder="Classes" />
{/* Ici je me dis que je peux gérer un composant
filtre qui s'appellerait FiltersActivities */}
<>
{/* Ce filtre gère les activités principales */}
{/* <Filters labels={activitiesLabel} placeholder="Activités" /> */}
{/* Ce filtre dépend de l'acitivité principales choisies */}
{/* <Filters labels={activitiesLabel} placeholder="Thèmes" /> */}
</>
<FiltersActivities />
{/* Et ici un second composant qui s'appellerait
FiltersUsers */}
<>
{/* Ce filtre gère les différents village monde */}
<Filters labels={activitiesLabel} placeholder="VM" />
{/* Ce filtre dépend du village monde choisi */}
<Filters labels={activitiesLabel} placeholder="Pays" />
{/* Ce filtre dépend du pays choisi et du village monde */}
<Filters labels={activitiesLabel} placeholder="Classes" />
</>

<CheckboxAdmin />
<IconButton aria-label="delete" color="primary">
<RefreshIcon />
Expand Down

0 comments on commit 27379df

Please sign in to comment.