Closed frankcollins3 closed 11 months ago
chatGPT came up with this but did not yield any change:
async function setDataStatePROMISE(date:boolean, hydro_data:boolean, hydro_schedule:boolean, hydro_intake:boolean, status:boolean): Promise
I threw this at the wall in good hope:
async function setDataStatePROMISE
[4:08pm]
👎 I guessed this as well:
async function setDataStatePROMISE(date:boolean, hydro_data:boolean, hydro_schedule:boolean, hydro_intake:boolean, status:boolean):Promise
[4:09pm]
i credit dabbling in C with this idea coming to mind: instead of sending 4 parameters, all boolean
try 1 paramter: // an array with 4 ints, from which a truthy one will determine corresponding state in same above order as bool [1, 1, 1, 1]
[4:11pm]
lucked out. went back up to see about types and defaults and realized parameters must be declared. to be honest kind of surprised chatGPT didn't catch this.
type PromiseTypes = { tokenID: number
iPROMISEcookies: () => any;
getUserSettingsPROMISE: () => any;
userSettingsSchedulePROMISE: () => any;
userSettingsIntakePROMISE: () => any;
getDailyDataPROMISE: () => any;
setDataStatePROMISE: (date:boolean, hydro_data:boolean, hydro_schedule:boolean, hydro_intake:boolean, status:boolean) => any;
}
const PromiseDefaults = { tokenID: 1,
iPROMISEcookies: () => {},
getUserSettingsPROMISE: () => {},
userSettingsSchedulePROMISE: () => {},
userSettingsIntakePROMISE: () => {},
getDailyDataPROMISE: () => {},
setDataStatePROMISE: (date:boolean, hydro_data:boolean, hydro_schedule:boolean, hydro_intake:boolean, status:boolean) => {},
}
[4:14pm]
attempting to do: 1 asyncFunc() / Promise that allows parameter-determined specification on which state inits the currentUser upon app load
error: async function setDataStatePROMISE(date:boolean, hydro_data:boolean, hydro_schedule:boolean, hydro_intake:boolean, status:boolean) {
return getDailyDataPROMISE() .then(async(dailyData:any) => { return new Promise(async(resolve:any, reject:any) => { console.log('dailyData from the promise', dailyData)
if (date) dispatch(SET_DATE(dailyData.date)) if (hydro_data) dispatch(SET_HYDRO_DATA(dailyData)) if (status) dispatch(SET_STATUS(dailyData.status)) if (hydro_intake) { const waterintake:any = await userSettingsIntakePROMISE() console.log('waterintake', waterintake) dispatch(SET_HYDRO_INTAKE(waterintake)) } if (hydro_schedule) { const userDailyWaterSchedule = await userSettingsSchedulePROMISE() console.log('schedule in promise', userDailyWaterSchedule) }
resolve([{hydro_data:
${HYDRO_DATA}
, hydro_schedule:${HYDRO_SCHEDULE}
, hydro_intake:${HYDRO_INTAKE}
, date:${DATE}
, status:${STATUS}
}])reject("error") }) }) }
proposed approach: 👎 return getDailyDataPROMISE() // added this.to get the same error