Skip to content

Commit

Permalink
refactor(form): change way of clicking asset thumb
Browse files Browse the repository at this point in the history
  • Loading branch information
RitaDias committed Sep 26, 2024
1 parent eb5f79a commit 4b2a4ee
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export const AssetThumb = memo(function AssetThumb(props: AssetProps) {
const [showUsageDialog, setShowUsageDialog] = useState(false)
const [showDeleteDialog, setShowDeleteDialog] = useState(false)
const [isDeleting, setIsDeleting] = useState(false)
const [isSelectedTemp, setIsSelectedTemp] = useState(false)
const {t} = useTranslation()

useEffect(() => {
Expand Down Expand Up @@ -181,6 +182,16 @@ export const AssetThumb = memo(function AssetThumb(props: AssetProps) {
)
}, [asset, handleDialogClose, showUsageDialog])

const handleImageClick = useCallback(
(event: React.MouseEvent) => {
setIsSelectedTemp(!isSelectedTemp)
if (onClick) {
onClick(event)
}
},
[onClick, setIsSelectedTemp, isSelectedTemp],
)

const deleteDialog = useMemo(() => {
return (
showDeleteDialog && (
Expand Down Expand Up @@ -208,21 +219,21 @@ export const AssetThumb = memo(function AssetThumb(props: AssetProps) {
return (
<Root>
<Button
selected={isSelected}
selected={isSelectedTemp}
tabIndex={0}
data-id={_id}
mode="ghost"
mode={isSelectedTemp ? 'default' : 'ghost'}
onKeyPress={onKeyPress}
padding={0}
style={{padding: 2, background: isSelected ? 'red' : 'transparent'}}
style={{padding: 2}}
>
<Container __unstable_checkered>
<Image alt={originalFilename} src={imageUrl} onClick={onClick} data-id={_id} />
<Image alt={originalFilename} src={imageUrl} onClick={handleImageClick} data-id={_id} />
{isDeleting && <LoadingBlock />}
</Container>
</Button>
<MenuContainer>
<AssetMenu isSelected={isSelected} onAction={handleMenuAction} />
<AssetMenu isSelected={isSelectedTemp} onAction={handleMenuAction} />
</MenuContainer>
{usageDialog || deleteDialog}
</Root>
Expand Down

0 comments on commit 4b2a4ee

Please sign in to comment.