import { ChevronLeftIcon, ChevronRightIcon } from "@heroicons/react/20/solid"; import { useLocation } from "@remix-run/react"; import { z } from "zod"; import { LinkButton } from "~/components/primitives/Buttons"; import { cn } from "~/utils/cn"; type List = { pagination: { next?: string | undefined; previous?: string | undefined; }; }; export const DirectionSchema = z.union([z.literal("forward"), z.literal("backward")]); export type Direction = z.infer; export function ListPagination({ list, className }: { list: List; className?: string }) { const bothDisabled = !list.pagination.previous && !list.pagination.next; return (
); } function PreviousButton({ cursor }: { cursor?: string }) { const path = useCursorPath(cursor, "backward"); return (
!path && e.preventDefault()} shortcut={{ key: "j" }} tooltip="Previous" disabled={!path} />
); } function NextButton({ cursor }: { cursor?: string }) { const path = useCursorPath(cursor, "forward"); return (
!path && e.preventDefault()} shortcut={{ key: "k" }} tooltip="Next" disabled={!path} />
); } function useCursorPath(cursor: string | undefined, direction: Direction) { const location = useLocation(); if (!cursor) { return undefined; } const search = new URLSearchParams(location.search); search.set("cursor", cursor); search.set("direction", direction); return location.pathname + "?" + search.toString(); }