list-columns.server.ts 717 B

12345678910111213141516171819
  1. import 'server-only'
  2. import { cookies } from 'next/headers'
  3. import { columnsFrom, LIST_COLUMNS_COOKIE, parseListColumnsCookie } from './list-columns'
  4. import type { ListKey } from './list-sort-preference'
  5. /**
  6. * The optional columns a list page should render with, read on the server so
  7. * the first paint already has them. No URL form on purpose: which columns you
  8. * keep is a habit of the person, not something to share in a link.
  9. */
  10. export async function resolveListColumns(
  11. list: ListKey,
  12. available: Record<string, boolean>
  13. ): Promise<string[]> {
  14. const store = await cookies()
  15. const stored = parseListColumnsCookie(store.get(LIST_COLUMNS_COOKIE)?.value)[list]
  16. return columnsFrom(stored, available)
  17. }