From c651c5d1bb8e5c71141c382936c339046ba34f92 Mon Sep 17 00:00:00 2001 From: James Birnie Date: Wed, 2 Apr 2025 14:38:23 -0700 Subject: [PATCH] Got rid of reload on lock --- .../react-app/src/components/LockUnlockTask.jsx | 8 +++++--- frontend/react-app/src/pages/MyTasks.jsx | 13 +++++++++++-- frontend/react-app/src/pages/TeamTasks.jsx | 13 ++++++++++--- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/frontend/react-app/src/components/LockUnlockTask.jsx b/frontend/react-app/src/components/LockUnlockTask.jsx index af7ffa2..4a36a4b 100644 --- a/frontend/react-app/src/components/LockUnlockTask.jsx +++ b/frontend/react-app/src/components/LockUnlockTask.jsx @@ -3,7 +3,7 @@ import { lockTask, unlockTask } from '../api/adminApi'; import { Lock, LockOpen } from 'lucide-react'; import "../css/MyTasks.css"; -function LockUnlockTask({ initialIsLocked, taskId }) { +function LockUnlockTask({ initialIsLocked, taskId, updateLinkById }) { const [isLocked, setIsLocked] = useState(initialIsLocked); const handleLockUnlock = async () => { @@ -12,13 +12,15 @@ function LockUnlockTask({ initialIsLocked, taskId }) { const unlock = await unlockTask(taskId); if (unlock) { setIsLocked(false); - window.location.reload(); + updateLinkById(taskId, false) + //window.location.reload(); } } else { const lock = await lockTask(taskId); if (lock) { + updateLinkById(taskId, true) setIsLocked(true); - window.location.reload(); + //window.location.reload(); } } } catch (error) { diff --git a/frontend/react-app/src/pages/MyTasks.jsx b/frontend/react-app/src/pages/MyTasks.jsx index b30ffaa..c300d7a 100644 --- a/frontend/react-app/src/pages/MyTasks.jsx +++ b/frontend/react-app/src/pages/MyTasks.jsx @@ -57,6 +57,15 @@ function MyTasks(){ const [tasksToDo, setTasksToDo ] = useState([]); const [loading, setLoading] = useState(true); + const updateLinkById = (id, isLocked)=>{ + setTasksToDo(tasksToDo.map((task)=>{ + if(task.taskId === id){ + task.isLocked = isLocked; + } + return task + })) + } + async function fetchData(){ try{ const results = await getAssignedTasks(userId); @@ -75,7 +84,7 @@ useEffect(()=>{ console.log("Tasks To Do:", tasksToDo); -},[]); +},[tasksToDo]); @@ -122,7 +131,7 @@ const headerAndAccessors = [ Cell: (original) => { const isLocked = original.value; return isAdmin ? ( - + ) : ( isLocked ? '🔒' : '🔓' ); diff --git a/frontend/react-app/src/pages/TeamTasks.jsx b/frontend/react-app/src/pages/TeamTasks.jsx index 9f70a21..ac28d5d 100644 --- a/frontend/react-app/src/pages/TeamTasks.jsx +++ b/frontend/react-app/src/pages/TeamTasks.jsx @@ -122,13 +122,20 @@ function TeamTasks(){ setallUsersLoading(false) } } - + const updateLinkById = (id, isLocked)=>{ + setTasksToDo(tasksToDo.map((task)=>{ + if(task.taskId === id){ + task.isLocked = isLocked; + } + return task + })) +} useEffect(()=>{ fetchData(); console.log("Tasks To Do:", tasksToDo); - },[]); + },[tasksToDo]); const isAdmin = cookies.userInfo.role ==='admin'; const headerAndAccessors = [ @@ -147,7 +154,7 @@ function TeamTasks(){ Cell: (original) => { const isLocked = original.value; return isAdmin ? ( - + ) : ( isLocked ? '🔒' : '🔓' );