Skip to content

Commit

Permalink
fix: fix lint on product summary image
Browse files Browse the repository at this point in the history
  • Loading branch information
LPastine committed Dec 15, 2023
1 parent 600d62c commit 1b8a151
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions react/ProductSummaryImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,13 @@ function ProductImage({
fetchpriority = 'byPosition',
}: Props) {
// @ts-expect-error - Depends on vtex.product-summary-context update on PR: https://github.com/vtex-apps/product-summary-context/pull/25
const { product, position }: { product: ProductSummaryTypes.Product, position: number | undefined } = useProductSummary()
const {
product,
position

Check failure on line 322 in react/ProductSummaryImage.tsx

View workflow job for this annotation

GitHub Actions / Lint

Insert `,`
}: {
product: ProductSummaryTypes.Product,

Check failure on line 324 in react/ProductSummaryImage.tsx

View workflow job for this annotation

GitHub Actions / Lint

Delete `,`
position: number | undefined
} = useProductSummary()
const { handles, withModifiers } = useCssHandles(CSS_HANDLES, { classes })

Check warning on line 327 in react/ProductSummaryImage.tsx

View workflow job for this annotation

GitHub Actions / Lint

Expected blank line before this statement

const [error, setError] = useState(false)
Expand Down Expand Up @@ -427,16 +433,26 @@ function ProductImage({

/**
* Determines the priority ('high' or 'low') based on the isMobile flag and the position value.
* @param isMobile - A boolean indicating the device type (true for mobile, false for non-mobile).
* @param position - The Product Summary's position on a list context or search result, used to determine priority.
* @param isMobileDevice - A boolean indicating the device type (true for mobile, false for non-mobile).
* @param positionNumber - The Product Summary's position on a list context or search result, used to determine priority.
* @returns A string representing the priority: 'high' for high priority, 'low' for low priority.
*/
const getFetchPriority = (isMobile: boolean, position: number | undefined): 'high' | 'low' => {
if (position) {
return isMobile ? (position === 1 ? 'high' : 'low') : position < 4 ? 'high' : 'low';
const getFetchPriority = (
isMobileDevice: boolean,
positionNumber: number | undefined
): 'high' | 'low' => {
if (positionNumber) {
return isMobileDevice ?

Check failure on line 445 in react/ProductSummaryImage.tsx

View workflow job for this annotation

GitHub Actions / Lint

Delete `·?`
positionNumber === 1

Check failure on line 446 in react/ProductSummaryImage.tsx

View workflow job for this annotation

GitHub Actions / Lint

Insert `···?`
? 'high'

Check failure on line 447 in react/ProductSummaryImage.tsx

View workflow job for this annotation

GitHub Actions / Lint

Insert `····`
: 'low'

Check failure on line 448 in react/ProductSummaryImage.tsx

View workflow job for this annotation

GitHub Actions / Lint

Insert `····`
: positionNumber < 4

Check failure on line 449 in react/ProductSummaryImage.tsx

View workflow job for this annotation

GitHub Actions / Lint

Insert `··`
? 'high'

Check failure on line 450 in react/ProductSummaryImage.tsx

View workflow job for this annotation

GitHub Actions / Lint

Insert `··`
: 'low'

Check failure on line 451 in react/ProductSummaryImage.tsx

View workflow job for this annotation

GitHub Actions / Lint

Insert `··`
}
return 'low';
};

return 'low'
}

return (
<div className={imageClassName}>
Expand All @@ -461,7 +477,11 @@ function ProductImage({
alt={name}
className={imageClassname}
onError={onError}
fetchpriority={fetchpriority === 'byPosition' ? getFetchPriority(isMobile, position) : fetchpriority}
fetchpriority={
fetchpriority === 'byPosition'
? getFetchPriority(isMobile, position)

Check failure on line 482 in react/ProductSummaryImage.tsx

View workflow job for this annotation

GitHub Actions / Lint

Insert `··`
: fetchpriority
}
/>
{selectedHoverImage && !isMobile && (
<Image
Expand Down Expand Up @@ -570,12 +590,12 @@ ProductImage.schema = {
'admin/editor.productSummaryImage.fetchpriority.high',
'admin/editor.productSummaryImage.fetchpriority.low',
'admin/editor.productSummaryImage.fetchpriority.auto',
'admin/editor.productSummaryImage.fetchpriority.byPosition'
'admin/editor.productSummaryImage.fetchpriority.byPosition',
],
widget: {
'ui:widget': 'radio'
'ui:widget': 'radio',
},
default: 'byPosition'
default: 'byPosition',
},
},
}
Expand Down

0 comments on commit 1b8a151

Please sign in to comment.