generated from Real-Dev-Squad/website-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from saxenaaman628/mine
Completed Mine Task
- Loading branch information
Showing
3 changed files
with
52 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,54 @@ | ||
import { FC } from 'react'; | ||
import { FC, useState, useEffect } from 'react'; | ||
import Head from '@/components/head'; | ||
import Layout from '@/components/Layout'; | ||
import Card from '@/components/tasks/card'; | ||
import useFetch from '@/hooks/useFetch'; | ||
import classNames from '@/styles/tasks.module.scss'; | ||
import { task } from '@/components/constants/types'; | ||
|
||
const Mine: FC = () => ( | ||
<Layout> | ||
<Head title="Mine" /> | ||
</Layout> | ||
); | ||
const TASKS_URL = `${process.env.NEXT_PUBLIC_BASE_URL}/task/self`; | ||
|
||
function CardList(tasks: task[]) { | ||
return tasks.map( | ||
(item: task) => <Card content={item} key={item.id} />, | ||
); | ||
} | ||
|
||
const Mine: FC = () => { | ||
const [tasks, setTasks] = useState<task[]>([]); | ||
const { | ||
response, | ||
error, | ||
isLoading, | ||
} = useFetch(TASKS_URL); | ||
|
||
useEffect(() => { | ||
if ('tasks' in response) { setTasks(response.tasks); } | ||
}, [isLoading, response]); | ||
return ( | ||
<Layout> | ||
<Head title="Mine" /> | ||
<div className={classNames.container}> | ||
{!!error && <p>Something went wrong, please contact admin!</p>} | ||
{ | ||
isLoading | ||
? ( | ||
<p>Loading...</p> | ||
) : ( | ||
<> | ||
{ | ||
tasks.length > 0 | ||
? ( | ||
<div> | ||
{CardList(tasks)} | ||
</div> | ||
) : (!error && 'No Tasks Found') | ||
} | ||
</> | ||
) | ||
} | ||
</div> | ||
</Layout> | ||
); | ||
}; | ||
export default Mine; |