frankcollins3 / Next-Water-App

Happy, Healthy Water Cycling App that tracks user/human fluid intake.
https://next-water-app.vercel.app
1 stars 0 forks source link

else block, based on imgSrc isn't working [4:43pm] #107

Closed frankcollins3 closed 11 months ago

frankcollins3 commented 11 months ago

attempting to do: poor man's logout based exclusively on cookies (while login uses Oauth2.0)

error: for this code:

    const loginLogout = (event:any) => {
        const imgSrc:string = event.target.src
        console.log('imgSrc', imgSrc)
        if (imgSrc.includes(NON_GOOGLE_IMG_URL)) {
          console.log('i like cookies')
          const getCookiePROMISE = new Promise((cookies:any, milk:any) => {
            if (document.cookie) {
                const webcookies = document.cookie.split('; ');
                // console.log('webcookies', webcookies)
                cookies(webcookies)
                milk('spill')
            }
        })
        getCookiePROMISE
        .then( (cookies:any) => {
          console.log('cookies', cookies)          
          for (let i = 0; i < cookies.length; i++) {
            // MwordBeforeEqualsForCookies
            let match;
            while ((match = MwordBeforeEqualsForCookies.exec(cookies[i]))) {
              console.log('heres the cookies', match[1]);
              let regexName:any = match[1]
              clearCookie(regexName)
              dispatch(SET_NON_GOOGLE_IMG_URL(''))
            }
          }
        })
        **} else if(imgSrc === exit) {**
          console.log("no cookies no logout!!")
          window.location.href = "/logInOutGoogle"
        }
    }

that function is based on this UI which is leads to login/signup if no userCookies, and is the profile icon if signed in. it's also the logout button.

<img onClick={loginLogout} id="loginLogoutIcon" src={ NON_GOOGLE_IMG_URL ? NON_GOOGLE_IMG_URL : exit}/>

proposed approach: separate concerns of the else if block not running. ternary to render different functions

frankcollins3 commented 11 months ago

first proposed approach including conditionally declaring which function would be run in the onClick prop but wondering how to get imgSrc if that context is declared in the other element prop.

onClick={leftIconClick}

new approach: { <img onClick={login} src={exit} <img onClick={logout} src={NON_GOOGLE_IMG_URL }

frankcollins3 commented 11 months ago

onClick={NON_GOOGLE_IMG_URL ? logout : login}

this would've also worked. {

} [5:03pm]