ccsync icon indicating copy to clipboard operation
ccsync copied to clipboard

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

Open SGI-CAPP-AT2 opened this issue 2 years ago • 4 comments

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 >

SGI-CAPP-AT2 avatar Nov 24 '24 04:11 SGI-CAPP-AT2

can you assign me this issue?

chetansharma0706 avatar Nov 24 '24 18:11 chetansharma0706

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.

its-me-abhishek avatar Nov 24 '24 18:11 its-me-abhishek

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.

SGI-CAPP-AT2 avatar Nov 25 '24 01:11 SGI-CAPP-AT2

Will surely consider this once we have to migrate to a separate view that requires more prop drilling. Thanks!

its-me-abhishek avatar Dec 06 '24 16:12 its-me-abhishek