Skip to content

Commit 5d15d37

Browse files
committed
Add recent tapes column to artists
1 parent e8c3740 commit 5d15d37

File tree

5 files changed

+111
-0
lines changed

5 files changed

+111
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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);

src/components/RecentTapesRow.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { RawParams } from '@/types/params';
2+
import Row from './Row';
3+
4+
const RecentTapesRow = async ({ artistSlug }: Pick<RawParams, 'artistSlug'>) => {
5+
return (
6+
<Row href={`/${artistSlug}/recently-added`} activeSegments={{ year: 'recently-added' }}>
7+
<div>
8+
<div>Recent Tapes</div>
9+
<div className="text-xxs text-foreground-muted">The newest recordings</div>
10+
</div>
11+
<div className="min-w-[20%] text-right text-xxs text-foreground-muted">
12+
<div>fresh shows</div>
13+
<div>fresh tapes</div>
14+
</div>
15+
</Row>
16+
);
17+
};
18+
19+
export default RecentTapesRow;

src/components/ShowsColumn.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ import Row from './Row';
1111
import RowHeader from './RowHeader';
1212
import Tag from './Tag';
1313
import TodayInHistoryColumn from './TodayInHistoryColumn';
14+
import RecentTapesColumn from './RecentTapesColumn';
1415

1516
const ShowsColumn = async ({ artistSlug, year }: Pick<RawParams, 'artistSlug' | 'year'>) => {
1617
if (year === 'today-in-history') return <TodayInHistoryColumn artistSlug={artistSlug} />;
18+
if (year === 'recently-added') return <RecentTapesColumn artistSlug={artistSlug} />;
1719

1820
const artistShows = await RelistenAPI.fetchShows(artistSlug, year).catch(() => {
1921
notFound();

src/components/YearsColumn.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { notFound } from 'next/navigation';
77
import Column from './Column';
88
import Row from './Row';
99
import TodayInHistoryRow from './TodayInHistoryRow';
10+
import RecentTapesRow from './RecentTapesRow';
1011

1112
const YearsColumn = async ({ artistSlug }: Pick<RawParams, 'artistSlug'>) => {
1213
const [artists, artistYears] = await Promise.all([
@@ -22,6 +23,7 @@ const YearsColumn = async ({ artistSlug }: Pick<RawParams, 'artistSlug'>) => {
2223
return (
2324
<Column heading={artist?.name ?? 'Years'}>
2425
<TodayInHistoryRow artistSlug={artistSlug} />
26+
<RecentTapesRow artistSlug={artistSlug} />
2527
{artistSlug &&
2628
artistYears.length &&
2729
sortActiveBands(artistSlug, artistYears).map((yearObj) => (

src/lib/RelistenAPI.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ export class RelistenAPI {
119119
}
120120
);
121121

122+
// Recently Added Shows API
123+
static fetchRecentlyAdded = cache(async (artistSlug?: string): Promise<Show[]> => {
124+
if (!artistSlug) return [];
125+
126+
return this.cachedFetch<Show[]>(
127+
`/api/v2/artists/${artistSlug}/shows/recently-added`
128+
);
129+
});
130+
122131
// Live API
123132
static fetchRecentlyPlayed = cache(async (): Promise<any[]> => {
124133
return this.cachedFetch<any[]>('/api/v2/live/recently_played', { revalidate: 0 });

0 commit comments

Comments
 (0)