1+ import sortActiveBands from '../lib/sortActiveBands' ;
2+ import { durationToHHMMSS , removeLeadingZero , simplePluralize , splitShowDate } from '../lib/utils' ;
3+
4+ import RelistenAPI from '@/lib/RelistenAPI' ;
5+ import { RawParams } from '@/types/params' ;
6+ import React from 'react' ;
7+ import Column from './Column' ;
8+ import Flex from './Flex' ;
9+ import Row from './Row' ;
10+ import RowHeader from './RowHeader' ;
11+ import Tag from './Tag' ;
12+ import { notFound } from 'next/navigation' ;
13+
14+ const RecentTapesColumn = async ( {
15+ artistSlug,
16+ year,
17+ } : Pick < RawParams , 'artistSlug' | 'year' > ) => {
18+ const shows = await RelistenAPI . fetchRecentlyAdded ( artistSlug ) . catch ( ( ) => {
19+ notFound ( ) ;
20+ } ) ;
21+ const tours = { } ;
22+ return (
23+ < Column heading = { year ? year : 'Recently Added' } key = { year } >
24+ { ( ! shows || shows . length === 0 ) && (
25+ < div className = "text-center text-gray-700 text-sm py-2" >
26+ No recently added shows!
27+ </ div >
28+ ) }
29+ { shows &&
30+ artistSlug &&
31+ sortActiveBands ( artistSlug , shows ) . map ( ( show ) => {
32+ const { year, month, day } = splitShowDate ( show . display_date ) ;
33+ const { venue, avg_duration, tour } = show ;
34+ let tourName = '' ;
35+
36+ // keep track of which tours we've displayed
37+ if ( tour ) {
38+ if ( ! tours [ tour . id ] ) tourName = tour . name ?? '' ;
39+
40+ tours [ tour . id ] = true ;
41+ }
42+
43+ return (
44+ < div key = { show . id } >
45+ { tourName && (
46+ < RowHeader > { tourName === 'Not Part of a Tour' ? '' : tourName } </ RowHeader >
47+ ) }
48+ < Row
49+ href = { `/${ artistSlug } /${ year } /${ month } /${ day } ` }
50+ activeSegments = { {
51+ month,
52+ day,
53+ } }
54+ >
55+ < div >
56+ < Flex >
57+ { removeLeadingZero ( month ) } /{ day } /{ year }
58+ { show . has_soundboard_source && < Tag > SBD</ Tag > }
59+ </ Flex >
60+ { venue && (
61+ < div className = "text-xxs text-foreground-muted" >
62+ < div > { venue . name } </ div >
63+ < div > { venue . location } </ div >
64+ </ div >
65+ ) }
66+ </ div >
67+ < div className = "flex h-full min-w-[20%] flex-col justify-center gap-2 text-right text-xxs text-foreground-muted" >
68+ < div > { durationToHHMMSS ( avg_duration ) } </ div >
69+ < div > { simplePluralize ( 'tape' , show . source_count ) } </ div >
70+ </ div >
71+ </ Row >
72+ </ div >
73+ ) ;
74+ } ) }
75+ </ Column >
76+ ) ;
77+ } ;
78+
79+ export default React . memo ( RecentTapesColumn ) ;
0 commit comments