Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
ToDoList
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IHM-WEB
ToDoList
Commits
e4b94c59
Commit
e4b94c59
authored
4 months ago
by
BENKORTBI Abdelhak
Browse files
Options
Downloads
Patches
Plain Diff
add a tasks list to home page + sync with calendar.
parent
d0d10a67
No related branches found
No related tags found
1 merge request
!15
add a tasks list to home page + sync with calendar.
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/components/Calendar.jsx
+47
-48
47 additions, 48 deletions
src/components/Calendar.jsx
src/components/Navbar.jsx
+7
-7
7 additions, 7 deletions
src/components/Navbar.jsx
src/pages/Home.jsx
+61
-24
61 additions, 24 deletions
src/pages/Home.jsx
src/pages/Todolist.jsx
+7
-2
7 additions, 2 deletions
src/pages/Todolist.jsx
with
122 additions
and
81 deletions
src/components/Calendar.jsx
+
47
−
48
View file @
e4b94c59
...
@@ -3,9 +3,8 @@ import { format, addMonths, subMonths, startOfMonth, endOfMonth, eachDayOfInterv
...
@@ -3,9 +3,8 @@ import { format, addMonths, subMonths, startOfMonth, endOfMonth, eachDayOfInterv
import
{
enUS
}
from
'
date-fns/locale
'
;
import
{
enUS
}
from
'
date-fns/locale
'
;
import
{
ChevronLeft
,
ChevronRight
}
from
'
lucide-react
'
;
import
{
ChevronLeft
,
ChevronRight
}
from
'
lucide-react
'
;
const
Calendar
=
()
=>
{
const
Calendar
=
(
{
selectedDate
,
setSelectedDate
}
)
=>
{
const
[
currentDate
,
setCurrentDate
]
=
useState
(
new
Date
());
const
[
currentDate
,
setCurrentDate
]
=
useState
(
new
Date
());
const
[
selectedDate
,
setSelectedDate
]
=
useState
(
new
Date
());
const
nextMonth
=
()
=>
setCurrentDate
(
addMonths
(
currentDate
,
1
));
const
nextMonth
=
()
=>
setCurrentDate
(
addMonths
(
currentDate
,
1
));
const
prevMonth
=
()
=>
setCurrentDate
(
subMonths
(
currentDate
,
1
));
const
prevMonth
=
()
=>
setCurrentDate
(
subMonths
(
currentDate
,
1
));
...
...
This diff is collapsed.
Click to expand it.
src/components/Navbar.jsx
+
7
−
7
View file @
e4b94c59
...
@@ -7,24 +7,24 @@ const Navbar = () => {
...
@@ -7,24 +7,24 @@ const Navbar = () => {
const
navigate
=
useNavigate
();
const
navigate
=
useNavigate
();
useEffect
(()
=>
{
useEffect
(()
=>
{
// Écouter les changements sur `localStorage`
const
handleStorageChange
=
()
=>
{
const
handleStorageChange
=
()
=>
{
setIsAuthenticated
(
!!
localStorage
.
getItem
(
"
user
"
));
setIsAuthenticated
(
!!
localStorage
.
getItem
(
"
user
"
));
};
};
// Ajouter un écouteur d'événement sur `storage`
window
.
addEventListener
(
"
storage
"
,
handleStorageChange
);
window
.
addEventListener
(
"
storage
"
,
handleStorageChange
);
return
()
=>
{
return
()
=>
{
// Nettoyer l'écouteur quand le composant est démonté
window
.
removeEventListener
(
"
storage
"
,
handleStorageChange
);
window
.
removeEventListener
(
"
storage
"
,
handleStorageChange
);
};
};
},
[]);
},
[]);
const
handleLogout
=
()
=>
{
const
handleLogout
=
()
=>
{
localStorage
.
removeItem
(
"
user
"
);
// Supprimer l'utilisateur
localStorage
.
removeItem
(
"
user
"
);
setIsAuthenticated
(
false
);
setIsAuthenticated
(
false
);
navigate
(
"
/signin
"
);
// Rediriger vers la page de connexion
navigate
(
"
/signin
"
);
};
};
return
(
return
(
...
@@ -53,7 +53,7 @@ const Navbar = () => {
...
@@ -53,7 +53,7 @@ const Navbar = () => {
</
Link
>
</
Link
>
<
div
className
=
"flex items-center gap-2"
>
<
div
className
=
"flex items-center gap-2"
>
{
isAuthenticated
?
(
{
isAuthenticated
?
(
// Bouton Logout si l'utilisateur est connecté
<
button
<
button
onClick
=
{
handleLogout
}
onClick
=
{
handleLogout
}
className
=
"bg-red-500 text-white hover:bg-red-600 px-4 py-2 rounded-md text-sm font-medium"
className
=
"bg-red-500 text-white hover:bg-red-600 px-4 py-2 rounded-md text-sm font-medium"
...
@@ -61,7 +61,7 @@ const Navbar = () => {
...
@@ -61,7 +61,7 @@ const Navbar = () => {
Logout
Logout
</
button
>
</
button
>
)
:
(
)
:
(
// Boutons Login & Signup si l'utilisateur N'EST PAS connecté
<>
<>
<
Link
<
Link
to
=
"/signin"
to
=
"/signin"
...
...
This diff is collapsed.
Click to expand it.
src/pages/Home.jsx
+
61
−
24
View file @
e4b94c59
import
React
from
"
react
"
;
import
React
,
{
useState
}
from
"
react
"
;
import
TaskStats
from
"
@components/dashboard/TaskStats
"
;
import
TaskStats
from
"
@components/dashboard/TaskStats
"
;
import
TasksStatPercent
from
"
@components/dashboard/TasksStatPercent.jsx
"
;
import
TasksStatPercent
from
"
@components/dashboard/TasksStatPercent.jsx
"
;
import
{
use
Navigate
}
from
"
react-router-dom
"
;
import
{
use
Tasks
}
from
"
@context/TasksContext
"
;
import
Calendar
from
"
@components/Calendar
"
;
import
Calendar
from
"
@components/Calendar
"
;
import
TaskList
from
"
@components/todolist/TaskList
"
;
import
AddTaskButton
from
"
@components/todolist/AddTaskButton
"
;
import
Modal
from
"
@components/todolist/Modal
"
;
const
Home
=
()
=>
{
const
Home
=
()
=>
{
const
navigate
=
useNavigate
();
const
{
tasks
,
setTasks
}
=
useTasks
();
const
[
selectedDate
,
setSelectedDate
]
=
useState
(
new
Date
());
const
[
isModalOpen
,
setIsModalOpen
]
=
useState
(
false
);
const
openModal
=
()
=>
setIsModalOpen
(
true
);
const
closeModal
=
()
=>
setIsModalOpen
(
false
);
// Fonction pour ajouter une nouvelle tâche
const
saveTask
=
(
task
)
=>
{
const
newTask
=
{
...
task
,
dueDate
:
task
.
dueDate
||
selectedDate
.
toISOString
().
split
(
"
T
"
)[
0
],
// Ajouter une dueDate par défaut
};
setTasks
([...
tasks
,
newTask
]);
};
// Filtrer les tâches en fonction de leur dueDate
const
filteredTasks
=
tasks
.
filter
(
task
=>
{
if
(
!
task
.
dueDate
)
return
false
;
// Vérifie si une tâche a bien une date
const
taskDate
=
new
Date
(
task
.
dueDate
);
// Convertir en objet Date
return
taskDate
.
toDateString
()
===
selectedDate
.
toDateString
();
// Comparer avec la date sélectionnée
});
return
(
return
(
<
div
>
<
div
>
<
div
className
=
"p-6 bg-gray"
>
<
div
className
=
"p-6 bg-gray"
>
...
@@ -13,27 +39,38 @@ const Home = () => {
...
@@ -13,27 +39,38 @@ const Home = () => {
<
div
className
=
"min-h-screen bg-gray-100 p-8"
>
<
div
className
=
"min-h-screen bg-gray-100 p-8"
>
<
div
className
=
"grid grid-cols-2 gap-6"
>
<
div
className
=
"grid grid-cols-2 gap-6"
>
<
div
className
=
"bg-white rounded-lg shadow-md p-6 min-h-[300px]"
>
<
div
className
=
"bg-white rounded-lg shadow-md p-6 min-h-[300px]"
>
<
h3
className
=
"text-lg font-semibold mb-4"
>
Tasks for
{
selectedDate
.
toDateString
()
}
</
h3
>
<
AddTaskButton
onClick
=
{
openModal
}
/>
{
filteredTasks
.
length
>
0
?
(
<
TaskList
tasks
=
{
filteredTasks
}
/>
)
:
(
<
p
className
=
"text-gray-500 mt-4"
>
No tasks for this day
</
p
>
)
}
</
div
>
</
div
>
<
div
className
=
"bg-white rounded-lg shadow-md p-6 min-h-[300px]"
>
<
div
className
=
"bg-white rounded-lg shadow-md p-6 min-h-[300px]"
>
<
Calendar
/>
<
Calendar
selectedDate
=
{
selectedDate
}
setSelectedDate
=
{
setSelectedDate
}
/>
</
div
>
</
div
>
<
div
className
=
"bg-white rounded-lg shadow-md p-6 min-h-[300px]"
>
<
div
className
=
"bg-white rounded-lg shadow-md p-6 min-h-[300px]"
>
</
div
>
</
div
>
<
div
className
=
"bg-white rounded-lg shadow-md p-6 min-h-[300px]"
>
<
div
className
=
"bg-white rounded-lg shadow-md p-6 min-h-[300px]"
>
<
TasksStatPercent
/>
<
TasksStatPercent
/>
</
div
>
</
div
>
</
div
>
</
div
>
</
div
>
</
div
>
<
Modal
isOpen
=
{
isModalOpen
}
closeModal
=
{
closeModal
}
saveTask
=
{
saveTask
}
/>
</
div
>
</
div
>
);
);
};
};
...
...
This diff is collapsed.
Click to expand it.
src/pages/Todolist.jsx
+
7
−
2
View file @
e4b94c59
...
@@ -7,8 +7,13 @@ import { useTasks } from "@context/TasksContext";
...
@@ -7,8 +7,13 @@ import { useTasks } from "@context/TasksContext";
export
default
function
Todolist
()
{
export
default
function
Todolist
()
{
const
{
tasks
,
setTasks
}
=
useTasks
()
const
{
tasks
,
setTasks
}
=
useTasks
()
const
saveTask
=
(
task
)
=>
{
const
saveTask
=
(
task
)
=>
{
setTasks
([...
tasks
,
task
])
const
newTask
=
{
}
...
task
,
dueDate
:
task
.
dueDate
||
new
Date
().
toISOString
().
split
(
"
T
"
)[
0
],
};
setTasks
([...
tasks
,
newTask
]);
};
const
[
isModalOpen
,
setIsModalOpen
]
=
useState
(
false
);
const
[
isModalOpen
,
setIsModalOpen
]
=
useState
(
false
);
const
openModal
=
()
=>
setIsModalOpen
(
true
);
const
openModal
=
()
=>
setIsModalOpen
(
true
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment