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
63c6107b
Unverified
Commit
63c6107b
authored
Jan 30, 2024
by
Max Alekseenko
Committed by
GitHub
Jan 30, 2024
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1543 from blockscout/category-tabs
New category tabs
parents
878cb938
3d8e3986
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
100 additions
and
15 deletions
+100
-15
ABI_slim.svg
icons/ABI_slim.svg
+2
-2
marketplace.ts
types/client/marketplace.ts
+1
-1
MarketplaceList.tsx
ui/marketplace/MarketplaceList.tsx
+19
-2
useMarketplace.tsx
ui/marketplace/useMarketplace.tsx
+10
-3
Marketplace.tsx
ui/pages/Marketplace.tsx
+67
-6
EmptySearchResult.tsx
ui/shared/EmptySearchResult.tsx
+1
-1
No files found.
icons/ABI_slim.svg
View file @
63c6107b
<svg
xmlns=
"http://www.w3.org/2000/svg"
viewBox=
"0 0 20 20"
fill=
"none"
>
<svg
xmlns=
"http://www.w3.org/2000/svg"
viewBox=
"0 0 20 20"
fill=
"none"
>
<g
clip-path=
"url(#a)"
fill=
"currentColor"
>
<g
clip-path=
"url(#a)"
fill=
"currentColor"
>
<path
d=
"M5.176 5.291a1.253 1.253 0 0 0-1.76.159L.29 9.2a1.247 1.247 0 0 0 0 1.6l3.125 3.75a1.25 1.25 0 1 0 1.919-1.6L2.876 10l2.459-2.949a1.25 1.25 0 0 0-.159-1.76Z"
/>
<path
d=
"M5.176 5.291a1.253 1.253 0 0 0-1.76.159L.29 9.2a1.247 1.247 0 0 0 0 1.6l3.125 3.75a1.25 1.25 0 1 0 1.919-1.6L2.876 10l2.459-2.949a1.25 1.25 0 0 0-.159-1.76Z"
/>
<path
d=
"M5.176 5.291a1.253 1.253 0 0 0-1.76.159L.29 9.2a1.247 1.247 0 0 0 0 1.6l3.125 3.75a1.25 1.25 0 1 0 1.919-1.6L2.876 10l2.459-2.949a1.25 1.25 0 0 0-.159-1.76Z
M11.494 2.525a1.261 1.261 0 0 0-1.47.981l-2.5 12.5A1.247 1.247 0 0 0 8.754 17.5a
1.249 1.249 0 0 0 1.223-1.006l2.5-12.5a1.246 1.246 0 0 0-.982-1.469Z"
/>
<path
d=
"M5.176 5.291a1.253 1.253 0 0 0-1.76.159L.29 9.2a1.247 1.247 0 0 0 0 1.6l3.125 3.75a1.25 1.25 0 1 0 1.919-1.6L2.876 10l2.459-2.949a1.25 1.25 0 0 0-.159-1.76Z
m6.318-2.766a1.261 1.261 0 0 0-1.47.981l-2.5 12.5a1.247 1.247 0 0 0 1.23 1.494
1.249 1.249 0 0 0 1.223-1.006l2.5-12.5a1.246 1.246 0 0 0-.982-1.469Z"
/>
<path
d=
"M11.494 2.525a1.261 1.261 0 0 0-1.47.981l-2.5 12.5
A1.247 1.247 0 0 0 8.754 17.5a
1.249 1.249 0 0 0 1.223-1.006l2.5-12.5a1.246 1.246 0 0 0-.982-1.469ZM19.708 9.2l-3.124-3.75a1.249 1.249 0 1 0-1.92 1.601l2.46 2.95-2.46 2.948a1.25 1.25 0 1 0 1.92 1.602l3.124-3.75a1.246 1.246 0 0 0 0-1.601Z"
/>
<path
d=
"M11.494 2.525a1.261 1.261 0 0 0-1.47.981l-2.5 12.5
a1.247 1.247 0 0 0 1.23 1.494
1.249 1.249 0 0 0 1.223-1.006l2.5-12.5a1.246 1.246 0 0 0-.982-1.469ZM19.708 9.2l-3.124-3.75a1.249 1.249 0 1 0-1.92 1.601l2.46 2.95-2.46 2.948a1.25 1.25 0 1 0 1.92 1.602l3.124-3.75a1.246 1.246 0 0 0 0-1.601Z"
/>
<path
d=
"m19.708 9.2-3.124-3.75a1.249 1.249 0 1 0-1.92 1.601l2.46 2.95-2.46 2.948a1.25 1.25 0 1 0 1.92 1.602l3.124-3.75a1.246 1.246 0 0 0 0-1.601Z"
/>
<path
d=
"m19.708 9.2-3.124-3.75a1.249 1.249 0 1 0-1.92 1.601l2.46 2.95-2.46 2.948a1.25 1.25 0 1 0 1.92 1.602l3.124-3.75a1.246 1.246 0 0 0 0-1.601Z"
/>
</g>
</g>
<defs>
<defs>
...
...
types/client/marketplace.ts
View file @
63c6107b
...
@@ -20,6 +20,6 @@ export type MarketplaceAppOverview = MarketplaceAppPreview & {
...
@@ -20,6 +20,6 @@ export type MarketplaceAppOverview = MarketplaceAppPreview & {
}
}
export
enum
MarketplaceCategory
{
export
enum
MarketplaceCategory
{
ALL
=
'
All
apps
'
,
ALL
=
'
All
'
,
FAVORITES
=
'
Favorites
'
,
FAVORITES
=
'
Favorites
'
,
}
}
ui/marketplace/MarketplaceList.tsx
View file @
63c6107b
...
@@ -2,9 +2,12 @@ import { Grid } from '@chakra-ui/react';
...
@@ -2,9 +2,12 @@ import { Grid } from '@chakra-ui/react';
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
type
{
MarketplaceAppPreview
}
from
'
types/client/marketplace
'
;
import
type
{
MarketplaceAppPreview
}
from
'
types/client/marketplace
'
;
import
{
MarketplaceCategory
}
from
'
types/client/marketplace
'
;
import
useFeatureValue
from
'
lib/growthbook/useFeatureValue
'
;
import
{
apos
}
from
'
lib/html-entities
'
;
import
{
apos
}
from
'
lib/html-entities
'
;
import
EmptySearchResult
from
'
ui/shared/EmptySearchResult
'
;
import
EmptySearchResult
from
'
ui/shared/EmptySearchResult
'
;
import
IconSvg
from
'
ui/shared/IconSvg
'
;
import
MarketplaceAppCard
from
'
./MarketplaceAppCard
'
;
import
MarketplaceAppCard
from
'
./MarketplaceAppCard
'
;
...
@@ -15,9 +18,12 @@ type Props = {
...
@@ -15,9 +18,12 @@ type Props = {
onFavoriteClick
:
(
id
:
string
,
isFavorite
:
boolean
)
=>
void
;
onFavoriteClick
:
(
id
:
string
,
isFavorite
:
boolean
)
=>
void
;
isLoading
:
boolean
;
isLoading
:
boolean
;
showDisclaimer
:
(
id
:
string
)
=>
void
;
showDisclaimer
:
(
id
:
string
)
=>
void
;
selectedCategoryId
?:
string
;
}
}
const
MarketplaceList
=
({
apps
,
onAppClick
,
favoriteApps
,
onFavoriteClick
,
isLoading
,
showDisclaimer
}:
Props
)
=>
{
const
MarketplaceList
=
({
apps
,
onAppClick
,
favoriteApps
,
onFavoriteClick
,
isLoading
,
showDisclaimer
,
selectedCategoryId
}:
Props
)
=>
{
const
{
value
:
isExperiment
}
=
useFeatureValue
(
'
marketplace_exp
'
,
false
);
return
apps
.
length
>
0
?
(
return
apps
.
length
>
0
?
(
<
Grid
<
Grid
templateColumns=
{
{
templateColumns=
{
{
...
@@ -48,7 +54,18 @@ const MarketplaceList = ({ apps, onAppClick, favoriteApps, onFavoriteClick, isLo
...
@@ -48,7 +54,18 @@ const MarketplaceList = ({ apps, onAppClick, favoriteApps, onFavoriteClick, isLo
))
}
))
}
</
Grid
>
</
Grid
>
)
:
(
)
:
(
<
EmptySearchResult
text=
{
`Couldn${ apos }t find an app that matches your filter query.`
}
/>
<
EmptySearchResult
text=
{
(
selectedCategoryId
===
MarketplaceCategory
.
FAVORITES
&&
!
favoriteApps
.
length
&&
isExperiment
)
?
(
<>
You don
{
apos
}
t have any favorite apps.
Click on the
<
IconSvg
name=
"star_outline"
w=
{
4
}
h=
{
4
}
mb=
{
-
0.5
}
/>
icon on the app
{
apos
}
s card to add it to Favorites.
</>
)
:
(
`Couldn${ apos }t find an app that matches your filter query.`
)
}
/>
);
);
};
};
...
...
ui/marketplace/useMarketplace.tsx
View file @
63c6107b
import
_groudBy
from
'
lodash/groupBy
'
;
import
_pickBy
from
'
lodash/pickBy
'
;
import
_pickBy
from
'
lodash/pickBy
'
;
import
_unique
from
'
lodash/uniq
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
...
@@ -74,7 +74,12 @@ export default function useMarketplace() {
...
@@ -74,7 +74,12 @@ export default function useMarketplace() {
const
{
isPlaceholderData
,
isError
,
error
,
data
,
displayedApps
}
=
useMarketplaceApps
(
debouncedFilterQuery
,
selectedCategoryId
,
favoriteApps
);
const
{
isPlaceholderData
,
isError
,
error
,
data
,
displayedApps
}
=
useMarketplaceApps
(
debouncedFilterQuery
,
selectedCategoryId
,
favoriteApps
);
const
categories
=
React
.
useMemo
(()
=>
{
const
categories
=
React
.
useMemo
(()
=>
{
return
_unique
(
data
?.
map
(
app
=>
app
.
categories
).
flat
())
||
[];
const
grouped
=
_groudBy
(
data
,
app
=>
app
.
categories
);
return
Object
.
keys
(
grouped
).
map
(
category
=>
({
name
:
category
,
count
:
grouped
[
category
].
length
,
}));
// return _unique(data?.map(app => app.categories).flat()) || [];
},
[
data
]);
},
[
data
]);
React
.
useEffect
(()
=>
{
React
.
useEffect
(()
=>
{
...
@@ -83,7 +88,7 @@ export default function useMarketplace() {
...
@@ -83,7 +88,7 @@ export default function useMarketplace() {
React
.
useEffect
(()
=>
{
React
.
useEffect
(()
=>
{
if
(
!
isPlaceholderData
&&
!
isError
)
{
if
(
!
isPlaceholderData
&&
!
isError
)
{
const
isValidDefaultCategory
=
categories
.
includes
(
defaultCategoryId
);
const
isValidDefaultCategory
=
categories
.
map
(
c
=>
c
.
name
).
includes
(
defaultCategoryId
);
isValidDefaultCategory
&&
setSelectedCategoryId
(
defaultCategoryId
);
isValidDefaultCategory
&&
setSelectedCategoryId
(
defaultCategoryId
);
}
}
// run only when data is loaded
// run only when data is loaded
...
@@ -128,6 +133,7 @@ export default function useMarketplace() {
...
@@ -128,6 +133,7 @@ export default function useMarketplace() {
isAppInfoModalOpen
,
isAppInfoModalOpen
,
isDisclaimerModalOpen
,
isDisclaimerModalOpen
,
showDisclaimer
,
showDisclaimer
,
appsTotal
:
data
?.
length
||
0
,
}),
[
}),
[
selectedCategoryId
,
selectedCategoryId
,
categories
,
categories
,
...
@@ -145,5 +151,6 @@ export default function useMarketplace() {
...
@@ -145,5 +151,6 @@ export default function useMarketplace() {
isAppInfoModalOpen
,
isAppInfoModalOpen
,
isDisclaimerModalOpen
,
isDisclaimerModalOpen
,
showDisclaimer
,
showDisclaimer
,
data
?.
length
,
]);
]);
}
}
ui/pages/Marketplace.tsx
View file @
63c6107b
import
{
Box
}
from
'
@chakra-ui/react
'
;
import
{
Box
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
{
MarketplaceCategory
}
from
'
types/client/marketplace
'
;
import
type
{
TabItem
}
from
'
ui/shared/Tabs/types
'
;
import
config
from
'
configs/app
'
;
import
config
from
'
configs/app
'
;
import
throwOnResourceLoadError
from
'
lib/errors/throwOnResourceLoadError
'
;
import
throwOnResourceLoadError
from
'
lib/errors/throwOnResourceLoadError
'
;
import
useFeatureValue
from
'
lib/growthbook/useFeatureValue
'
;
import
MarketplaceAppModal
from
'
ui/marketplace/MarketplaceAppModal
'
;
import
MarketplaceAppModal
from
'
ui/marketplace/MarketplaceAppModal
'
;
import
MarketplaceCategoriesMenu
from
'
ui/marketplace/MarketplaceCategoriesMenu
'
;
import
MarketplaceCategoriesMenu
from
'
ui/marketplace/MarketplaceCategoriesMenu
'
;
import
MarketplaceDisclaimerModal
from
'
ui/marketplace/MarketplaceDisclaimerModal
'
;
import
MarketplaceDisclaimerModal
from
'
ui/marketplace/MarketplaceDisclaimerModal
'
;
import
MarketplaceList
from
'
ui/marketplace/MarketplaceList
'
;
import
MarketplaceList
from
'
ui/marketplace/MarketplaceList
'
;
import
FilterInput
from
'
ui/shared/filters/FilterInput
'
;
import
FilterInput
from
'
ui/shared/filters/FilterInput
'
;
import
IconSvg
from
'
ui/shared/IconSvg
'
;
import
TabsSkeleton
from
'
ui/shared/Tabs/TabsSkeleton
'
;
import
TabsWithScroll
from
'
ui/shared/Tabs/TabsWithScroll
'
;
import
useMarketplace
from
'
../marketplace/useMarketplace
'
;
import
useMarketplace
from
'
../marketplace/useMarketplace
'
;
const
feature
=
config
.
features
.
marketplace
;
const
feature
=
config
.
features
.
marketplace
;
...
@@ -31,8 +38,45 @@ const Marketplace = () => {
...
@@ -31,8 +38,45 @@ const Marketplace = () => {
isAppInfoModalOpen
,
isAppInfoModalOpen
,
isDisclaimerModalOpen
,
isDisclaimerModalOpen
,
showDisclaimer
,
showDisclaimer
,
appsTotal
,
}
=
useMarketplace
();
}
=
useMarketplace
();
const
{
value
:
isExperiment
}
=
useFeatureValue
(
'
marketplace_exp
'
,
false
);
const
categoryTabs
=
React
.
useMemo
(()
=>
{
const
tabs
:
Array
<
TabItem
>
=
categories
.
map
(
category
=>
({
id
:
category
.
name
,
title
:
category
.
name
,
count
:
category
.
count
,
component
:
null
,
}));
tabs
.
unshift
({
id
:
MarketplaceCategory
.
ALL
,
title
:
MarketplaceCategory
.
ALL
,
count
:
appsTotal
,
component
:
null
,
});
tabs
.
unshift
({
id
:
MarketplaceCategory
.
FAVORITES
,
title
:
()
=>
<
IconSvg
name=
"star_outline"
w=
{
4
}
h=
{
4
}
/>,
count
:
null
,
component
:
null
,
});
return
tabs
;
},
[
categories
,
appsTotal
]);
const
selectedCategoryIndex
=
React
.
useMemo
(()
=>
{
const
index
=
categoryTabs
.
findIndex
(
c
=>
c
.
id
===
selectedCategoryId
);
return
index
===
-
1
?
0
:
index
;
},
[
categoryTabs
,
selectedCategoryId
]);
const
handleCategoryChange
=
React
.
useCallback
((
index
:
number
)
=>
{
onCategoryChange
(
categoryTabs
[
index
].
id
);
},
[
categoryTabs
,
onCategoryChange
]);
throwOnResourceLoadError
(
isError
&&
error
?
{
isError
,
error
}
:
{
isError
:
false
,
error
:
null
});
throwOnResourceLoadError
(
isError
&&
error
?
{
isError
,
error
}
:
{
isError
:
false
,
error
:
null
});
if
(
!
feature
.
isEnabled
)
{
if
(
!
feature
.
isEnabled
)
{
...
@@ -43,16 +87,32 @@ const Marketplace = () => {
...
@@ -43,16 +87,32 @@ const Marketplace = () => {
return
(
return
(
<>
<>
{
isExperiment
&&
(
<
Box
marginTop=
{
{
base
:
0
,
lg
:
8
}
}
>
{
isPlaceholderData
?
(
<
TabsSkeleton
tabs=
{
categoryTabs
}
/>
)
:
(
<
TabsWithScroll
tabs=
{
categoryTabs
}
onTabChange=
{
handleCategoryChange
}
defaultTabIndex=
{
selectedCategoryIndex
}
marginBottom=
{
{
base
:
0
,
lg
:
-
2
}
}
/>
)
}
</
Box
>
)
}
<
Box
<
Box
display=
"flex"
display=
"flex"
flexDirection=
{
{
base
:
'
column
'
,
sm
:
'
row
'
}
}
flexDirection=
{
{
base
:
'
column
'
,
sm
:
'
row
'
}
}
>
>
<
MarketplaceCategoriesMenu
{
!
isExperiment
&&
(
categories=
{
categories
}
<
MarketplaceCategoriesMenu
selectedCategoryId=
{
selectedCategoryId
}
categories=
{
categories
.
map
(
c
=>
c
.
name
)
}
onSelect=
{
onCategoryChange
}
selectedCategoryId=
{
selectedCategoryId
}
isLoading=
{
isPlaceholderData
}
onSelect=
{
onCategoryChange
}
/>
isLoading=
{
isPlaceholderData
}
/>
)
}
<
FilterInput
<
FilterInput
initialValue=
{
filterQuery
}
initialValue=
{
filterQuery
}
...
@@ -71,6 +131,7 @@ const Marketplace = () => {
...
@@ -71,6 +131,7 @@ const Marketplace = () => {
onFavoriteClick=
{
onFavoriteClick
}
onFavoriteClick=
{
onFavoriteClick
}
isLoading=
{
isPlaceholderData
}
isLoading=
{
isPlaceholderData
}
showDisclaimer=
{
showDisclaimer
}
showDisclaimer=
{
showDisclaimer
}
selectedCategoryId=
{
selectedCategoryId
}
/>
/>
{
(
selectedApp
&&
isAppInfoModalOpen
)
&&
(
{
(
selectedApp
&&
isAppInfoModalOpen
)
&&
(
...
...
ui/shared/EmptySearchResult.tsx
View file @
63c6107b
...
@@ -4,7 +4,7 @@ import React from 'react';
...
@@ -4,7 +4,7 @@ import React from 'react';
import
IconSvg
from
'
ui/shared/IconSvg
'
;
import
IconSvg
from
'
ui/shared/IconSvg
'
;
interface
Props
{
interface
Props
{
text
:
string
;
text
:
string
|
JSX
.
Element
;
}
}
const
EmptySearchResult
=
({
text
}:
Props
)
=>
{
const
EmptySearchResult
=
({
text
}:
Props
)
=>
{
...
...
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