Skip to content

Commit

Permalink
fix: Open custom safe apps on click (#2350)
Browse files Browse the repository at this point in the history
  • Loading branch information
usame-algan authored Aug 7, 2023
1 parent beae29d commit bd9118c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
13 changes: 4 additions & 9 deletions src/components/safe-apps/SafeAppCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import SafeAppTags from '@/components/safe-apps/SafeAppTags'
import { isOptimizedForBatchTransactions } from '@/components/safe-apps/utils'
import { AppRoutes } from '@/config/routes'
import BatchIcon from '@/public/images/apps/batch-icon.svg'
import { useOpenedSafeApps } from '@/hooks/safe-apps/useOpenedSafeApps'
import css from './styles.module.css'

export type SafeAppsViewMode = 'list-view' | 'grid-view'
Expand Down Expand Up @@ -111,7 +110,7 @@ const SafeAppCardGridView = ({
openPreviewDrawer,
}: SafeAppCardViewProps) => {
return (
<SafeAppCardContainer safeApp={safeApp} safeAppUrl={safeAppUrl} onClickSafeApp={onClickSafeApp} height={'100%'}>
<SafeAppCardContainer safeAppUrl={safeAppUrl} onClickSafeApp={onClickSafeApp} height={'100%'}>
{/* Safe App Header */}
<CardHeader
className={css.safeAppHeader}
Expand Down Expand Up @@ -168,7 +167,7 @@ const SafeAppCardListView = ({
openPreviewDrawer,
}: SafeAppCardViewProps) => {
return (
<SafeAppCardContainer safeApp={safeApp} safeAppUrl={safeAppUrl} onClickSafeApp={onClickSafeApp}>
<SafeAppCardContainer safeAppUrl={safeAppUrl} onClickSafeApp={onClickSafeApp}>
<CardContent sx={{ pb: '16px !important' }}>
<Box display="flex" flexDirection="row" alignItems="center" gap={2}>
<div className={css.safeAppIconContainer}>
Expand Down Expand Up @@ -204,7 +203,6 @@ const SafeAppCardListView = ({

type SafeAppCardContainerProps = {
onClickSafeApp?: () => void
safeApp?: SafeAppData
safeAppUrl: string
children: ReactNode
height?: string
Expand All @@ -213,18 +211,15 @@ type SafeAppCardContainerProps = {

export const SafeAppCardContainer = ({
children,
safeApp,
safeAppUrl,
onClickSafeApp,
height,
className,
}: SafeAppCardContainerProps) => {
const { openedSafeAppIds } = useOpenedSafeApps()

const handleClickSafeApp = (event: SyntheticEvent) => {
if (safeApp && !openedSafeAppIds.includes(safeApp.id)) {
if (onClickSafeApp) {
event.preventDefault()
onClickSafeApp?.()
onClickSafeApp()
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/components/safe-apps/SafeAppList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import useSafeAppPreviewDrawer from '@/hooks/safe-apps/useSafeAppPreviewDrawer'
import css from './styles.module.css'
import { Skeleton } from '@mui/material'
import useLocalStorage from '@/services/local-storage/useLocalStorage'
import { useOpenedSafeApps } from '@/hooks/safe-apps/useOpenedSafeApps'

type SafeAppListProps = {
safeAppsList: SafeAppData[]
Expand All @@ -38,6 +39,7 @@ const SafeAppList = ({
}: SafeAppListProps) => {
const [safeAppsViewMode = GRID_VIEW_MODE, setSafeAppsViewMode] = useLocalStorage<SafeAppsViewMode>(VIEW_MODE_KEY)
const { isPreviewDrawerOpen, previewDrawerApp, openPreviewDrawer, closePreviewDrawer } = useSafeAppPreviewDrawer()
const { openedSafeAppIds } = useOpenedSafeApps()

const { filteredApps, query, setQuery, setSelectedCategories, setOptimizedWithBatchFilter, selectedCategories } =
useSafeAppsFilters(safeAppsList)
Expand All @@ -48,11 +50,11 @@ const SafeAppList = ({
(safeApp: SafeAppData) => {
const isCustomApp = safeApp.id < 1

if (isCustomApp) return
if (isCustomApp || openedSafeAppIds.includes(safeApp.id)) return

return () => openPreviewDrawer(safeApp)
},
[openPreviewDrawer],
[openPreviewDrawer, openedSafeAppIds],
)

return (
Expand Down

0 comments on commit bd9118c

Please sign in to comment.