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

array.push() not working [9:05am] #84

Closed frankcollins3 closed 11 months ago

frankcollins3 commented 11 months ago

attempting to do: write this working function without params. within the /ContextsPromises.tsx which gets the settings. client will set state. export default async function setScheduleWithSettings (settings:any, setState:any) { console.log('settings from schedule') console.log(settings) let schedule:number[] = []; if (!settings) { return } else if (settings) {
const SchedulePromise = new Promise(async(resolve:any, reject:any) => { const setSchedule = () => { for (let i = settings.start_time; i <= settings.end_time; i += settings.reminder) { schedule.push(i)} } await setSchedule() resolve(schedule.length ? schedule : "schedule fail") }) return SchedulePromise .then( (schedule) => { setState({payload: schedule}) return schedule }) } }

error: everything me and chatGPT try returns with an empty array

proposed approach: 2 promises?

frankcollins3 commented 11 months ago

2 things. the redux cache wasn't updating because the promise was trying to write to: 👍 redis.get("userSettings:${users_id}) but was mistakenly reading/writing to 👎 redis.get("users")

then the problem was a fast settings update which created: start_time: 5, end_time: 9 notification intensity 5. The loop increments by the notification intensity so it skipped 9. no val.

[10:00ishpm]