Skip to content

Commit

Permalink
Fix/perf
Browse files Browse the repository at this point in the history
  • Loading branch information
lailabjil committed Mar 28, 2024
1 parent 2c882dd commit e07c749
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/service/api-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ const requestPutSurveyData = (
data: SurveyData,
token?: string,
): Promise<SurveyData> => {
return new Promise((resolve, reject) => {
return new Promise(resolve => {
setTimeout(() => {
axios
.put(
Expand Down Expand Up @@ -291,7 +291,7 @@ const requestPutSurveyDataReviewer = (
requestPutDataReviewer(idSurvey, data, token);
});

return new Promise(resolve => {
return new Promise(() => {
const surveyData: SurveyData = {
stateData: stateData,
data: data,
Expand Down
27 changes: 10 additions & 17 deletions src/service/survey-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -943,23 +943,20 @@ const saveData = (
fixConditionals(data);
const isChange = forceUpdate || dataIsChange(idSurvey, data);
const promisesToWait: Promise<any>[] = [];

data = updateLocked(idSurvey, data);
datas.set(idSurvey, data);
let stateData: StateData = initStateData();
let dataRemote: SurveyData;

if (isChange) {
data = saveQualityScore(idSurvey, data);
if (!isDemoMode && isReviewerMode && !localSaveOnly && navigator.onLine) {
stateData = getSurveyStateData(data, idSurvey);
promisesToWait.push(
remotePutSurveyDataReviewer(idSurvey, stateData, data)
.then(dataR => {
dataRemote = dataR;
})
.catch(() => {
//return Promise.reject({});
//We ignore the error because user is stuck on EndSurveyPage if he couldn't submit in any moment his survey.
}),
remotePutSurveyDataReviewer(idSurvey, stateData, data).catch(() => {
//return Promise.reject({});
//We ignore the error because user is stuck on EndSurveyPage if he couldn't submit in any moment his survey.
}),
);
}
//We try to submit each time the local database is updated if the user is online
Expand All @@ -970,14 +967,10 @@ const saveData = (
data: data,
};
promisesToWait.push(
remotePutSurveyData(idSurvey, surveyData)
.then(dataR => {
dataRemote = dataR;
})
.catch(() => {
//return Promise.reject({});
//We ignore the error because user is stuck on EndSurveyPage if he couldn't submit in any moment his survey.
}),
remotePutSurveyData(idSurvey, surveyData).catch(() => {
//return Promise.reject({});
//We ignore the error because user is stuck on EndSurveyPage if he couldn't submit in any moment his survey.
}),
);
} else if (isDemoMode || localSaveOnly) {
stateData = getSurveyStateData(data, idSurvey);
Expand Down

0 comments on commit e07c749

Please sign in to comment.