-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab845e3
commit 0820edc
Showing
20 changed files
with
424 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Image } from '@monkvision/types'; | ||
|
||
/** | ||
* Utility function that extracts the images of the given inspection. | ||
* | ||
* @param inspectionId The ID of the inspection to get the images of. | ||
* @param images Array containing every image existing in the current local state. | ||
* @param filterRetakes Boolean indicating if retaken pictures should be filtered out or not (default: false). | ||
*/ | ||
export function getInspectionImages( | ||
inspectionId: string, | ||
images: Image[], | ||
filterRetakes = false, | ||
): Image[] { | ||
const inspectionImages = images.filter((image) => image.inspectionId === inspectionId); | ||
if (!filterRetakes) { | ||
return inspectionImages; | ||
} | ||
const filteredRetakes: Image[] = []; | ||
inspectionImages.forEach((image) => { | ||
if (image.additionalData?.sight_id) { | ||
const index = filteredRetakes.findIndex( | ||
(i) => i.additionalData?.sight_id === image.additionalData?.sight_id, | ||
); | ||
if (index >= 0) { | ||
const imageDateISO = image.additionalData?.created_at; | ||
const alreadyExistingImageDateISO = filteredRetakes[index].additionalData?.created_at; | ||
if ( | ||
alreadyExistingImageDateISO && | ||
imageDateISO && | ||
new Date(imageDateISO) > new Date(alreadyExistingImageDateISO) | ||
) { | ||
filteredRetakes[index] = image; | ||
} | ||
return; | ||
} | ||
} | ||
filteredRetakes.push(image); | ||
}); | ||
return filteredRetakes; | ||
} |
Oops, something went wrong.