feat: (frontend) Using Context (`<UserContext/>`) for `userInfo` instead of passing `userInfo` as prop.
Module: frontend
Description: Currently userInfo is being passed to many children components under the <HomePage/> component. We can use Context for same to avoid prop drilling (if occurring anywhere now or in future)
also if we apply context on Router, It'll avoid Sign In on / (<LandingPage/>) even if user is signed in.
Snippet:
<div>
{userInfo ? (
<div>
<Navbar
imgurl={userInfo.picture}
email={userInfo.email}
encryptionSecret={userInfo.encryption_secret}
origin={url.containerOrigin}
UUID={userInfo.uuid}
/>
<motion.div
initial={{ x: -1000 }}
animate={{ x: 0 }}
transition={{ duration: 0.5, ease: "easeOut" }}
>
<Hero
name={userInfo.name}
uuid={userInfo.uuid}
encryption_secret={userInfo.encryption_secret}
/>
</motion.div>
<Tasks
email={userInfo.email}
encryptionSecret={userInfo.encryption_secret}
origin={url.containerOrigin}
UUID={userInfo.uuid}
/>
<SetupGuide
name={userInfo.name}
uuid={userInfo.uuid}
encryption_secret={userInfo.encryption_secret}
/>
<FAQ />
<Footer />
</div>
) : (<div>
<p>Session has been expired.</p>
<p>Please to go back to the
<a color="red" href={url.frontendURL}> home page </a>
and sign in again</p>
</div>
)}
</div >
can you assign me this issue?
i had thought to implement this earlier, but i think that since we are using only one layer (HomePage.tsx -> all the other components, the prop drilling should not be an issue), also, context hook would make all the elements re-render once anything gets updated.
also if we apply context on Router, It'll avoid Sign In on / (
) even if user is signed in.
we probably do not need this as some user might be running multiple instances of the UI for different taskwarrior cli clients (or accounts, in this case), and auto-login might be an issue.
context hook would make all the elements re-render once anything gets updated.
Yes, It may be a problem with context.
But What if we want to have a different route for tasks. For now the tasks operations ar being done on /homebut if we want to have task editor on a seperate page the router context will help.
Will surely consider this once we have to migrate to a separate view that requires more prop drilling. Thanks!