Skip to content

Commit

Permalink
Merge branch 'develop' into fix/trim-moment-empty-content
Browse files Browse the repository at this point in the history
  • Loading branch information
wlliaml authored Aug 23, 2024
2 parents 38b8147 + 1c9f4a5 commit 4894fef
Show file tree
Hide file tree
Showing 19 changed files with 30 additions and 44 deletions.
16 changes: 10 additions & 6 deletions src/common/utils/url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe('utils/url/toSizedImageURL', () => {
width: 72,
})
).toBe(
'https://imagedelivery.net/abc/prod/image.jpeg/w=72,h=288,fit=scale-down'
'https://imagedelivery.net/abc/prod/image.jpeg/w=72,h=288,fit=scale-down,anim=false'
)

// width
Expand All @@ -147,7 +147,7 @@ describe('utils/url/toSizedImageURL', () => {
width: 72,
})
).toBe(
'https://imagedelivery.net/abc/prod/image.jpeg/w=72,h=288,fit=scale-down'
'https://imagedelivery.net/abc/prod/image.jpeg/w=72,h=288,fit=scale-down,anim=false'
)

// with width and height
Expand All @@ -157,7 +157,9 @@ describe('utils/url/toSizedImageURL', () => {
width: 72,
height: 72,
})
).toBe('https://imagedelivery.net/abc/prod/image.jpeg/w=72,h=72,fit=crop')
).toBe(
'https://imagedelivery.net/abc/prod/image.jpeg/w=72,h=72,fit=crop,anim=false'
)

// with width and height and ext
expect(
Expand All @@ -167,15 +169,17 @@ describe('utils/url/toSizedImageURL', () => {
height: 72,
ext: 'webp',
})
).toBe('https://imagedelivery.net/abc/prod/image.webp/w=72,h=72,fit=crop')
).toBe(
'https://imagedelivery.net/abc/prod/image.webp/w=72,h=72,fit=crop,anim=false'
)

