From ffdcd3eb67f422b69a3f0cddf7cb7b8b4e3c044f Mon Sep 17 00:00:00 2001 From: sonai99 Date: Sat, 22 Apr 2023 13:59:12 +0530 Subject: [PATCH] fixed issues/375 --- .env.development | 2 +- src/pages/mine.tsx | 41 +++++++++++++++++++++++------------------ 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/.env.development b/.env.development index ec7dc94e1..a59c70dc5 100644 --- a/.env.development +++ b/.env.development @@ -1,4 +1,4 @@ NEXT_PUBLIC_BASE_URL='https://staging-api.realdevsquad.com' NEXT_PUBLIC_GITHUB_IMAGE_URL='https://raw.githubusercontent.com/Real-Dev-Squad/website-static/main/members' -NEXT_PUBLIC_API_MOCKING='OFF' +NEXT_PUBLIC_API_MOCKING='ON' diff --git a/src/pages/mine.tsx b/src/pages/mine.tsx index e91faf365..f69c8ec30 100644 --- a/src/pages/mine.tsx +++ b/src/pages/mine.tsx @@ -9,31 +9,36 @@ import task from '@/interfaces/task.type'; import { LOGIN_URL, TASKS_URL } from '@/components/constants/url'; function CardList(tasks: task[]) { - return tasks.map((item: task) => ( + return tasks.map( + (item: task) => ( - )); -} + ) + ); + } + const Mine: FC = () => { const [tasks, setTasks] = useState([]); - const { response, error, isLoading, callAPI } = useFetch( - TASKS_URL, - {}, - false - ); + const { + response, + error, + isLoading, + callAPI + } = useFetch(TASKS_URL, {}, false); const { state } = useAppContext(); const { isLoading: isAuthenticating, isLoggedIn } = state; useEffect(() => { - if (isLoggedIn && !Object.keys(response).length) { + if (JSON.stringify(response) === "{}") { callAPI(); + } else { setTasks(response); - } - }, [isLoggedIn, response]); + } + }, [isLoggedIn, response]) return ( @@ -50,10 +55,10 @@ const Mine: FC = () => {

) : ( <> - {tasks.length > 0 ? ( -
{CardList(tasks)}
+ {response?.length > 0 ? ( +
{CardList(tasks)}
) : ( -

No Tasks Found

+

No Tasks Found

)} )