Skip to content

Commit

Permalink
Pull logic into a function
Browse files Browse the repository at this point in the history
  • Loading branch information
ghengeveld committed May 22, 2024
1 parent e176ea9 commit 7a37790
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/components/SnapshotImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,23 @@ const StyledStack = styled(Stack)({
margin: "30px 15px",
});

const getOverlayImageLoaded = ({
comparisonImageLoaded,
focusImageLoaded,
showDiff,
showFocus,
}: {
comparisonImageLoaded: boolean;
focusImageLoaded: boolean;
showDiff: boolean;
showFocus: boolean;
}) => {
if (showDiff && showFocus) return comparisonImageLoaded && focusImageLoaded;
if (showDiff) return comparisonImageLoaded;
if (showFocus) return focusImageLoaded;
return true;
};

interface SnapshotImageProps {
componentName?: NonNullable<NonNullable<Test["story"]>["component"]>["name"];
storyName?: NonNullable<Test["story"]>["name"];
Expand Down Expand Up @@ -153,15 +170,12 @@ export const SnapshotImage = ({
const [comparisonImageLoaded, setComparisonImageLoaded] = React.useState(false);
const [focusImageLoaded, setFocusImageLoaded] = React.useState(false);
const snapshotImageLoaded = baselineImageVisible ? baselineImageLoaded : latestImageLoaded;

let overlayImageLoaded = true;
if (showDiff && showFocus) {
overlayImageLoaded = comparisonImageLoaded && focusImageLoaded;
} else if (showDiff) {
overlayImageLoaded = comparisonImageLoaded;
} else if (showFocus) {
overlayImageLoaded = focusImageLoaded;
}
const overlayImageLoaded = getOverlayImageLoaded({
comparisonImageLoaded,
focusImageLoaded,
showDiff,
showFocus,
});
const loading = !latestImageLoaded || !overlayImageLoaded;

return (
Expand Down

0 comments on commit 7a37790

Please sign in to comment.