Skip to content

Commit

Permalink
Only prevent link from opening if never opened before
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacook committed Dec 2, 2024
1 parent 97d4391 commit 691a5a2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ const SafeAppsDashboardSection = () => {
safeApp={rankedSafeApp}
onBookmarkSafeApp={(appId) => togglePin(appId, SAFE_APPS_LABELS.dashboard)}
isBookmarked={pinnedSafeAppIds.has(rankedSafeApp.id)}
onClickSafeApp={() => openPreviewDrawer(rankedSafeApp)}
onClickSafeApp={(e) => {
// Don't open link
e.preventDefault()
openPreviewDrawer(rankedSafeApp)
}}
openPreviewDrawer={openPreviewDrawer}
/>
</Grid>
Expand Down
9 changes: 4 additions & 5 deletions src/components/safe-apps/SafeAppCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import css from './styles.module.css'

type SafeAppCardProps = {
safeApp: SafeAppData
onClickSafeApp?: () => void
onClickSafeApp?: (e: SyntheticEvent) => void
isBookmarked?: boolean
onBookmarkSafeApp?: (safeAppId: number) => void
removeCustomApp?: (safeApp: SafeAppData) => void
Expand Down Expand Up @@ -66,7 +66,7 @@ export const getSafeAppUrl = (router: NextRouter, safeAppUrl: string) => {

type SafeAppCardViewProps = {
safeApp: SafeAppData
onClickSafeApp?: () => void
onClickSafeApp?: (e: SyntheticEvent) => void
safeAppUrl: string
isBookmarked?: boolean
onBookmarkSafeApp?: (safeAppId: number) => void
Expand Down Expand Up @@ -137,7 +137,7 @@ const SafeAppCardGridView = ({
}

type SafeAppCardContainerProps = {
onClickSafeApp?: () => void
onClickSafeApp?: (e: SyntheticEvent) => void
safeAppUrl: string
children: ReactNode
height?: string
Expand All @@ -153,8 +153,7 @@ export const SafeAppCardContainer = ({
}: SafeAppCardContainerProps) => {
const handleClickSafeApp = (event: SyntheticEvent) => {
if (onClickSafeApp) {
event.preventDefault()
onClickSafeApp()
onClickSafeApp(event)
}
}

Expand Down
20 changes: 9 additions & 11 deletions src/components/safe-apps/SafeAppList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback } from 'react'
import { type SyntheticEvent, useCallback } from 'react'
import type { SafeAppData } from '@safe-global/safe-gateway-typescript-sdk'

import SafeAppCard from '@/components/safe-apps/SafeAppCard'
Expand Down Expand Up @@ -46,18 +46,16 @@ const SafeAppList = ({
const showZeroResultsPlaceholder = query && safeAppsList.length === 0

const handleSafeAppClick = useCallback(
(safeApp: SafeAppData) => {
if (openedSafeAppIds.includes(safeApp.id)) {
(e: SyntheticEvent, safeApp: SafeAppData) => {
const isCustomApp = safeApp.id < 1
if (!openedSafeAppIds.includes(safeApp.id) && !isCustomApp) {
// Don't open link
e.preventDefault()
openPreviewDrawer(safeApp)
} else {
// We only track if not previously opened as it is then tracked in preview drawer
trackSafeAppEvent({ ...SAFE_APPS_EVENTS.OPEN_APP, label: eventLabel }, safeApp.name)
return
}

const isCustomApp = safeApp.id < 1

if (isCustomApp) return

openPreviewDrawer(safeApp)
},
[eventLabel, openPreviewDrawer, openedSafeAppIds],
)
Expand Down Expand Up @@ -93,7 +91,7 @@ const SafeAppList = ({
isBookmarked={bookmarkedSafeAppsId?.has(safeApp.id)}
onBookmarkSafeApp={() => togglePin(safeApp.id, eventLabel)}
removeCustomApp={removeCustomApp}
onClickSafeApp={() => handleSafeAppClick(safeApp)}
onClickSafeApp={(e) => handleSafeAppClick(e, safeApp)}
openPreviewDrawer={openPreviewDrawer}
/>
</li>
Expand Down

0 comments on commit 691a5a2

Please sign in to comment.