// with width and height and disableAnimation
// with width and height and enableAnimation
expect(
toSizedImageURL({
url: 'https://imagedelivery.net/abc/prod/image.gif',
width: 72,
height: 72,
disableAnimation: true,
enableAnimation: false,
})
).toBe(
'https://imagedelivery.net/abc/prod/image.gif/w=72,h=72,fit=crop,anim=false'
Expand Down
6 changes: 3 additions & 3 deletions src/common/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface ToSizedImageURLProps {
width: ToSizedImageURLSize
height?: ToSizedImageURLSize
ext?: 'webp'
disableAnimation?: boolean
enableAnimation?: boolean
}

const changeExt = ({ key, ext }: { key: string; ext?: 'webp' }) => {
Expand All @@ -52,7 +52,7 @@ export const toSizedImageURL = ({
width,
height,
ext,
disableAnimation,
enableAnimation,
}: ToSizedImageURLProps) => {
const assetDomain = process.env.NEXT_PUBLIC_CF_IMAGE_URL
? `${process.env.NEXT_PUBLIC_CF_IMAGE_URL}`
Expand Down Expand Up @@ -81,7 +81,7 @@ export const toSizedImageURL = ({
? `w=${width},h=${height},fit=crop`
: `w=${width},h=${width * 4},fit=scale-down`

if (disableAnimation) {
if (!enableAnimation) {
postfix += ',anim=false'
}

Expand Down
7 changes: 1 addition & 6 deletions src/components/ArticleDigest/AuthorSidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,7 @@ export const ArticleDigestAuthorSidebar = ({
{showCover && cover && (
<LinkWrapper {...path} disabled={isBanned}>
<aside className={styles.cover}>
<ResponsiveImage
url={cover}
width={imgSize}
height={imgSize}
disableAnimation={true}
/>
<ResponsiveImage url={cover} width={imgSize} height={imgSize} />
</aside>
</LinkWrapper>
)}
Expand Down
1 change: 0 additions & 1 deletion src/components/ArticleDigest/Curated/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export const ArticleDigestCurated = ({
url={cover || IMAGE_DEFAULT_CURATED}
width={404}
height={404}
disableAnimation={true}
/>
</LinkWrapper>
</section>
Expand Down
1 change: 0 additions & 1 deletion src/components/ArticleDigest/Feed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ const BaseArticleDigestFeed = ({
height={152}
smUpWidth={212}
smUpHeight={212}
disableAnimation={true}
loading={isFirstFold ? undefined : 'lazy'}
fetchPriority={isFirstFold ? 'high' : 'low'}
/>
Expand Down
1 change: 0 additions & 1 deletion src/components/ArticleDigest/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export const ArticleDigestSidebar = ({
url={cover}
width={hasBackground ? 336 : 144}
height={hasBackground ? undefined : 144}
disableAnimation={true}
/>
</aside>
)}
Expand Down
1 change: 1 addition & 0 deletions src/components/Avatar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export const Avatar = (props: AvatarProps) => {
smUpWidth={240}
smUpHeight={240}
disabled={isFallback || inEditor}
enableAnimation
/>

{isCivicLiker && !hasArchitectBadge && (
Expand Down
1 change: 0 additions & 1 deletion src/components/Book/Article/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ const BookArticle: React.FC<BookArticleProps> = ({
width={240}
height={200}
anonymous
disableAnimation={true}
/>
</div>
)}
Expand Down
1 change: 0 additions & 1 deletion src/components/Book/Collection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ const BookCollection: React.FC<BookCollectionProps> = ({
width={240}
height={200}
anonymous
disableAnimation={true}
/>
{hasMask && (
<div className={styles.mask}>
Expand Down
1 change: 0 additions & 1 deletion src/components/Book/Flat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const BookFlat: React.FC<BookFlatProps> = ({ title, cover, type }) => {
width={100} // smaller size for color thief
height={100}
anonymous
disableAnimation={true}
/>
</div>

Expand Down
1 change: 1 addition & 0 deletions src/components/CircleAvatar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const CircleAvatar = (props: CircleAvatarProps) => {
width={144}
height={144}
disabled={isFallback || inEditor}
enableAnimation
/>
</div>
)
Expand Down
1 change: 0 additions & 1 deletion src/components/Editor/ListItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const CoverIndicator = ({ cover }: { cover?: string | null }) => (
url: cover,
width: 72,
height: 72,
disableAnimation: true,
})}
alt="cover"
/>
Expand Down
1 change: 0 additions & 1 deletion src/components/Editor/SetCover/Selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ const Selector: React.FC<SelectorProps> = ({
url: asset.path,
width: 72,
height: 72,
disableAnimation: true,
})}
alt="cover"
/>
Expand Down
1 change: 0 additions & 1 deletion src/components/Editor/Sidebar/Cover/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const SidebarCover = ({ cover, disabled, ...restProps }: SidebarCoverProps) => {
url: cover,
width: 230,
height: 230,
disableAnimation: true,
})}
alt="cover"
/>
Expand Down
9 changes: 6 additions & 3 deletions src/components/MomentDigest/Assets/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'photoswipe/dist/photoswipe.css'

import gql from 'graphql-tag'
import PhotoSwipe from 'photoswipe'
import type PhotoSwipe from 'photoswipe'
import { useEffect, useRef, useState } from 'react'
import { Gallery, Item } from 'react-photoswipe-gallery'

Expand Down Expand Up @@ -115,10 +115,13 @@ const Assets = ({ moment }: { moment: MomentDigestAssetsMomentFragment }) => {
{loadedAssets.map((asset) => (
<Item
key={asset.id}
original={asset.path}
original={toSizedImageURL({
url: asset.path,
width: 1366,
})}
thumbnail={toSizedImageURL({
url: asset.path,
width: width,
width,
})}
width={asset.width}
height={asset.height}
Expand Down
16 changes: 7 additions & 9 deletions src/components/ResponsiveImage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface ResponsiveImageProps {
disabled?: boolean
loading?: 'eager' | 'lazy'
anonymous?: boolean
disableAnimation?: boolean
enableAnimation?: boolean
fetchPriority?: 'high' | 'low' | 'auto'
}

Expand All @@ -29,15 +29,15 @@ const BaseResponsiveImage = ({
disabled,
loading,
anonymous,
disableAnimation,
enableAnimation,
fetchPriority,
}: ResponsiveImageProps) => {
const [error, setError] = useState(false)
const [loaded, setLoaded] = useState(false)

// eg: https://.../images/prod/avatar/b1bea2ab-112a-4cb9-8fa1-2703113751cc.gif/public
const isGIF = /gif(\/|$)/i.test(url)
if (isGIF && !disableAnimation) {
if (isGIF && enableAnimation) {
// override some fetch policy for animated GIF, work around some cloudflare images GIF re-sizing problems
loading = 'lazy'
fetchPriority = 'low'
Expand All @@ -62,7 +62,7 @@ const BaseResponsiveImage = ({
url,
width: smUpWidth,
height: smUpHeight,
disableAnimation,
enableAnimation,
})}
/>
)}
Expand All @@ -72,7 +72,7 @@ const BaseResponsiveImage = ({
url,
width,
height,
disableAnimation,
enableAnimation,
})}
/>

Expand All @@ -82,15 +82,13 @@ const BaseResponsiveImage = ({
url,
width,
height,
disableAnimation: !loaded || disableAnimation, // use true until loaded
enableAnimation: !loaded || !enableAnimation, // use true until loaded
})}
loading={loading}
alt=""
crossOrigin={anonymous ? 'anonymous' : undefined}
fetchPriority={fetchPriority}
onLoad={() => {
// console.log(`img onload:`)
// this.srcSet = toSizedImageURL({ url, width, height, disableAnimation })
setLoaded(true)
}}
/>
Expand All @@ -115,7 +113,7 @@ export const ResponsiveImage = React.memo(
prevProps.smUpWidth === props.smUpWidth &&
prevProps.smUpHeight === props.smUpHeight &&
prevProps.disabled === props.disabled &&
prevProps.disableAnimation === props.disableAnimation &&
prevProps.enableAnimation === props.enableAnimation &&
prevProps.fetchPriority === props.fetchPriority
)
}
Expand Down
1 change: 0 additions & 1 deletion src/components/TagDigest/Feed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ const Feed = ({ tag, ...cardProps }: TagDigestFeedProps) => {
url={tag.cover || IMAGE_TAG_COVER.src}
width={144}
height={144}
disableAnimation={true}
/>
</a>
</Link>
Expand Down
1 change: 0 additions & 1 deletion src/components/TagDigest/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ const Sidebar = ({ tag, ...cardProps }: TagDigestSidebarProps) => {
url={tag.cover || IMAGE_TAG_COVER.src}
width={144}
height={144}
disableAnimation={true}
/>
</a>
</Link>
Expand Down
7 changes: 1 addition & 6 deletions src/views/Follow/Feed/FollowingRecommendArticle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ const RecommendArticle = ({ article, ...cardProps }: Props) => {

{cover && (
<section className={styles.cover}>
<ResponsiveImage
url={cover}
width={144}
height={144}
disableAnimation={true}
/>
<ResponsiveImage url={cover} width={144} height={144} />
</section>
)}
</section>
Expand Down

0 comments on commit 4894fef

Please sign in to comment.