brunorplima / divino-dog-menu-app

Automated menu and order app for Divino Dog
divino-dog-menu-app.vercel.app
0 stars 0 forks source link

singleItem checkbox fixed #162

Closed ericbraz closed 1 year ago

ericbraz commented 1 year ago

Resolves #155

Besides the problem related in the isseu 155 I also realized that whenever we would reload and item page it would display the message as if that item was unavailable. To fix this I created a state to know if it was the first time the useEffect in which we check if the item is available ran. This state variable is placed in line 150 as follow:

const [isUseEffectSecondLoad, setIsUseEffectSecondLoad] = useState(false)

From line 154 to 158 is where the useEffect runs as follow:

useEffect(() => {
      setButtonState(defineButtonState(addOns))
      isUseEffectSecondLoad && !theItem?.isAvailable && setDialog(true)
      !isUseEffectSecondLoad && setIsUseEffectSecondLoad(true)
   }, [addOns, theItem])

This avoid the unavailable message right after the page is loaded and is only displayed when the item is indeed unavailable.

vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
divino-dog-menu-app ✅ Ready (Inspect) Visit Preview Jun 17, 2023 10:08pm