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

state resets incorrectly for water cycle update. [1:14pm] #93

Closed frankcollins3 closed 11 months ago

frankcollins3 commented 11 months ago

attempting to do: update water cycling as Y|N with every click.

error: the yes updates one time correctly and continues to update to be 20

      const setStatePROMISE = new Promise(async(resolve:any, reject:any) => {
        let value = percentageCount + percentage
        await setPercentageCount(value)
        await resolve(percentageCount)
        reject('no percentage')
      })
      setStatePROMISE
      .then( (percentState:any) => {
        console.log('percentState', percentState)
        dispatch(SET_PROGRESS(percentageCount))
      })

proposed approach: 0: SET_PROGRESS is redux state... first approach creates localState to separate concerns. also created a promise in hopes of having more async ability.

frankcollins3 commented 11 months ago

@redux/toolkit

PROGRESS: 0 process in the click 000

it appears to be a float representing 3 zeros ? PROGRESS:number is typed as a number of 0 but upon client log the value is 000.

wonder if this is a bytes issue or other.

also changed PROGRESS = action.payload to be an incrementer: SET_PROGRESS: (state, action) => { state.PROGRESS = state.PROGRESS += action.payload},

[1:26pm]

frankcollins3 commented 11 months ago

kept the state like this typed -> PROGRESS:any. defined value -> PROGRESS: null; output: process in the click null00 SET_PROGRESS: (state, action) => { state.PROGRESS = state.PROGRESS += action.payload}, [1:59pm]

frankcollins3 commented 11 months ago

radix and parseInt() const newProgressValue = PROGRESS + parseInt(HYDRO_SCHEDULE.length, 10); [2:23pm]

frankcollins3 commented 11 months ago

using ['check', 'check', 'no'] // count of "check" as basis from which to SET_PROGRESS

this works during Yes instances of 'check' but because SET_STATE is based on count of checkChecker... ['false', 'false'] checkChecker still returns an int for every instance in the array which falsy returns length + 1 // this action causes an inaccurate count because a falsy value yields array.length which is what truthy is based on

const checkChecker = STATUS.map(STATUS => STATUS === 'check') const length = checkChecker.length const percentage = 100 / HYDRO_SCHEDULE.length dispatch(SET_PROGRESS(percentage * length))

[3:11pm]