All files / Bandstand/src/app/bands page.tsx

0% Statements 0/32
0% Branches 0/1
0% Functions 0/1
0% Lines 0/32

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43                                                                                     
export const dynamic = 'force-dynamic'
 
import {pageUser} from '@/lib/guard'
import {bandForHost, myBands, requestHost} from '@/lib/band'
import BandPicker from '@/components/BandPicker'
 
export const metadata = {title: 'Your bands'}
 
/**
 * The band picker, for people in more than one. The band this address
 * belongs to goes first. Someone in one band never sees this page.
 */
export default async function BandsPage({
  searchParams,
}: {
  searchParams: {next?: string}
}) {
  const {user} = await pageUser()
  const [bands, here] = await Promise.all([
    myBands(user.id),
    bandForHost(requestHost()),
  ])
  const ordered = [
    ...bands.filter((b) => b.id === here?.id),
    ...bands.filter((b) => b.id !== here?.id),
  ]
  const next = searchParams.next
  return (
    <BandPicker
      bands={ordered.map((b) => ({
        id: b.id,
        name: b.name,
        appName: b.appName,
        iconAt: b.iconAt?.getTime() ?? null,
      }))}
      next={
        next && next.startsWith('/') && !next.startsWith('//') ? next : '/songs'
      }
      isOwner={user.isOwner}
    />
  )
}