Skip to content

Commit

Permalink
go back to original updateCheck
Browse files Browse the repository at this point in the history
I changed this to accept the unmodified check with newProps as a separate parameter. It turns out the old implementation where the check was mutated was actually a behavior being relied on; so I am reverting
  • Loading branch information
JGreenlee committed Oct 5, 2024
1 parent 831960f commit 1121676
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions www/js/usePermissionStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ const usePermissionStatus = () => {

//using this function to update checks rather than mutate
//this cues React to update UI
function updateCheck(check, newProps) {
function updateCheck(newCheck) {
const tempList = [...checkList];
//"find and replace" the check
const i = tempList.findIndex((item) => item.name == check.name);
tempList[i] = { ...tempList[i], ...newProps };
const i = tempList.findIndex((item) => item.name == newCheck.name);
tempList[i] = newCheck;
setCheckList(tempList);
}

Expand All @@ -55,13 +55,15 @@ const usePermissionStatus = () => {
try {
const status = await nativeFn();
logDebug(`${checkObj.name} status = ${status}`);
updateCheck(newCheck, { status: true });
newCheck.status = true;
updateCheck(newCheck);
return status;
} catch (error) {
if (showError) {
AlertManager.addMessage({ text: error });
}
updateCheck(newCheck, { status: false });
newCheck.status = false;
updateCheck(newCheck);
return error;
}
}
Expand Down

0 comments on commit 1121676

Please sign in to comment.