From 57c5321c09f5a457aeab954cf80b40312d3a23a3 Mon Sep 17 00:00:00 2001 From: NouhailaAater Date: Tue, 8 Apr 2025 19:34:27 -0400 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20de=20la=20page=20dashboard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/pages/Teacher/Dashboard/Dashboard.tsx | 338 ++++++++++++------ 1 file changed, 220 insertions(+), 118 deletions(-) diff --git a/client/src/pages/Teacher/Dashboard/Dashboard.tsx b/client/src/pages/Teacher/Dashboard/Dashboard.tsx index 3d4cc65..a5b4f33 100644 --- a/client/src/pages/Teacher/Dashboard/Dashboard.tsx +++ b/client/src/pages/Teacher/Dashboard/Dashboard.tsx @@ -38,7 +38,7 @@ import { Upload, FolderCopy, ContentCopy, - Edit, + Edit } from '@mui/icons-material'; import ShareQuizModal from 'src/components/ShareQuizModal/ShareQuizModal'; @@ -65,6 +65,7 @@ const Dashboard: React.FC = () => { const [selectedRoom, selectRoom] = useState(); // menu const [errorMessage, setErrorMessage] = useState(''); const [showErrorDialog, setShowErrorDialog] = useState(false); + const [isSearchVisible, setIsSearchVisible] = useState(false); // Filter quizzes based on search term // const filteredQuizzes = quizzes.filter(quiz => @@ -104,7 +105,7 @@ const Dashboard: React.FC = () => { fetchData(); }, []); - + useEffect(() => { if (rooms.length > 0 && !selectedRoom) { selectRoom(rooms[rooms.length - 1]); @@ -120,41 +121,44 @@ const Dashboard: React.FC = () => { } }; - // Créer une salle - const createRoom = async (title: string) => { - // Créer la salle et récupérer l'objet complet - const newRoom = await ApiService.createRoom(title); - - // Mettre à jour la liste des salles - const updatedRooms = await ApiService.getUserRooms(); - setRooms(updatedRooms as RoomType[]); - - // Sélectionner la nouvelle salle avec son ID - selectRoomByName(newRoom); // Utiliser l'ID de l'objet retourné - }; + const toggleSearchVisibility = () => { + setIsSearchVisible(!isSearchVisible); + }; + // Créer une salle + const createRoom = async (title: string) => { + // Créer la salle et récupérer l'objet complet + const newRoom = await ApiService.createRoom(title); - // Sélectionner une salle - const selectRoomByName = (roomId: string) => { - const room = rooms.find(r => r._id === roomId); - selectRoom(room); - localStorage.setItem('selectedRoomId', roomId); - }; + // Mettre à jour la liste des salles + const updatedRooms = await ApiService.getUserRooms(); + setRooms(updatedRooms as RoomType[]); - const handleCreateRoom = async () => { - if (newRoomTitle.trim()) { - try { + // Sélectionner la nouvelle salle avec son ID + selectRoomByName(newRoom); // Utiliser l'ID de l'objet retourné + }; + + // Sélectionner une salle + const selectRoomByName = (roomId: string) => { + const room = rooms.find((r) => r._id === roomId); + selectRoom(room); + localStorage.setItem('selectedRoomId', roomId); + }; + + const handleCreateRoom = async () => { + if (newRoomTitle.trim()) { + try { await createRoom(newRoomTitle); const userRooms = await ApiService.getUserRooms(); setRooms(userRooms as RoomType[]); - setOpenAddRoomDialog(false); - setNewRoomTitle(''); - } catch (error) { - setErrorMessage(error instanceof Error ? error.message : "Erreur inconnue"); - setShowErrorDialog(true); - } - } - }; + setOpenAddRoomDialog(false); + setNewRoomTitle(''); + } catch (error) { + setErrorMessage(error instanceof Error ? error.message : 'Erreur inconnue'); + setShowErrorDialog(true); + } + } + }; const handleSelectFolder = (event: React.ChangeEvent) => { setSelectedFolderId(event.target.value); @@ -397,35 +401,68 @@ const Dashboard: React.FC = () => { } else { const randomSixDigit = Math.floor(100000 + Math.random() * 900000); navigate(`/teacher/manage-room/${quiz._id}/${randomSixDigit}`); - } + } }; return (
-
Tableau de bord
+ {/* Conteneur pour le titre et le sélecteur de salle */} +
+ {/* Titre tableau de bord */} +
+ Tableau de bord +
-
- - handleSelectRoom(e)} + id="room-select" + style={{ + padding: '8px 12px', + fontSize: '14px', + borderRadius: '8px', + border: '1px solid #ccc', + backgroundColor: '#fff', + maxWidth: '200px', + cursor: 'pointer', + fontWeight: '500' + }} + > + - ))} - - - + {rooms.map((room) => ( + + ))} + + +
- {selectedRoom && ( -
-

Salle sélectionnée: {selectedRoom.title}

-
- )} - + {/* Dialog pour créer une salle */} setOpenAddRoomDialog(false)}> Créer une nouvelle salle @@ -450,24 +487,17 @@ const Dashboard: React.FC = () => { -
- - - - - - ) - }} - /> -
+
+ {/* Conteneur principal avec les actions et la liste des quiz */}
{ color="primary" value={selectedFolderId} onChange={handleSelectFolder} + sx={{ + padding: '6px 12px', + maxWidth: '180px', + borderRadius: '8px', + borderColor: '#e0e0e0', + '&:hover': { borderColor: '#5271FF' } + }} > - - - {folders.map((folder: FolderType) => ( + + {folders.map((folder) => ( ))} @@ -497,65 +532,130 @@ const Dashboard: React.FC = () => {
- - {' '} - {' '} - + + {' '} + {' '} +
- - {' '} - {' '} - + + {' '} + {' '} +
- - {' '} - {' '} - + + {' '} + {' '} +
-
- +
+
+ {!isSearchVisible ? ( + + + + ) : ( + + + + + + ) + }} + /> + )} +
- + {/* À droite : les boutons */} +
+ + + +
+
{Object.keys(quizzesByFolder).map((folderName) => ( @@ -571,7 +671,9 @@ const Dashboard: React.FC = () => { onClick={() => handleLancerQuiz(quiz)} disabled={!validateQuiz(quiz.content)} > - {`${quiz.title} (${quiz.content.length} question${ + {`${quiz.title} (${ + quiz.content.length + } question${ quiz.content.length > 1 ? 's' : '' })`} @@ -622,7 +724,7 @@ const Dashboard: React.FC = () => {
- +