Closed frankcollins3 closed 1 year ago
index.tsx -> clientside invocation setDataStatePROMISE(true, true, true, true, true, true, true)
Contexts/Promises.tsx ->
async function setDataStatePROMISE(date:boolean, hydro_data:boolean, hydro_schedule:boolean, hydro_intake:boolean, status:boolean, disabled:boolean, progress:boolean):Promise
return getDailyDataPROMISE()
.then(async(dailyData:any) => {
return new Promise(async(resolve:any, reject:any) => {
console.log('dailyData before endpoint breakdown 190', dailyData)
console.log('dailyData from the promise', dailyData)
dailyData = dailyData.data.data.getDailyData
console.log('dailyData 192', dailyData)
let date = dailyData.date
if (date) dispatch(SET_DATE(dailyData.date))
if (hydro_data) dispatch(SET_HYDRO_DATA(dailyData))
if (status) dispatch(SET_STATUS(dailyData.status))
if (progress) dispatch(SET_PROGRESS(dailyData.progress))
if (hydro_intake) {
const waterintake:any = await userSettingsIntakePROMISE()
console.log('waterintake', waterintake)
dispatch(SET_HYDRO_INTAKE(waterintake))
}
if (hydro_schedule) {
const userDailyWaterSchedule = await userSettingsSchedulePROMISE()
let scheduleLength:number = userDailyWaterSchedule.length;
dispatch(SET_HYDRO_SCHEDULE(userDailyWaterSchedule))
if (disabled) {
dispatch(SET_DISABLED(Array(scheduleLength).fill(false)))
}
// console.log('schedule in promise', userDailyWaterSchedule)
}
resolve([{hydro_data: `${HYDRO_DATA}`, hydro_schedule: `${HYDRO_SCHEDULE}`, hydro_intake: `${HYDRO_INTAKE}`, date: `${DATE}`, status: `${STATUS}`, disabled: `${DISABLED}`}])
reject("error")
})
})
}
current approach is manually calling those functions 1 by 1 which set @redux/toolkit state: SETTINGS, WATER_DATA, HYDRO_INTAKE, STATUS, etc...
[11:43am]
issue 100 🎂🎂🎂🎂🎂🎂🎂🎂🎂🎂🎂🎂🎂🎂🎂
this approach would essentially be a separation of concerns issue: can see the data being there and then the lower promise saying it isn't there.
[11:51am]
can do the same thing with the clientside invocation with Promise.all() and have separate promises for each still expressed with 1 line of code.
The one that will be left out of that Promise.all() will be getDailyData because the endpoints are needed then and there.
oh and so the same for CURRENT_USER for the user icon needed immediately in that index.tsx effect
[11:53am]
"People hate going up the mountain. seeing the peak and realizing to get there they have to go all the way down."
// took some hours setting up Promises so true
hours until out of woods but this works in client:
iPROMISEcookies()
.then( (cookie) => {
console.log('cookie', cookie)
axios.post('/api/graphql', {
query: `query {
allUserData(users_id: ${cookie}) {
id
google_id
date
progress
weekday
status
users_id
}
}`,
}).then( (userdata) => {
console.log('userdata', userdata)
})
})
cookie: chrome-dev-tools -> application -> cookies ->
[12:10pm]
HUMAN ERROR! I was doing this when there was only piece of userdata, now that there's multiple, need a .find() to check for strict equality between date in psql data and current calendar date from JS constructor new Date() [12:23pm]
debating whether a new GraphQL query or a new Promise is better to handle this. // have done enough queries and want to be better at retrieving app PROMISES through useContext() [12:39pm
there already is such a query.. looking more into things. [12:42pm]
autoIncrement()
attempting to do: retrieve today-water-data corresponding to logged in user (by cookie). GraphQL query creates data if there is none for the day.
error: first page refresh: doesn't work. second page refresh works. seen: { line: 173Promises.tsx } 1 query works and the query for same data same line of code few browser logs down doesn't work
proposed approach: these are modular functions exported by Context. Might make an abstract function and work backwards.