Skip to content

Commit

Permalink
chore: fix-search-query-value-in-breadcrumbs
Browse files Browse the repository at this point in the history
#2246 fix search query value in breadcrumbs
  • Loading branch information
rupali-codes authored Feb 9, 2024
2 parents cd94f1f + 5c0473b commit 2f1f7e3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion components/Breadcrumps/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const BreadCrumbs: React.FC<ComponentProps> = ({ sections }) => {
href={section.url}
className="flex gap-x-2 bg-theme-quinary bg-opacity-20 text-text-primary-light dark:text-text-quaternary text-lg py-0.5 px-2.5 rounded-lg capitalize cursor-pointer"
>
{section.name}
{section.name?.split('-').join(' ')}
</Link>
))}
</div>
Expand Down
24 changes: 16 additions & 8 deletions components/Searchbar/Searchbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,23 @@ export const Searchbar: React.FC<SearchbarProps> = ({

const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()

dispatchSearch({ type: 'submit' })
if (searchQuery.trim() !== '') {
router.push({
pathname: '/search',
query: {
query: searchQuery,
},
})
const cleanedSearchQuery = searchQuery.toLocaleLowerCase().trim()
if (cleanedSearchQuery !== '') {
const { category } = sidebarData.find((item) =>
item.subcategory.find((subCat) => subCat.name === cleanedSearchQuery)
) || { category: '' }

if (category != '') {
router.push(`/${category}/${cleanedSearchQuery}`)
} else {
router.push({
pathname: '/search',
query: {
query: searchQuery,
},
})
}
}
}

Expand Down
7 changes: 4 additions & 3 deletions components/TopBar/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ export const TopBar: FC<TopBarProps> = ({}) => {
const { theme } = useTheme()

const category = router.asPath
const categoryName = category.split('/')[1]
const subcategoryName = category?.split('/')[2]
const categoryName = category?.split('/')[1]?.split('-').join(' ')
const subcategoryName = category?.split('/')[2]?.split('-').join(' ')

const searchQuery = router.query.query?.toString() || ''

let cleanedCategory = ''
Expand Down Expand Up @@ -63,7 +64,7 @@ export const TopBar: FC<TopBarProps> = ({}) => {
<IoIosArrowBack className="md:hidden" />
</Link>
<div className="md:bg-[#EDEDED] md:bg-opacity-20 px-[10px] py-[6px] text-xl md:text-base rounded-md truncate ...">
<h3>{capitalizeEachWord(cleanedCategory.split('-').join(' '))}</h3>
<h3>{capitalizeEachWord(cleanedCategory)}</h3>
</div>
<button>
<FaInfoCircle
Expand Down

0 comments on commit 2f1f7e3

Please sign in to comment.