All files / Bandstand/src/app/(band)/songs page.tsx

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

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                                                           
export const dynamic = 'force-dynamic'
 
import {detectKey, parseChordPro} from '@/lib/chordpro'
import {displayName, isImportNote, listSongs} from '@/lib/songs'
import {pageSession} from '@/lib/guard'
import SongLibrary, {type LibrarySong} from '@/components/SongLibrary'
 
export const metadata = {title: 'Songs'}
 
export default async function SongsPage() {
  const {band} = await pageSession()
  const songs = await listSongs(band.id)
  const rows: LibrarySong[] = songs.map((s) => {
    const chart = s.latest ? parseChordPro(s.latest.source) : null
    return {
      id: s.id,
      title: s.title,
      leadSinger: s.leadSinger,
      writer: s.writer,
      ready: s.status === 'READY',
      key: chart ? detectKey(chart) : null,
      hasChart: Boolean(chart?.sections.length),
      editedBy: s.latest ? displayName(s.latest.author) : null,
      editedAt: s.latest?.createdAt.toISOString() ?? null,
      imported: isImportNote(s.latest?.note),
    }
  })
  return <SongLibrary songs={rows} />
}