Commit 72f54499 authored by Stefan Probst's avatar Stefan Probst
Browse files

fix: remove empty query string

parent 87a5ae54
import { useRouter } from 'next/router'
import { ReactNode, useMemo, useState } from 'react'
import { useAutocompleteItems, useGetItemCategories } from '@/api/sshoc'
import { ItemCategory } from '@/api/sshoc/types'
import { ItemCategory, ItemSearchQuery } from '@/api/sshoc/types'
import { Button } from '@/elements/Button/Button'
import { HighlightedText } from '@/elements/HighlightedText/HighlightedText'
import { useDebouncedState } from '@/lib/hooks/useDebouncedState'
......@@ -26,16 +26,16 @@ export default function ItemSearchForm(
const router = useRouter()
function onSubmit(values: SearchFormValues) {
router.push({
pathname: '/search',
query: {
q: values.q !== undefined && values.q.length > 0 ? values.q : undefined,
categories:
values.category !== undefined && values.category.length > 0
? [values.category]
: undefined,
},
})
const query: ItemSearchQuery = {}
if (values.q !== undefined && values.q.length > 0) {
query.q = values.q
}
if (values.category !== undefined && values.category.length > 0) {
query.categories = [values.category]
}
router.push({ pathname: '/search', query })
}
return (
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment