diff --git a/src/App.jsx b/src/App.jsx index 444e24b9365d8e44049c63d77771837b0919c091..c5a22fb81711850b27279ef9842639c7ef5d1967 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -18,10 +18,9 @@ function App() { <Navbar /> <main className="flex-grow pt-4"> <Routes> - <Route path="/signin" element={<SignIn />} /> + <Route path="/" element={<SignIn />} /> <Route path="/signup" element={<SignUp />} /> - <Route path="/" element={<Home />} /> - <Route path="/todolist" element={<Todolist />} /> + <Route path="/home" element={<Home />} /> </Routes> </main> <Footer /> diff --git a/src/components/Navbar.jsx b/src/components/Navbar.jsx index 88094212419ca5638145c23fcc8c8e893bcd1f68..1f772b141df6c5198b0b65b5728e5b9dcc1809a9 100644 --- a/src/components/Navbar.jsx +++ b/src/components/Navbar.jsx @@ -26,7 +26,7 @@ const Navbar = () => { const handleLogout = () => { localStorage.removeItem("user"); setIsAuthenticated(false); - navigate("/signin"); + navigate("/"); }; return ( @@ -34,25 +34,24 @@ const Navbar = () => { <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"> <div className="flex justify-between h-16"> <div className="flex items-center"> - <Link to="/" className="flex items-center gap-2"> + <Link to="/home" className="flex items-center gap-2"> <CheckCircle className="h-8 w-8 text-violet-600 dark:text-violet-400" /> <span className="text-xl font-semibold text-gray-900 dark:text-white">TaskMaster</span> </Link> </div> <div className="flex items-center gap-6"> + {isAuthenticated ? ( <Link - to="/" + to="/home" className="text-gray-700 dark:text-white hover:text-violet-600 dark:hover:text-violet-400 px-3 py-2 rounded-md text-sm font-medium" > Dashboard - </Link> - <Link - to="/todolist" - className="text-gray-700 dark:text-white hover:text-violet-600 dark:hover:text-violet-400 px-3 py-2 rounded-md text-sm font-medium" - > - Tasks List - </Link> + </Link>) : (<p></p>)} + + + + {/* Bouton Light/Dark Mode */} <button onClick={toggleTheme} className="p-2 rounded-md bg-gray-200 dark:bg-gray-700"> @@ -72,7 +71,7 @@ const Navbar = () => { <> <Link - to="/signin" + to="/" className="text-gray-700 dark:text-white hover:text-violet-600 dark:hover:text-violet-400 px-3 py-2 rounded-md text-sm font-medium" > Login diff --git a/src/components/dashboard/TaskStats.jsx b/src/components/dashboard/TaskStats.jsx index f334de73fb6d1c77831a090e46d3247493ff77ec..5e345d5433dcc742b8d6098342e79c14ee7b1096 100644 --- a/src/components/dashboard/TaskStats.jsx +++ b/src/components/dashboard/TaskStats.jsx @@ -5,9 +5,10 @@ import { useTasks } from "@context/TasksContext"; const TaskStats = () => { const { tasks } = useTasks(); - const completed = tasks.filter(task => task.isCompleted).length; - const incompleted = tasks.filter(task => !task.isCompleted).length; - const total = tasks.length; + const currentUser = JSON.parse(localStorage.getItem("currentUser")); + const completed = tasks.filter(task => task.isCompleted && task.email == currentUser.email).length; + const incompleted = tasks.filter(task => !task.isCompleted && task.email == currentUser.email).length; + const total = tasks.filter(task => task.email == currentUser.email).length; return ( <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4"> diff --git a/src/components/dashboard/TasksStatPercent.jsx b/src/components/dashboard/TasksStatPercent.jsx index fbd1998f29dd39a4f3246e1af2412736b6c83c7c..1c933914db6efa27c029cb439f8694de013f2fb9 100644 --- a/src/components/dashboard/TasksStatPercent.jsx +++ b/src/components/dashboard/TasksStatPercent.jsx @@ -4,8 +4,10 @@ import { useTasks } from "@context/TasksContext"; const TasksStatPercent = () => { const { tasks } = useTasks(); - const totalTasks = tasks.length; - const completedTasks = tasks.filter(task => task.isCompleted).length; + const currentUser = JSON.parse(localStorage.getItem("currentUser")); + + const totalTasks = tasks.filter(task => task.email == currentUser.email).length; + const completedTasks = tasks.filter(task => task.isCompleted && task.email == currentUser.email).length; const radius = 50; const circumference = 2 * Math.PI * radius; diff --git a/src/components/todolist/Todolist.jsx b/src/components/todolist/Todolist.jsx index 50bfd20c02b5754e4d588106073898d9094b5989..a0f591ca6b8472c579b3f1c4d7beb8a378b9320d 100644 --- a/src/components/todolist/Todolist.jsx +++ b/src/components/todolist/Todolist.jsx @@ -8,7 +8,9 @@ export default function Todolist({ selectedDate=null }) { const { tasks, setTasks } = useTasks() const newTask = () => { + const currentUser = JSON.parse(localStorage.getItem("currentUser")); return { + email : currentUser.email, name: "", isCompleted: false, dueDate: new Date().toISOString().split("T")[0], @@ -57,7 +59,8 @@ export default function Todolist({ selectedDate=null }) { } const filteredTasks = selectedDate ? tasks.filter(task => { - if (!task.dueDate) return false; + const currentUser = JSON.parse(localStorage.getItem("currentUser")); + if (!task.dueDate || task.email != currentUser.email) return false; const taskDate = new Date(task.dueDate); return taskDate.toDateString() === selectedDate.toDateString(); }) : tasks; diff --git a/src/pages/SignIn.jsx b/src/pages/SignIn.jsx index e32929eda97f9725089f2e53a2c8459073b1e66b..740aed4ef0115f6f34c9d15b17d24d8e4cdf52b9 100644 --- a/src/pages/SignIn.jsx +++ b/src/pages/SignIn.jsx @@ -16,7 +16,7 @@ const SignIn = () => { if (result.success) { localStorage.setItem("user", JSON.stringify(result.user)); window.dispatchEvent(new Event("storage")); - navigate("/"); // Rediriger vers Home après connexion + navigate("/home"); // Rediriger vers Home après connexion } else { setError(result.message); } diff --git a/src/pages/SignUp.jsx b/src/pages/SignUp.jsx index 9f28cb2f5812143a068a0d342c9a22d18c082c82..f1b716e94b236be36a436bc1c735d17ec3210944 100644 --- a/src/pages/SignUp.jsx +++ b/src/pages/SignUp.jsx @@ -15,7 +15,7 @@ const SignUp = () => { const result = signUp(name, email, password); if (result.success) { - navigate("/signin"); // Rediriger vers Sign In après l'inscription + navigate("/"); // Rediriger vers Sign In après l'inscription } else { setError(result.message); } @@ -72,7 +72,7 @@ const SignUp = () => { <p className="mt-4 text-center text-sm text-gray-600 dark:text-gray-300"> Already have an account? - <Link to="/signin" className="text-blue-600 dark:text-blue-400 ml-1">Sign in</Link> + <Link to="/" className="text-blue-600 dark:text-blue-400 ml-1">Sign in</Link> </p> </div> </div>