-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix(images): encode escape sequences in external images paths * fix(images): apply fallback image without waiting for an error * refactor(images): defined default user image url constant * refactor(api): images loading
- Loading branch information
Showing
13 changed files
with
91 additions
and
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,28 @@ | ||
import type { ImageProps as NextImageProps } from 'next/image'; | ||
import NextImage from 'next/image'; | ||
import clsx from 'clsx'; | ||
import { useState } from 'react'; | ||
|
||
interface Props extends NextImageProps { | ||
rounded?: boolean; | ||
} | ||
|
||
export const Image = ({ rounded = false, className, src, ...props }: Props) => { | ||
const [error, setError] = useState(false); | ||
return ( | ||
<div className={clsx('overflow-hidden', rounded && 'rounded-full')}> | ||
<NextImage | ||
className={clsx( | ||
'bg-foreground before:grid before:h-full before:place-items-center before:p-2 before:text-center', | ||
rounded && 'rounded-full', | ||
className, | ||
)} | ||
placeholder="blur" | ||
blurDataURL="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAQSURBVHgBAQUA+v8ANTU1/wLhAZ/HkyyzAAAAAElFTkSuQmCC" | ||
style={{ | ||
maxWidth: '100%', | ||
height: 'auto', | ||
objectFit: 'cover', | ||
}} | ||
loading="lazy" | ||
src={ | ||
error | ||
? 'https://cdn.stats.fm/file/statsfm/images/placeholders/users/private.webp' | ||
: src | ||
} | ||
onError={() => setError(true)} | ||
{...props} | ||
/> | ||
</div> | ||
); | ||
}; | ||
export const Image = ({ rounded = false, className, ...props }: Props) => ( | ||
<div className={clsx('overflow-hidden', rounded && 'rounded-full')}> | ||
<NextImage | ||
className={clsx( | ||
'bg-foreground before:grid before:h-full before:place-items-center before:p-2 before:text-center', | ||
rounded && 'rounded-full', | ||
className, | ||
)} | ||
placeholder="blur" | ||
blurDataURL="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAQSURBVHgBAQUA+v8ANTU1/wLhAZ/HkyyzAAAAAElFTkSuQmCC" | ||
style={{ | ||
maxWidth: '100%', | ||
height: 'auto', | ||
objectFit: 'cover', | ||
}} | ||
loading="lazy" | ||
{...props} | ||
/> | ||
</div> | ||
); |
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,2 @@ | ||
export const defaultUserImageURL = | ||
'https://cdn.stats.fm/file/statsfm/images/placeholders/users/private.webp'; |
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
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,2 @@ | ||
export const isFacebookURL = (url: string): boolean => | ||
url.includes('fbcdn') || url.includes('fbsbx'); |