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
f294adcc
Commit
f294adcc
authored
Aug 28, 2024
by
Max Alekseenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reuse CopyToClipboard component
parent
d13bc9f7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
35 deletions
+23
-35
MarketplaceAppCard.tsx
ui/marketplace/MarketplaceAppCard.tsx
+16
-32
CopyToClipboard.tsx
ui/shared/CopyToClipboard.tsx
+7
-3
No files found.
ui/marketplace/MarketplaceAppCard.tsx
View file @
f294adcc
import
{
IconButton
,
Image
,
Link
,
LinkBox
,
Skeleton
,
useColorModeValue
,
chakra
,
Flex
,
Tooltip
,
useClipboard
,
useDisclosure
}
from
'
@chakra-ui/react
'
;
import
{
IconButton
,
Image
,
Link
,
LinkBox
,
Skeleton
,
useColorModeValue
,
chakra
,
Flex
}
from
'
@chakra-ui/react
'
;
import
type
{
MouseEvent
}
from
'
react
'
;
import
type
{
MouseEvent
}
from
'
react
'
;
import
React
,
{
useCallback
,
useState
,
useEffect
}
from
'
react
'
;
import
React
,
{
useCallback
}
from
'
react
'
;
import
type
{
MarketplaceAppWithSecurityReport
,
ContractListTypes
,
AppRating
}
from
'
types/client/marketplace
'
;
import
type
{
MarketplaceAppWithSecurityReport
,
ContractListTypes
,
AppRating
}
from
'
types/client/marketplace
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
isBrowser
from
'
lib/isBrowser
'
;
import
isBrowser
from
'
lib/isBrowser
'
;
import
IconSvg
from
'
ui/shared/IconSvg
'
;
import
CopyToClipboard
from
'
ui/shared/CopyToClipboard
'
;
import
AppSecurityReport
from
'
./AppSecurityReport
'
;
import
AppSecurityReport
from
'
./AppSecurityReport
'
;
import
FavoriteIcon
from
'
./FavoriteIcon
'
;
import
FavoriteIcon
from
'
./FavoriteIcon
'
;
...
@@ -58,20 +58,6 @@ const MarketplaceAppCard = ({
...
@@ -58,20 +58,6 @@ const MarketplaceAppCard = ({
const
isMobile
=
useIsMobile
();
const
isMobile
=
useIsMobile
();
const
categoriesLabel
=
categories
.
join
(
'
,
'
);
const
categoriesLabel
=
categories
.
join
(
'
,
'
);
const
linkToApp
=
isBrowser
()
?
window
.
location
.
origin
+
`/apps/
${
id
}
`
:
''
;
const
{
hasCopied
,
onCopy
}
=
useClipboard
(
linkToApp
,
1000
);
const
[
copied
,
setCopied
]
=
useState
(
false
);
// have to implement controlled tooltip because of the issue - https://github.com/chakra-ui/chakra-ui/issues/7107
const
{
isOpen
,
onOpen
,
onClose
}
=
useDisclosure
();
useEffect
(()
=>
{
if
(
hasCopied
)
{
setCopied
(
true
);
}
else
{
setCopied
(
false
);
}
},
[
hasCopied
]);
const
handleInfoClick
=
useCallback
((
event
:
MouseEvent
)
=>
{
const
handleInfoClick
=
useCallback
((
event
:
MouseEvent
)
=>
{
event
.
preventDefault
();
event
.
preventDefault
();
onInfoClick
(
id
);
onInfoClick
(
id
);
...
@@ -199,27 +185,25 @@ const MarketplaceAppCard = ({
...
@@ -199,27 +185,25 @@ const MarketplaceAppCard = ({
aria
-
label=
"Mark as favorite"
aria
-
label=
"Mark as favorite"
title=
"Mark as favorite"
title=
"Mark as favorite"
variant=
"ghost"
variant=
"ghost"
colorScheme=
"gray"
w=
{
{
base
:
6
,
md
:
'
30px
'
}
}
w=
{
{
base
:
6
,
md
:
'
30px
'
}
}
h=
{
{
base
:
6
,
md
:
'
30px
'
}
}
h=
{
{
base
:
6
,
md
:
'
30px
'
}
}
onClick=
{
handleFavoriteClick
}
onClick=
{
handleFavoriteClick
}
icon=
{
<
FavoriteIcon
isFavorite=
{
isFavorite
}
/>
}
icon=
{
<
FavoriteIcon
isFavorite=
{
isFavorite
}
/>
}
ml=
{
2
}
ml=
{
2
}
/>
/>
<
Tooltip
label=
{
copied
?
'
Copied
'
:
'
Copy link to clipboard
'
}
isOpen=
{
isOpen
||
copied
}
>
<
CopyToClipboard
<
IconButton
text=
{
isBrowser
()
?
window
.
location
.
origin
+
`/apps/${ id }`
:
''
}
aria
-
label=
"Copy link"
icon=
"share"
variant=
"ghost"
size=
{
4
}
colorScheme=
"gray"
variant=
"ghost"
w=
{
{
base
:
6
,
md
:
'
30px
'
}
}
w=
{
{
base
:
6
,
md
:
'
30px
'
}
}
h=
{
{
base
:
6
,
md
:
'
30px
'
}
}
h=
{
{
base
:
6
,
md
:
'
30px
'
}
}
onClick=
{
onCopy
}
color=
"gray.400"
onMouseEnter=
{
onOpen
}
_hover=
{
{
color
:
'
gray.400
'
}
}
onMouseLeave=
{
onClose
}
ml=
{
{
base
:
1
,
md
:
0
}
}
icon=
{
<
IconSvg
name=
"share"
boxSize=
{
4
}
color=
"gray.400"
/>
}
display=
"inline-flex"
ml=
{
{
base
:
1
,
md
:
0
}
}
borderRadius=
"base"
/>
/>
</
Tooltip
>
</
Flex
>
</
Flex
>
</
Flex
>
</
Flex
>
)
}
)
}
...
...
ui/shared/CopyToClipboard.tsx
View file @
f294adcc
import
{
IconButton
,
Tooltip
,
useClipboard
,
chakra
,
useDisclosure
,
Skeleton
,
useColorModeValue
}
from
'
@chakra-ui/react
'
;
import
{
IconButton
,
Tooltip
,
useClipboard
,
chakra
,
useDisclosure
,
Skeleton
,
useColorModeValue
}
from
'
@chakra-ui/react
'
;
import
React
,
{
useEffect
,
useState
}
from
'
react
'
;
import
React
,
{
useEffect
,
useState
}
from
'
react
'
;
import
type
{
IconName
}
from
'
ui/shared/IconSvg
'
;
import
IconSvg
from
'
ui/shared/IconSvg
'
;
import
IconSvg
from
'
ui/shared/IconSvg
'
;
export
interface
Props
{
export
interface
Props
{
...
@@ -10,14 +11,17 @@ export interface Props {
...
@@ -10,14 +11,17 @@ export interface Props {
onClick
?:
(
event
:
React
.
MouseEvent
)
=>
void
;
onClick
?:
(
event
:
React
.
MouseEvent
)
=>
void
;
size
?:
number
;
size
?:
number
;
type
?:
'
link
'
;
type
?:
'
link
'
;
icon
?:
IconName
;
variant
?:
'
simple
'
;
}
}
const
CopyToClipboard
=
({
text
,
className
,
isLoading
,
onClick
,
size
=
5
,
type
}:
Props
)
=>
{
const
CopyToClipboard
=
({
text
,
className
,
isLoading
,
onClick
,
size
=
5
,
type
,
icon
,
variant
}:
Props
)
=>
{
const
{
hasCopied
,
onCopy
}
=
useClipboard
(
text
,
1000
);
const
{
hasCopied
,
onCopy
}
=
useClipboard
(
text
,
1000
);
const
[
copied
,
setCopied
]
=
useState
(
false
);
const
[
copied
,
setCopied
]
=
useState
(
false
);
// have to implement controlled tooltip because of the issue - https://github.com/chakra-ui/chakra-ui/issues/7107
// have to implement controlled tooltip because of the issue - https://github.com/chakra-ui/chakra-ui/issues/7107
const
{
isOpen
,
onOpen
,
onClose
}
=
useDisclosure
();
const
{
isOpen
,
onOpen
,
onClose
}
=
useDisclosure
();
const
iconColor
=
useColorModeValue
(
'
gray.400
'
,
'
gray.500
'
);
const
iconColor
=
useColorModeValue
(
'
gray.400
'
,
'
gray.500
'
);
const
iconName
=
icon
||
(
type
===
'
link
'
?
'
link
'
:
'
copy
'
);
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
hasCopied
)
{
if
(
hasCopied
)
{
...
@@ -40,10 +44,10 @@ const CopyToClipboard = ({ text, className, isLoading, onClick, size = 5, type }
...
@@ -40,10 +44,10 @@ const CopyToClipboard = ({ text, className, isLoading, onClick, size = 5, type }
<
Tooltip
label=
{
copied
?
'
Copied
'
:
`Copy${ type === 'link' ? ' link ' : ' ' }to clipboard`
}
isOpen=
{
isOpen
||
copied
}
>
<
Tooltip
label=
{
copied
?
'
Copied
'
:
`Copy${ type === 'link' ? ' link ' : ' ' }to clipboard`
}
isOpen=
{
isOpen
||
copied
}
>
<
IconButton
<
IconButton
aria
-
label=
"copy"
aria
-
label=
"copy"
icon=
{
<
IconSvg
name=
{
type
===
'
link
'
?
'
link
'
:
'
copy
'
}
boxSize=
{
size
}
/>
}
icon=
{
<
IconSvg
name=
{
iconName
}
boxSize=
{
size
}
/>
}
boxSize=
{
size
}
boxSize=
{
size
}
color=
{
iconColor
}
color=
{
iconColor
}
variant=
"simple"
variant=
{
variant
}
display=
"inline-block"
display=
"inline-block"
flexShrink=
{
0
}
flexShrink=
{
0
}
onClick=
{
handleClick
}
onClick=
{
handleClick
}
...
...
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