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
bf709de4
Unverified
Commit
bf709de4
authored
Feb 20, 2024
by
Igor Stuev
Committed by
GitHub
Feb 20, 2024
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1619 from blockscout/dapp-sorting-with-favourites
Sort dapps by favourite
parents
66ec60d0
2d3066fc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
3 deletions
+13
-3
useMarketplaceApps.tsx
ui/marketplace/useMarketplaceApps.tsx
+13
-3
No files found.
ui/marketplace/useMarketplaceApps.tsx
View file @
bf709de4
...
...
@@ -22,11 +22,15 @@ function isAppCategoryMatches(category: string, app: MarketplaceAppOverview, fav
app
.
categories
.
includes
(
category
);
}
function
sortApps
(
apps
:
Array
<
MarketplaceAppOverview
>
)
{
function
sortApps
(
apps
:
Array
<
MarketplaceAppOverview
>
,
favoriteApps
:
Array
<
string
>
)
{
return
apps
.
sort
((
a
,
b
)
=>
{
const
priorityA
=
a
.
priority
||
0
;
const
priorityB
=
b
.
priority
||
0
;
// First, sort by priority (descending)
// First, sort by favorite apps
if
(
favoriteApps
.
includes
(
a
.
id
)
!==
favoriteApps
.
includes
(
b
.
id
))
{
return
favoriteApps
.
includes
(
a
.
id
)
?
-
1
:
1
;
}
// Then sort by priority (descending)
if
(
priorityB
!==
priorityA
)
{
return
priorityB
-
priorityA
;
}
...
...
@@ -47,6 +51,12 @@ export default function useMarketplaceApps(filter: string, selectedCategoryId: s
const
fetch
=
useFetch
();
const
apiFetch
=
useApiFetch
();
// Update favorite apps only when selectedCategoryId changes to avoid sortApps to be called on each favorite app click
const
lastFavoriteAppsRef
=
React
.
useRef
(
favoriteApps
);
React
.
useEffect
(()
=>
{
lastFavoriteAppsRef
.
current
=
favoriteApps
;
},
[
selectedCategoryId
]);
// eslint-disable-line react-hooks/exhaustive-deps
const
{
isPlaceholderData
,
isError
,
error
,
data
}
=
useQuery
<
unknown
,
ResourceError
<
unknown
>
,
Array
<
MarketplaceAppOverview
>>
({
queryKey
:
[
'
marketplace-dapps
'
],
queryFn
:
async
()
=>
{
...
...
@@ -58,7 +68,7 @@ export default function useMarketplaceApps(filter: string, selectedCategoryId: s
return
apiFetch
(
'
marketplace_dapps
'
,
{
pathParams
:
{
chainId
:
config
.
chain
.
id
}
});
}
},
select
:
(
data
)
=>
sortApps
(
data
as
Array
<
MarketplaceAppOverview
>
),
select
:
(
data
)
=>
sortApps
(
data
as
Array
<
MarketplaceAppOverview
>
,
lastFavoriteAppsRef
.
current
),
placeholderData
:
feature
.
isEnabled
?
Array
(
9
).
fill
(
MARKETPLACE_APP
)
:
undefined
,
staleTime
:
Infinity
,
enabled
:
feature
.
isEnabled
,
...
...
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