Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed mine component issue #414

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/pages/mine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function CardList(tasks: task[]) {
);
}


const Mine: FC = () => {
const [tasks, setTasks] = useState<task[]>([]);
const {
Expand All @@ -32,12 +33,11 @@ const Mine: FC = () => {
const { state } = useAppContext();
const { isLoading: isAuthenticating, isLoggedIn } = state;
useEffect(() => {
if (isLoggedIn && !Object.keys(response).length) {
callAPI();
setTasks(response);
if (isLoggedIn) {
if (JSON.stringify(response) === "{}") callAPI();
if (JSON.stringify(response) !== "{}") setTasks(response);
Comment on lines +37 to +38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of 2 if's could we not add an if else block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for pointing it out, will do that.

}
}, [isLoggedIn, response])

return (
<Layout>
<Head title="Mine" />
Expand All @@ -51,11 +51,12 @@ const Mine: FC = () => {
<p>Something went wrong! Please contact admin</p>
) : (
<>
{tasks.length > 0 ? (
<div>{CardList(tasks)}</div>
) : (
<p>No Tasks Found</p>
)}
{
tasks.length > 0 && <div>{CardList(tasks)}</div>
}
{
response?.length == 0 && tasks.length == 0 && <p>No Tasks Found</p>
Comment on lines +55 to +58
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the code, this response object holds the tasks array right? so, if yes then why are we even checking the state (task state), why not a simple check of response.length > 0 ? {render tasks} : no tasks, do check if you can do this.

}
</>
)
) : (
Expand Down