1- import { BookmarkIcon , XMarkIcon } from '@heroicons/react/24/outline'
1+ import { BookmarkIcon , MagnifyingGlassIcon , XMarkIcon } from '@heroicons/react/24/outline'
22import clsx from 'clsx'
33import { DisplayUser } from 'common/api/user-types'
4- import { FilterFields } from 'common/filters'
4+ import { FilterFields , OriginLocation } from 'common/filters'
55import { formatFilters , locationType } from 'common/filters-format'
66import { User } from 'common/user'
77import { Users } from 'lucide-react'
@@ -19,15 +19,20 @@ import {useMeasurementSystem} from 'web/hooks/use-measurement-system'
1919import { useUser } from 'web/hooks/use-user'
2020import { api } from 'web/lib/api'
2121import { useT } from 'web/lib/locale'
22+ import { track } from 'web/lib/service/analytics'
2223import { deleteBookmarkedSearch } from 'web/lib/supabase/searches'
2324
2425export function BookmarkSearchButton ( props : {
2526 bookmarkedSearches : BookmarkedSearchesType [ ]
2627 refreshBookmarkedSearches : ( ) => void
2728 open : boolean
2829 setOpen : ( checked : boolean ) => void
30+ applySavedSearch ?: (
31+ filters : Partial < FilterFields > ,
32+ location : { location ?: OriginLocation | null ; radius ?: number } | null ,
33+ ) => void
2934} ) {
30- const { bookmarkedSearches, refreshBookmarkedSearches, open, setOpen} = props
35+ const { bookmarkedSearches, refreshBookmarkedSearches, open, setOpen, applySavedSearch } = props
3136 const user = useUser ( )
3237
3338 const t = useT ( )
@@ -51,6 +56,7 @@ export function BookmarkSearchButton(props: {
5156 user = { user }
5257 bookmarkedSearches = { bookmarkedSearches }
5358 refreshBookmarkedSearches = { refreshBookmarkedSearches }
59+ applySavedSearch = { applySavedSearch }
5460 />
5561 </ >
5662 )
@@ -74,8 +80,12 @@ function ButtonModal(props: {
7480 user : User
7581 bookmarkedSearches : BookmarkedSearchesType [ ]
7682 refreshBookmarkedSearches : ( ) => void
83+ applySavedSearch ?: (
84+ filters : Partial < FilterFields > ,
85+ location : { location ?: OriginLocation | null ; radius ?: number } | null ,
86+ ) => void
7787} ) {
78- const { open, setOpen, bookmarkedSearches, refreshBookmarkedSearches} = props
88+ const { open, setOpen, bookmarkedSearches, refreshBookmarkedSearches, applySavedSearch } = props
7989 const t = useT ( )
8090 const choicesIdsToLabels = useChoicesContext ( )
8191 const { measurementSystem} = useMeasurementSystem ( )
@@ -116,6 +126,27 @@ function ButtonModal(props: {
116126 ) ?. join ( ' • ' ) }
117127 </ div >
118128 </ div >
129+ { applySavedSearch && (
130+ < button
131+ data-testid = "apply-saved-search"
132+ onClick = { ( ) => {
133+ applySavedSearch (
134+ ( search . search_filters ?? { } ) as Partial < FilterFields > ,
135+ search . location as {
136+ location ?: OriginLocation | null
137+ radius ?: number
138+ } | null ,
139+ )
140+ track ( 'bookmarked_searches apply' , { id : search . id } )
141+ setOpen ( false )
142+ } }
143+ className = "inline-flex shrink-0 items-center gap-1.5 rounded-lg border border-canvas-300 bg-canvas-0 px-2.5 h-8 text-xs font-medium text-ink-600 hover:border-primary-400 hover:bg-primary-50 hover:text-primary-700 transition-all focus:outline-none focus:ring-2 focus:ring-primary-400 focus:ring-offset-1"
144+ aria-label = { t ( 'saved_searches.apply' , 'Apply this search' ) }
145+ >
146+ < MagnifyingGlassIcon className = "h-4 w-4" />
147+ { t ( 'saved_searches.apply_short' , 'Apply' ) }
148+ </ button >
149+ ) }
119150 < button
120151 onClick = { async ( ) => {
121152 await deleteBookmarkedSearch ( search . id )
0 commit comments