Skip to content

Commit

Permalink
Fix: safe apps search performance (#3008)
Browse files Browse the repository at this point in the history
* Fix: safe apps search performance

* Lint
  • Loading branch information
katspaugh authored Dec 14, 2023
1 parent b3c9168 commit cbc431d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 1 addition & 5 deletions src/hooks/safe-apps/useSafeAppsFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,14 @@ type ReturnType = {

const useSafeAppsFilters = (safeAppsList: SafeAppData[]): ReturnType => {
const [query, setQuery] = useState<string>('')
const debouncedQuery = useDebounce(query, 400)
const [selectedCategories, setSelectedCategories] = useState<string[]>([])
const [optimizedWithBatchFilter, setOptimizedWithBatchFilter] = useState<boolean>(false)

const filteredAppsByQuery = useAppsSearch(safeAppsList, debouncedQuery)

const filteredAppsByQuery = useAppsSearch(safeAppsList, query)
const filteredAppsByQueryAndCategories = useAppsFilterByCategory(filteredAppsByQuery, selectedCategories)

const filteredApps = useAppsFilterByOptimizedForBatch(filteredAppsByQueryAndCategories, optimizedWithBatchFilter)

const debouncedSearchQuery = useDebounce(query, 2000)

useEffect(() => {
if (debouncedSearchQuery) {
trackSafeAppEvent({ ...SAFE_APPS_EVENTS.SEARCH, label: debouncedSearchQuery })
Expand Down
8 changes: 6 additions & 2 deletions src/pages/apps/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { NextPage } from 'next'
import Head from 'next/head'
import { useRouter } from 'next/router'
import { useEffect, useMemo } from 'react'
import { useCallback, useEffect, useMemo } from 'react'
import debounce from 'lodash/debounce'

import { useSafeApps } from '@/hooks/safe-apps/useSafeApps'
import SafeAppsSDKLink from '@/components/safe-apps/SafeAppsSDKLink'
Expand All @@ -23,6 +24,9 @@ const SafeApps: NextPage = () => {
[remoteSafeApps, pinnedSafeAppIds],
)

// eslint-disable-next-line react-hooks/exhaustive-deps
const onChangeQuery = useCallback(debounce(setQuery, 300), [])

// Redirect to an individual safe app page if the appUrl is in the query params
useEffect(() => {
const appUrl = router.query.appUrl as string
Expand All @@ -44,7 +48,7 @@ const SafeApps: NextPage = () => {
<main>
{/* Safe Apps Filters */}
<SafeAppsFilters
onChangeQuery={setQuery}
onChangeQuery={onChangeQuery}
onChangeFilterCategory={setSelectedCategories}
onChangeOptimizedWithBatch={setOptimizedWithBatchFilter}
selectedCategories={selectedCategories}
Expand Down

0 comments on commit cbc431d

Please sign in to comment.