diff --git a/apps/web/src/app/(admin)/admin/(default)/badges/page.tsx b/apps/web/src/app/(admin)/admin/(default)/badges/page.tsx index 6dbe41079..058ea4de9 100644 --- a/apps/web/src/app/(admin)/admin/(default)/badges/page.tsx +++ b/apps/web/src/app/(admin)/admin/(default)/badges/page.tsx @@ -4,16 +4,19 @@ import BadgeTable from "@peated/web/components/admin/badgeTable"; import { Breadcrumbs } from "@peated/web/components/breadcrumbs"; import Button from "@peated/web/components/button"; import EmptyActivity from "@peated/web/components/emptyActivity"; +import useApiQueryParams from "@peated/web/hooks/useApiQueryParams"; import { trpc } from "@peated/web/lib/trpc/client"; -import { useSearchParams } from "next/navigation"; export default function Page() { - const searchParams = useSearchParams(); - const [badgeList] = trpc.badgeList.useSuspenseQuery({ - sort: "name", - ...Object.fromEntries(searchParams.entries()), + const queryParams = useApiQueryParams({ + defaults: { + sort: "name", + }, + numericFields: ["cursor", "limit"], }); + const [badgeList] = trpc.badgeList.useSuspenseQuery(queryParams); + return (
diff --git a/apps/web/src/app/(admin)/admin/(default)/tags/page.tsx b/apps/web/src/app/(admin)/admin/(default)/tags/page.tsx index 203dd097b..d67258e63 100644 --- a/apps/web/src/app/(admin)/admin/(default)/tags/page.tsx +++ b/apps/web/src/app/(admin)/admin/(default)/tags/page.tsx @@ -4,14 +4,14 @@ import TagTable from "@peated/web/components/admin/tagTable"; import { Breadcrumbs } from "@peated/web/components/breadcrumbs"; import Button from "@peated/web/components/button"; import EmptyActivity from "@peated/web/components/emptyActivity"; +import useApiQueryParams from "@peated/web/hooks/useApiQueryParams"; import { trpc } from "@peated/web/lib/trpc/client"; -import { useSearchParams } from "next/navigation"; export default function Page() { - const searchParams = useSearchParams(); - const [tagList] = trpc.tagList.useSuspenseQuery({ - ...Object.fromEntries(searchParams.entries()), + const queryParams = useApiQueryParams({ + numericFields: ["cursor", "limit"], }); + const [tagList] = trpc.tagList.useSuspenseQuery(queryParams); return (
diff --git a/apps/web/src/app/(default)/locations/[countrySlug]/(tabs)/page.tsx b/apps/web/src/app/(default)/locations/[countrySlug]/(tabs)/page.tsx index 512d5b799..94cef4d41 100644 --- a/apps/web/src/app/(default)/locations/[countrySlug]/(tabs)/page.tsx +++ b/apps/web/src/app/(default)/locations/[countrySlug]/(tabs)/page.tsx @@ -3,23 +3,26 @@ import EmptyActivity from "@peated/web/components/emptyActivity"; import EntityTable from "@peated/web/components/entityTable"; import PaginationButtons from "@peated/web/components/paginationButtons"; +import useApiQueryParams from "@peated/web/hooks/useApiQueryParams"; import { trpc } from "@peated/web/lib/trpc/client"; -import { useSearchParams } from "next/navigation"; export default function Page({ params: { countrySlug }, }: { params: { countrySlug: string }; }) { - const searchParams = useSearchParams(); - const [[topEntityList]] = trpc.useSuspenseQueries((t) => [ - t.entityList({ - ...Object.fromEntries(searchParams.entries()), + const queryParams = useApiQueryParams({ + numericFields: ["cursor", "limit"], + overrides: { country: countrySlug, type: "distiller", sort: "-bottles", limit: 20, - }), + }, + }); + + const [[topEntityList]] = trpc.useSuspenseQueries((t) => [ + t.entityList(queryParams), ]); return ( diff --git a/apps/web/src/app/(default)/locations/[countrySlug]/(tabs)/regions/page.tsx b/apps/web/src/app/(default)/locations/[countrySlug]/(tabs)/regions/page.tsx index 54ac8f417..10a1ce167 100644 --- a/apps/web/src/app/(default)/locations/[countrySlug]/(tabs)/regions/page.tsx +++ b/apps/web/src/app/(default)/locations/[countrySlug]/(tabs)/regions/page.tsx @@ -1,22 +1,25 @@ "use client"; import Table from "@peated/web/components/table"; +import useApiQueryParams from "@peated/web/hooks/useApiQueryParams"; import { trpc } from "@peated/web/lib/trpc/client"; -import { useSearchParams } from "next/navigation"; export default function Page({ params: { countrySlug }, }: { params: { countrySlug: string }; }) { - const searchParams = useSearchParams(); - const [[regionList]] = trpc.useSuspenseQueries((t) => [ - t.regionList({ - ...Object.fromEntries(searchParams.entries()), + const queryParams = useApiQueryParams({ + numericFields: ["cursor", "limit"], + overrides: { country: countrySlug, sort: "-bottles", limit: 100, - }), + }, + }); + + const [[regionList]] = trpc.useSuspenseQueries((t) => [ + t.regionList(queryParams), ]); return ( diff --git a/apps/web/src/app/(default)/locations/[countrySlug]/regions/[regionSlug]/(tabs)/page.tsx b/apps/web/src/app/(default)/locations/[countrySlug]/regions/[regionSlug]/(tabs)/page.tsx index 8f2bbdc18..05e166bfc 100644 --- a/apps/web/src/app/(default)/locations/[countrySlug]/regions/[regionSlug]/(tabs)/page.tsx +++ b/apps/web/src/app/(default)/locations/[countrySlug]/regions/[regionSlug]/(tabs)/page.tsx @@ -3,24 +3,27 @@ import EmptyActivity from "@peated/web/components/emptyActivity"; import EntityTable from "@peated/web/components/entityTable"; import PaginationButtons from "@peated/web/components/paginationButtons"; +import useApiQueryParams from "@peated/web/hooks/useApiQueryParams"; import { trpc } from "@peated/web/lib/trpc/client"; -import { useSearchParams } from "next/navigation"; export default function Page({ params: { countrySlug, regionSlug }, }: { params: { countrySlug: string; regionSlug: string }; }) { - const searchParams = useSearchParams(); - const [[topEntityList]] = trpc.useSuspenseQueries((t) => [ - t.entityList({ - ...Object.fromEntries(searchParams.entries()), + const queryParams = useApiQueryParams({ + numericFields: ["cursor", "limit"], + overrides: { country: countrySlug, region: regionSlug, type: "distiller", sort: "-bottles", limit: 20, - }), + }, + }); + + const [[topEntityList]] = trpc.useSuspenseQueries((t) => [ + t.entityList(queryParams), ]); return ( diff --git a/apps/web/src/app/(default)/notifications/(tabs)/all/page.tsx b/apps/web/src/app/(default)/notifications/(tabs)/all/page.tsx index f15246ddb..6532143ba 100644 --- a/apps/web/src/app/(default)/notifications/(tabs)/all/page.tsx +++ b/apps/web/src/app/(default)/notifications/(tabs)/all/page.tsx @@ -2,18 +2,21 @@ import EmptyActivity from "@peated/web/components/emptyActivity"; import NotificationList from "@peated/web/components/notifications/list"; +import useApiQueryParams from "@peated/web/hooks/useApiQueryParams"; import useAuthRequired from "@peated/web/hooks/useAuthRequired"; import { trpc } from "@peated/web/lib/trpc/client"; -import { useSearchParams } from "next/navigation"; export default function Page() { useAuthRequired(); - const searchParams = useSearchParams(); - const [notificationList] = trpc.notificationList.useSuspenseQuery({ - filter: "all", - ...Object.fromEntries(searchParams.entries()), + const queryParams = useApiQueryParams({ + numericFields: ["cursor", "limit"], + overrides: { + filter: "all", + }, }); + const [notificationList] = + trpc.notificationList.useSuspenseQuery(queryParams); return notificationList.results.length ? ( diff --git a/apps/web/src/app/(default)/notifications/(tabs)/page.tsx b/apps/web/src/app/(default)/notifications/(tabs)/page.tsx index 1e095d211..af3425cb6 100644 --- a/apps/web/src/app/(default)/notifications/(tabs)/page.tsx +++ b/apps/web/src/app/(default)/notifications/(tabs)/page.tsx @@ -2,18 +2,21 @@ import EmptyActivity from "@peated/web/components/emptyActivity"; import NotificationList from "@peated/web/components/notifications/list"; +import useApiQueryParams from "@peated/web/hooks/useApiQueryParams"; import useAuthRequired from "@peated/web/hooks/useAuthRequired"; import { trpc } from "@peated/web/lib/trpc/client"; -import { useSearchParams } from "next/navigation"; export default function Page() { useAuthRequired(); - const searchParams = useSearchParams(); - const [notificationList] = trpc.notificationList.useSuspenseQuery({ - filter: "unread", - ...Object.fromEntries(searchParams.entries()), + const queryParams = useApiQueryParams({ + numericFields: ["cursor", "limit"], + overrides: { + filter: "unread", + }, }); + const [notificationList] = + trpc.notificationList.useSuspenseQuery(queryParams); return notificationList.results.length ? (