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
27768300
Commit
27768300
authored
Jul 16, 2024
by
Max Alekseenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dapps lazy loading
parent
b7597493
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
40 deletions
+46
-40
useLazyRenderedList.tsx
lib/hooks/useLazyRenderedList.tsx
+3
-3
MarketplaceList.tsx
ui/marketplace/MarketplaceList.tsx
+43
-37
No files found.
lib/hooks/useLazyRenderedList.tsx
View file @
27768300
...
...
@@ -5,12 +5,12 @@ import { useInView } from 'react-intersection-observer';
const
STEP
=
10
;
const
MIN_ITEMS_NUM
=
50
;
export
default
function
useLazyRenderedList
(
list
:
Array
<
unknown
>
,
isEnabled
:
boolean
)
{
const
[
renderedItemsNum
,
setRenderedItemsNum
]
=
React
.
useState
(
MIN_ITEMS_NUM
);
export
default
function
useLazyRenderedList
(
list
:
Array
<
unknown
>
,
isEnabled
:
boolean
,
minItemsNum
:
number
=
MIN_ITEMS_NUM
)
{
const
[
renderedItemsNum
,
setRenderedItemsNum
]
=
React
.
useState
(
minItemsNum
);
const
{
ref
,
inView
}
=
useInView
({
rootMargin
:
'
200px
'
,
triggerOnce
:
false
,
skip
:
!
isEnabled
||
list
.
length
<=
MIN_ITEMS_NUM
,
skip
:
!
isEnabled
||
list
.
length
<=
minItemsNum
,
});
React
.
useEffect
(()
=>
{
...
...
ui/marketplace/MarketplaceList.tsx
View file @
27768300
import
{
Grid
}
from
'
@chakra-ui/react
'
;
import
{
Grid
,
Box
}
from
'
@chakra-ui/react
'
;
import
React
,
{
useCallback
}
from
'
react
'
;
import
type
{
MouseEvent
}
from
'
react
'
;
import
type
{
MarketplaceAppWithSecurityReport
,
ContractListTypes
,
AppRating
}
from
'
types/client/marketplace
'
;
import
useLazyRenderedList
from
'
lib/hooks/useLazyRenderedList
'
;
import
*
as
mixpanel
from
'
lib/mixpanel/index
'
;
import
EmptySearchResult
from
'
./EmptySearchResult
'
;
...
...
@@ -30,6 +31,8 @@ const MarketplaceList = ({
apps
,
showAppInfo
,
favoriteApps
,
onFavoriteClick
,
isLoading
,
selectedCategoryId
,
onAppClick
,
showContractList
,
userRatings
,
rateApp
,
isSendingRating
,
isRatingLoading
,
canRate
,
}:
Props
)
=>
{
const
{
cutRef
,
renderedItemsNum
}
=
useLazyRenderedList
(
apps
,
!
isLoading
,
16
);
const
handleInfoClick
=
useCallback
((
id
:
string
)
=>
{
mixpanel
.
logEvent
(
mixpanel
.
EventTypes
.
PAGE_WIDGET
,
{
Type
:
'
More button
'
,
Info
:
id
,
Source
:
'
Discovery view
'
});
showAppInfo
(
id
);
...
...
@@ -40,42 +43,45 @@ const MarketplaceList = ({
},
[
onFavoriteClick
]);
return
apps
.
length
>
0
?
(
<
Grid
templateColumns=
{
{
md
:
'
repeat(auto-fill, minmax(230px, 1fr))
'
,
lg
:
'
repeat(auto-fill, minmax(260px, 1fr))
'
,
}
}
autoRows=
"1fr"
gap=
{
{
base
:
'
16px
'
,
md
:
'
24px
'
}
}
>
{
apps
.
map
((
app
,
index
)
=>
(
<
MarketplaceAppCard
key=
{
app
.
id
+
(
isLoading
?
index
:
''
)
}
onInfoClick=
{
handleInfoClick
}
id=
{
app
.
id
}
external=
{
app
.
external
}
url=
{
app
.
url
}
title=
{
app
.
title
}
logo=
{
app
.
logo
}
logoDarkMode=
{
app
.
logoDarkMode
}
shortDescription=
{
app
.
shortDescription
}
categories=
{
app
.
categories
}
isFavorite=
{
favoriteApps
.
includes
(
app
.
id
)
}
onFavoriteClick=
{
handleFavoriteClick
}
isLoading=
{
isLoading
}
internalWallet=
{
app
.
internalWallet
}
onAppClick=
{
onAppClick
}
securityReport=
{
app
.
securityReport
}
showContractList=
{
showContractList
}
rating=
{
app
.
rating
}
userRating=
{
userRatings
[
app
.
id
]
}
rateApp=
{
rateApp
}
isSendingRating=
{
isSendingRating
}
isRatingLoading=
{
isRatingLoading
}
canRate=
{
canRate
}
/>
))
}
</
Grid
>
<>
<
Grid
templateColumns=
{
{
md
:
'
repeat(auto-fill, minmax(230px, 1fr))
'
,
lg
:
'
repeat(auto-fill, minmax(260px, 1fr))
'
,
}
}
autoRows=
"1fr"
gap=
{
{
base
:
'
16px
'
,
md
:
'
24px
'
}
}
>
{
apps
.
slice
(
0
,
renderedItemsNum
).
map
((
app
,
index
)
=>
(
<
MarketplaceAppCard
key=
{
app
.
id
+
(
isLoading
?
index
:
''
)
}
onInfoClick=
{
handleInfoClick
}
id=
{
app
.
id
}
external=
{
app
.
external
}
url=
{
app
.
url
}
title=
{
app
.
title
}
logo=
{
app
.
logo
}
logoDarkMode=
{
app
.
logoDarkMode
}
shortDescription=
{
app
.
shortDescription
}
categories=
{
app
.
categories
}
isFavorite=
{
favoriteApps
.
includes
(
app
.
id
)
}
onFavoriteClick=
{
handleFavoriteClick
}
isLoading=
{
isLoading
}
internalWallet=
{
app
.
internalWallet
}
onAppClick=
{
onAppClick
}
securityReport=
{
app
.
securityReport
}
showContractList=
{
showContractList
}
rating=
{
app
.
rating
}
userRating=
{
userRatings
[
app
.
id
]
}
rateApp=
{
rateApp
}
isSendingRating=
{
isSendingRating
}
isRatingLoading=
{
isRatingLoading
}
canRate=
{
canRate
}
/>
))
}
</
Grid
>
<
Box
ref=
{
cutRef
}
h=
{
0
}
/>
</>
)
:
(
<
EmptySearchResult
selectedCategoryId=
{
selectedCategoryId
}
favoriteApps=
{
favoriteApps
}
/>
);
...
...
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