Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
787b1991
Commit
787b1991
authored
Mar 27, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix nft image placeholder issue
parent
23b1163a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
12 deletions
+30
-12
NftImage.tsx
ui/shared/nft/NftImage.tsx
+30
-12
No files found.
ui/shared/nft/NftImage.tsx
View file @
787b1991
import
type
{
ResponsiveValue
}
from
'
@chakra-ui/react
'
;
import
{
AspectRatio
,
chakra
,
Icon
,
Image
,
shouldForwardProp
,
Skeleton
,
useColorModeValue
}
from
'
@chakra-ui/react
'
;
import
{
Box
,
AspectRatio
,
chakra
,
Icon
,
Image
,
shouldForwardProp
,
Skeleton
,
useColorModeValue
}
from
'
@chakra-ui/react
'
;
import
type
{
Property
}
from
'
csstype
'
;
import
React
from
'
react
'
;
...
...
@@ -30,6 +30,7 @@ const Fallback = ({ className, padding }: FallbackProps) => {
const
NftImage
=
({
url
,
className
,
fallbackPadding
,
objectFit
}:
Props
)
=>
{
const
[
isLoading
,
setIsLoading
]
=
React
.
useState
(
true
);
const
[
isError
,
setIsError
]
=
React
.
useState
(
false
);
const
handleLoad
=
React
.
useCallback
(()
=>
{
setIsLoading
(
false
);
...
...
@@ -37,10 +38,37 @@ const NftImage = ({ url, className, fallbackPadding, objectFit }: Props) => {
const
handleLoadError
=
React
.
useCallback
(()
=>
{
setIsLoading
(
false
);
setIsError
(
true
);
},
[]);
const
_objectFit
=
objectFit
||
'
contain
'
;
const
content
=
(()
=>
{
// as of ChakraUI v2.5.3
// fallback prop of Image component doesn't work well with loading prop lazy strategy
// so we have to render fallback and loader manually
if
(
isError
||
!
url
)
{
return
<
Fallback
className=
{
className
}
padding=
{
fallbackPadding
}
/>;
}
return
(
<
Box
>
{
isLoading
&&
<
Skeleton
position=
"absolute"
left=
{
0
}
top=
{
0
}
w=
"100%"
h=
"100%"
zIndex=
"1"
/>
}
<
Image
w=
"100%"
h=
"100%"
objectFit=
{
_objectFit
}
src=
{
url
}
opacity=
{
isLoading
?
0
:
1
}
alt=
"Token instance image"
onError=
{
handleLoadError
}
onLoad=
{
handleLoad
}
loading=
{
url
?
'
lazy
'
:
undefined
}
/>
</
Box
>
);
})();
return
(
<
AspectRatio
className=
{
className
}
...
...
@@ -54,17 +82,7 @@ const NftImage = ({ url, className, fallbackPadding, objectFit }: Props) => {
},
}
}
>
<
Image
w=
"100%"
h=
"100%"
objectFit=
{
_objectFit
}
src=
{
url
||
undefined
}
alt=
"Token instance image"
fallback=
{
url
&&
isLoading
?
<
Skeleton
/>
:
<
Fallback
className=
{
className
}
padding=
{
fallbackPadding
}
/>
}
onError=
{
handleLoadError
}
onLoad=
{
handleLoad
}
loading=
{
url
?
'
lazy
'
:
undefined
}
/>
{
content
}
</
AspectRatio
>
);
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment