Skip to content

Commit

Permalink
🚸 Improved UX
Browse files Browse the repository at this point in the history
If you were in page let's say 27 and then clicked on a tab item to
search for that topic, the query params would perform a `&` so most
likely there are no video of ZK (for example) in page 27.

The improvement consists on redoing the URL to it only matches the
topic, giving it priority over the page number.
  • Loading branch information
Mario-SO committed Jul 24, 2024
1 parent a2adad6 commit b23a524
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions packages/app/app/explore/components/ExploreTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
'use client'
import {
Tabs,
TabsTrigger,
TabsList,
TabsContent,
} from '@/components/ui/tabs'
import { Tabs, TabsTrigger, TabsList } from '@/components/ui/tabs'
import useSearchParams from '@/lib/hooks/useSearchParams'
import { useRouter } from 'next/navigation'

const ExploreTabs = () => {
const { handleTermChange, searchParams } = useSearchParams()
const router = useRouter()
const currentTerm = searchParams.get('searchQuery') || ''

const tabData = [
{ name: 'All', searchQuery: '' },
{ name: 'Home', searchQuery: '' },
{ name: 'Vitalik', searchQuery: 'vitalik' },
{ name: 'Zk', searchQuery: 'zk' },
{ name: 'Identity', searchQuery: 'identity' },
Expand All @@ -22,13 +19,20 @@ const ExploreTabs = () => {
{ name: 'Cryptography', searchQuery: 'cryptography' },
]

const handleTabChange = (value: string) => {
const newParams = new URLSearchParams(searchParams)
newParams.set('searchQuery', value)
newParams.delete('page')

const newUrl = `${window.location.pathname}?${newParams.toString()}`
router.push(newUrl)
}

return (
<Tabs
defaultValue={currentTerm}
className="w-full"
onValueChange={(value) =>
handleTermChange([{ key: 'searchQuery', value }])
}>
onValueChange={handleTabChange}>
<TabsList className="flex flex-wrap justify-center">
{tabData.map((tab) => (
<TabsTrigger
Expand Down

0 comments on commit b23a524

Please sign in to comment.