hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | import { createMediaQuery } from "@/lib/create-media-query"; |
| 2 | |
| 3 | /** Below Tailwind's `sm` breakpoint — the width where tables turn into cards. */ |
| 4 | export const COMPACT_SCREEN_QUERY = "(max-width: 639px)"; |
| 5 | |
| 6 | /** |
| 7 | * Rows per page on a phone for a list that shows `desktop` rows on a wide |
| 8 | * screen. A table row becomes a four- or five-line card there, so the same |
| 9 | * count is several screens tall: half as many, never fewer than five, and a |
| 10 | * list that is already short keeps its own size. |
| 11 | */ |
| 12 | export function compactPageSize(desktop: number): number { |
| 13 | return Math.min(desktop, Math.max(5, Math.ceil(desktop / 2))); |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * A page size that follows the screen: `desktop` on wide screens, |
| 18 | * `compactPageSize(desktop)` on phones. Callers that page on the server pass |
| 19 | * the accessor into their fetch source, so a rotation refetches the right |
| 20 | * slice; callers keeping a page index should reset it when this changes. |
| 21 | */ |
| 22 | export function createResponsivePageSize(desktop: number): () => number { |
| 23 | const compact = createMediaQuery(COMPACT_SCREEN_QUERY); |
| 24 | return () => (compact() ? compactPageSize(desktop) : desktop); |
| 25 | } |