diff --git a/app/discussions/page.tsx b/app/discussions/page.tsx index 560f7cf..e567cfb 100644 --- a/app/discussions/page.tsx +++ b/app/discussions/page.tsx @@ -46,7 +46,7 @@ export default async function Page(props: { - }> + }> diff --git a/app/profile/discussions/page.tsx b/app/profile/discussions/page.tsx index 4b75af2..491d77b 100644 --- a/app/profile/discussions/page.tsx +++ b/app/profile/discussions/page.tsx @@ -30,7 +30,7 @@ export default async function MyProjects(props: { - }> + }> diff --git a/app/profile/projects/page.tsx b/app/profile/projects/page.tsx index fcd45ca..3538f77 100644 --- a/app/profile/projects/page.tsx +++ b/app/profile/projects/page.tsx @@ -35,7 +35,7 @@ export default async function MyProjects(props: { Start A New Project - }> + }> diff --git a/app/projects/page.tsx b/app/projects/page.tsx index 7d3fdc7..d7a515c 100644 --- a/app/projects/page.tsx +++ b/app/projects/page.tsx @@ -48,7 +48,7 @@ export default async function Page(props: { - }> + }> diff --git a/src/components/custom/pagination.tsx b/src/components/custom/pagination.tsx index 5eeaaa4..28eab31 100644 --- a/src/components/custom/pagination.tsx +++ b/src/components/custom/pagination.tsx @@ -12,7 +12,7 @@ export default function CustomPagination({ totalPages }: { totalPages: number }) const createPageURL = (pageNumber: number | string) => { const params = new URLSearchParams(searchParams); params.set('page', pageNumber.toString()); - router.push(`${pathname}?${params.toString()}`); + router.push(`${pathname}?${params.toString()}`, { scroll: false }); }; return ( @@ -23,7 +23,7 @@ export default function CustomPagination({ totalPages }: { totalPages: number }) createPageURL(currentPage - 1)} + onClick={(e) => { e.preventDefault(); if (currentPage > 1) createPageURL(currentPage - 1); }} /> @@ -31,6 +31,7 @@ export default function CustomPagination({ totalPages }: { totalPages: number }) e.preventDefault()} > {currentPage} @@ -41,7 +42,7 @@ export default function CustomPagination({ totalPages }: { totalPages: number }) createPageURL(currentPage + 1)} + onClick={(e) => { e.preventDefault(); if (currentPage < totalPages) createPageURL(currentPage + 1); }} /> diff --git a/src/components/custom/search-bar.tsx b/src/components/custom/search-bar.tsx index 29292e1..cdc016a 100644 --- a/src/components/custom/search-bar.tsx +++ b/src/components/custom/search-bar.tsx @@ -1,40 +1,45 @@ -'use client'; - -import { Input } from '@/src/components/ui/input'; -import { Label } from '@/src/components/ui/label'; -import { debounce } from '@/src/utils/utils'; -import { SearchIcon } from 'lucide-react'; -import { usePathname, useRouter, useSearchParams } from 'next/navigation'; - -export default function Search({ placeholder }: { placeholder: string }) { - const searchParams = useSearchParams(); - const pathname = usePathname(); - const { replace } = useRouter(); - const handleSearch = debounce((term) => { - const params = new URLSearchParams(searchParams); - params.set('page', '1'); - if (term) { - params.set('query', term); - } else { - params.delete('query'); - } - replace(`${pathname}?${params.toString()}`); - }, 300); - - return ( -
- - { - handleSearch(e.target.value); - }} - defaultValue={searchParams.get('query')?.toString()} - /> - -
- ); -} \ No newline at end of file +'use client'; + +import { Input } from '@/src/components/ui/input'; +import { Label } from '@/src/components/ui/label'; +import { debounce } from '@/src/utils/utils'; +import { SearchIcon } from 'lucide-react'; +import { usePathname, useRouter, useSearchParams } from 'next/navigation'; +import { useTransition } from 'react'; + +export default function Search({ placeholder }: { placeholder: string }) { + const searchParams = useSearchParams(); + const pathname = usePathname(); + const { replace } = useRouter(); + const [, startTransition] = useTransition(); + + const handleSearch = debounce((term: string) => { + const params = new URLSearchParams(searchParams); + params.set('page', '1'); + if (term) { + params.set('query', term); + } else { + params.delete('query'); + } + startTransition(() => { + replace(`${pathname}?${params.toString()}`, { scroll: false }); + }); + }, 300); + + return ( +
e.preventDefault()} className="relative min-w-60 flex flex-1 flex-shrink-0"> + + { + handleSearch(e.target.value); + }} + defaultValue={searchParams.get('query')?.toString()} + /> + + + ); +} \ No newline at end of file diff --git a/src/components/custom/tags-filter.tsx b/src/components/custom/tags-filter.tsx index 52edf4d..d32fa78 100644 --- a/src/components/custom/tags-filter.tsx +++ b/src/components/custom/tags-filter.tsx @@ -1,7 +1,7 @@ 'use client' import { usePathname, useRouter, useSearchParams } from "next/navigation"; -import { useEffect, useState } from "react"; +import { useEffect, useState, useTransition } from "react"; import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover"; import { Button } from "../ui/button"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "../ui/command"; @@ -13,6 +13,7 @@ export function TagsFilter({ for: filterType }: { for: 'discussions' | 'projects const searchParams = useSearchParams(); const pathname = usePathname(); const { replace } = useRouter(); + const [, startTransition] = useTransition(); const params = new URLSearchParams(searchParams); const currentTags = params.get('tags')?.split(',') || []; const [allTags, setAllTags] = useState([]); @@ -44,7 +45,9 @@ export function TagsFilter({ for: filterType }: { for: 'discussions' | 'projects } else { params.delete('tags'); } - replace(`${pathname}?${params.toString()}`); + startTransition(() => { + replace(`${pathname}?${params.toString()}`, { scroll: false }); + }); }; const onSelectTag = (tag: string) => { diff --git a/src/components/discussions/categories-carousel.tsx b/src/components/discussions/categories-carousel.tsx index 86a0d2b..94784bf 100644 --- a/src/components/discussions/categories-carousel.tsx +++ b/src/components/discussions/categories-carousel.tsx @@ -9,6 +9,7 @@ import { } from "@/src/components/ui/carousel" import { DiscussionCategoriesDescriptions, DiscussionCategory } from "@/src/types/enums" import { usePathname, useRouter, useSearchParams } from "next/navigation"; +import { useTransition } from "react"; import { Button } from "../ui/button"; import { cn } from "@/src/lib/utils"; @@ -16,17 +17,20 @@ export function CategoriesCarousel() { const searchParams = useSearchParams(); const pathname = usePathname(); const { replace } = useRouter(); + const [, startTransition] = useTransition(); const params = new URLSearchParams(searchParams); const currentcategory = params.get('category') as DiscussionCategory | null; - const handleFilter = (category : DiscussionCategory | null) => { + const handleFilter = (category: DiscussionCategory | null) => { params.set('page', '1'); if (category) { params.set('category', category); } else { params.delete('category'); } - replace(`${pathname}?${params.toString()}`); + startTransition(() => { + replace(`${pathname}?${params.toString()}`, { scroll: false }); + }); }; return ( @@ -42,11 +46,12 @@ export function CategoriesCarousel() {