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

feat: (frontend) Using Context (<UserContext/>) for userInfo instead of passing userInfo as prop. #57

Open
SGI-CAPP-AT2 opened this issue Nov 24, 2024 · 3 comments

Comments

@SGI-CAPP-AT2
Copy link
Contributor

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 >
@chetansharma0706
Copy link

can you assign me this issue?

@its-me-abhishek
Copy link
Collaborator

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.

@SGI-CAPP-AT2
Copy link
Contributor Author

SGI-CAPP-AT2 commented Nov 25, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants