Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielrindlaub committed Apr 20, 2024
1 parent 1204de6 commit 35f22e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/app/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ export const getRandomColor = () => {
const green = Math.floor(Math.random() * (255 - 0) + 0);
const blue = Math.floor(Math.random() * (255 - 0) + 0);

const integer = ((Math.round(red) & 0xff) << 16) + ((Math.round(green) & 0xff) << 8) + (Math.round(blue) & 0xff);
const integer =
((Math.round(red) & 0xff) << 16) +
((Math.round(green) & 0xff) << 8) +
(Math.round(blue) & 0xff);

const string = integer.toString(16).toUpperCase();
return '000000'.substring(string.length) + string;
Expand All @@ -156,10 +159,14 @@ export const normalizeErrors = (error, code) => {
};

export const isImageReviewed = (image) => {
// images are considered reviewed if they:
// have objects,
// all objects are locked,
// AND not all labels of all objects have been invalidated
const hasObjs = image.objects.length > 0;
const hasUnlockedObjs = image.objects.some((obj) => obj.locked === false);
const hasAllInvalidatedLabels = !image.objects.some((obj) =>
obj.labels.some((lbl) => !lbl.validation || lbl.validation.validated),
);
return hasObjs && !hasUnlockedObjs && !hasAllInvalidatedLabels;
};
};
5 changes: 3 additions & 2 deletions src/features/review/reviewSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ export const reviewSlice = createSlice({
if (!object.labels.length) {
const objectIndex = image.objects.findIndex((obj) => obj._id === objId);
image.objects.splice(objectIndex, 1);
image.reviewed = isImageReviewed(image);
}

image.reviewed = isImageReviewed(image);
}
},

Expand All @@ -102,7 +103,6 @@ export const reviewSlice = createSlice({
label.validation = { validated, userId };
const image = findImage(state.workingImages, imgId);
image.reviewed = isImageReviewed(image);
console.log(image);
});

state.lastAction = payload.labels[0].validated ? 'labels-validated' : 'labels-invalidated';
Expand All @@ -115,6 +115,7 @@ export const reviewSlice = createSlice({
object.locked = oldLocked;
const label = findLabel(state.workingImages, imgId, objId, lblId);
label.validation = oldValidation;
const image = findImage(state.workingImages, imgId);
image.reviewed = isImageReviewed(image);
});
},
Expand Down

0 comments on commit 35f22e9

Please sign in to comment.