Skip to content

Commit

Permalink
pull initial values from searchState
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKarow committed Mar 13, 2024
1 parent 7ec48f9 commit fb41c56
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
6 changes: 3 additions & 3 deletions packages/ui/components/core/SearchBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ export const SearchBox = ({
const variants = useCustomVariant()
const { t } = useTranslation()
const router = useRouter()
const form = useForm<FormValues>({ initialValues: { search: initialValue } })
const [search] = useDebouncedValue(form.values.search, 400)
const [locationSearch, setLocationSearch] = useLocationSearch()
const { isLoading, setLoading } = loadingManager
const isOrgSearch = type === 'organization'
const { searchStateActions } = useSearchState()
const { searchStateActions, searchState } = useSearchState()
const form = useForm<FormValues>({ initialValues: { search: searchState.searchTerm || initialValue } })
const [search] = useDebouncedValue(form.values.search, 400)

// tRPC functions
const { data: orgSearchData, isFetching: orgSearchLoading } = api.organization.searchName.useQuery(
Expand Down
10 changes: 2 additions & 8 deletions packages/ui/modals/MoreFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
import { useForm } from '@mantine/form'
import { useMediaQuery, useViewportSize } from '@mantine/hooks'
import { createPolymorphicComponent } from '@mantine/utils'
import { useRouter } from 'next/router'
import { useTranslation } from 'next-i18next'
import { forwardRef, type JSX, type MouseEventHandler, useEffect, useState } from 'react'

Expand Down Expand Up @@ -217,8 +216,7 @@ const MoreFilterBody = forwardRef<HTMLButtonElement, MoreFilterProps>(
const { t } = useTranslation(['common', 'attribute'])
const [opened, setOpened] = useState(false)
const theme = useMantineTheme()
const router = useRouter()
const { searchStateActions } = useSearchState()
const { searchStateActions, searchState } = useSearchState()

const isMobileQuery = useMediaQuery(`(max-width: ${theme.breakpoints.xs})`)
const isLandscape = useMediaQuery(`(orientation: landscape) and (max-height: ${em(430)})`)
Expand All @@ -233,11 +231,7 @@ const MoreFilterBody = forwardRef<HTMLButtonElement, MoreFilterProps>(
type FilterValue = AttributeFilter & { checked: boolean }

const form = useForm<FilterValue[]>({ initialValues: [] })
const preSelected = Array.isArray(router.query.a)
? router.query.a
: typeof router.query.a === 'string'
? [router.query.a]
: []
const preSelected = searchState.attributes

const generateInitialData = (opts?: { clear?: boolean }) => {
if (!moreFilterOptionData) return []
Expand Down
10 changes: 2 additions & 8 deletions packages/ui/modals/ServiceFilter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
Checkbox as VanillaCheckbox,
} from '@mantine/core'
import { useMediaQuery, useViewportSize } from '@mantine/hooks'
import { useRouter } from 'next/router'
import { useTranslation } from 'next-i18next'
import { type BaseSyntheticEvent, type MouseEvent, useEffect, useMemo, useState } from 'react'
import { useForm, useWatch } from 'react-hook-form'
Expand Down Expand Up @@ -44,8 +43,7 @@ export const ServiceFilter = ({ resultCount, isFetching, disabled }: ServiceFilt
const { t } = useTranslation(['common', 'services'])
const [opened, setOpened] = useState(false)
const theme = useMantineTheme()
const router = useRouter()
const { searchStateActions } = useSearchState()
const { searchStateActions, searchState } = useSearchState()

// #region Media Queries
const isMobileQuery = useMediaQuery(`(max-width: ${theme.breakpoints.xs})`)
Expand All @@ -58,11 +56,7 @@ export const ServiceFilter = ({ resultCount, isFetching, disabled }: ServiceFilt
const scrollAreaMaxHeight = isMobile ? viewportHeight - 210 + 30 : viewportHeight * 0.6 - 88
// #endregion

const preSelected = Array.isArray(router.query.s)
? router.query.s
: typeof router.query.s === 'string'
? [router.query.s]
: []
const preSelected = searchState.services
const form = useForm<{ selected: string[] }>({
values: { selected: preSelected },
})
Expand Down

0 comments on commit fb41c56

Please sign in to comment.