add filtre chapitre
This commit is contained in:
@@ -39,6 +39,19 @@ const ListeCours = () => {
|
|||||||
const [searchQuery, setSearchQuery] = useState("");
|
const [searchQuery, setSearchQuery] = useState("");
|
||||||
const [assignmentQuery, setAssignmentQuery] = useState("");
|
const [assignmentQuery, setAssignmentQuery] = useState("");
|
||||||
const [showOnlyMedia, setShowOnlyMedia] = useState(false);
|
const [showOnlyMedia, setShowOnlyMedia] = useState(false);
|
||||||
|
const [selectedSection, setSelectedSection] = useState(null);
|
||||||
|
|
||||||
|
const sectionOptions = pages
|
||||||
|
.reduce((acc, page) => {
|
||||||
|
if (!acc.find((s) => s.section === page.section)) {
|
||||||
|
acc.push({
|
||||||
|
section: page.section,
|
||||||
|
label: page.sectionname || `Chapitre ${page.section}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}, []);
|
||||||
|
|
||||||
const [tabIndex, setTabIndex] = useState(0);
|
const [tabIndex, setTabIndex] = useState(0);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
@@ -174,7 +187,9 @@ const ListeCours = () => {
|
|||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.includes(searchQuery.toLowerCase());
|
.includes(searchQuery.toLowerCase());
|
||||||
const mediaMatch = showOnlyMedia ? pageHasMedia(page.content) : true;
|
const mediaMatch = showOnlyMedia ? pageHasMedia(page.content) : true;
|
||||||
return nameMatch && mediaMatch;
|
const sectionMatch =
|
||||||
|
selectedSection === null || page.section === selectedSection;
|
||||||
|
return nameMatch && mediaMatch && sectionMatch;
|
||||||
});
|
});
|
||||||
|
|
||||||
const filteredAssignments = assignments.filter((assign) =>
|
const filteredAssignments = assignments.filter((assign) =>
|
||||||
@@ -253,6 +268,21 @@ const ListeCours = () => {
|
|||||||
</Tabs>
|
</Tabs>
|
||||||
{tabIndex === 0 ? (
|
{tabIndex === 0 ? (
|
||||||
<>
|
<>
|
||||||
|
<Autocomplete
|
||||||
|
options={sectionOptions}
|
||||||
|
getOptionLabel={(option) => option.label}
|
||||||
|
onChange={(e, value) =>
|
||||||
|
setSelectedSection(value?.section ?? null)
|
||||||
|
}
|
||||||
|
renderInput={(params) => (
|
||||||
|
<TextField
|
||||||
|
{...params}
|
||||||
|
label="Filtrer par chapitre"
|
||||||
|
sx={{ mb: 2 }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
<Autocomplete
|
<Autocomplete
|
||||||
options={pages.map((p) => p.name)}
|
options={pages.map((p) => p.name)}
|
||||||
freeSolo
|
freeSolo
|
||||||
@@ -271,6 +301,12 @@ const ListeCours = () => {
|
|||||||
<>
|
<>
|
||||||
{paginatedPages.map((page) => (
|
{paginatedPages.map((page) => (
|
||||||
<Box key={page.id} sx={{ mb: 4 }}>
|
<Box key={page.id} sx={{ mb: 4 }}>
|
||||||
|
<Typography
|
||||||
|
variant="overline"
|
||||||
|
sx={{ fontWeight: "bold", color: "gray" }}
|
||||||
|
>
|
||||||
|
{page.sectionname || `Chapitre ${page.section}`}
|
||||||
|
</Typography>
|
||||||
<Typography variant="h6" sx={{ mb: 1 }}>
|
<Typography variant="h6" sx={{ mb: 1 }}>
|
||||||
{page.name}
|
{page.name}
|
||||||
</Typography>
|
</Typography>
|
||||||
@@ -301,7 +337,6 @@ const ListeCours = () => {
|
|||||||
>
|
>
|
||||||
Générer lien public
|
Générer lien public
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
</Box>
|
</Box>
|
||||||
<Divider sx={{ mt: 3 }} />
|
<Divider sx={{ mt: 3 }} />
|
||||||
</Box>
|
</Box>
|
||||||
@@ -336,11 +371,11 @@ const ListeCours = () => {
|
|||||||
{filteredAssignments.length > 0 ? (
|
{filteredAssignments.length > 0 ? (
|
||||||
filteredAssignments.map((assign) => (
|
filteredAssignments.map((assign) => (
|
||||||
<Box key={assign.id} sx={{ mb: 3 }}>
|
<Box key={assign.id} sx={{ mb: 3 }}>
|
||||||
|
<Typography variant="overline" sx={{ fontWeight: "bold", color: "gray" }}>
|
||||||
|
{assign.sectionname || `Chapitre ${assign.section}`}
|
||||||
|
</Typography>
|
||||||
<Typography variant="h6">{assign.name}</Typography>
|
<Typography variant="h6">{assign.name}</Typography>
|
||||||
<Typography
|
<Typography variant="body2" sx={{ mb: 1 }} />
|
||||||
variant="body2"
|
|
||||||
sx={{ mb: 1 }}
|
|
||||||
/>
|
|
||||||
<Button
|
<Button
|
||||||
size="small"
|
size="small"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
@@ -405,7 +440,7 @@ const ListeCours = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
<Box
|
<Box
|
||||||
sx={{margin: "0 auto", paddingBottom: 8 }}
|
sx={{ margin: "0 auto", paddingBottom: 8 }}
|
||||||
dangerouslySetInnerHTML={{
|
dangerouslySetInnerHTML={{
|
||||||
__html:
|
__html:
|
||||||
selectedPage?.content || selectedAssignment?.intro || "",
|
selectedPage?.content || selectedAssignment?.intro || "",
|
||||||
|
|||||||
Reference in New Issue
Block a user