Skip to content

Commit

Permalink
Merge pull request #89 from saxenaaman628/mine
Browse files Browse the repository at this point in the history
Completed Mine Task
  • Loading branch information
whyDontI committed Apr 10, 2021
2 parents 22aa2d7 + 44a2aac commit a5dc91e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/components/Layout/index.tsx
Expand Up @@ -34,6 +34,8 @@ const Layout: FC<Props> = ({ children }) => (
<div className={styles.header}>
{navBarContent('Tasks', '/')}
|
{navBarContent('Mine', '/mine')}
|
{navBarContent('DS', '/challenges')}
|
{navBarContent('Open PRs', '/openPRs')}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/index.tsx
Expand Up @@ -52,7 +52,7 @@ const Index: FC = () => {
<Accordion open title={key} key={key}>
{renderCardList(filteredTask[key])}
</Accordion>
)) : 'No Tasks Found'
)) : (!error && 'No Tasks Found')
}
</>
)
Expand Down
55 changes: 49 additions & 6 deletions src/pages/mine.tsx
@@ -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;

0 comments on commit a5dc91e

Please sign in to comment.