Skip to content

Commit 263d549

Browse files
committed
Fetch today metadata in suspense boundary. Fixes #81
1 parent ba68f3d commit 263d549

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

src/components/TodayInHistoryColumn.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Row from './Row';
1313
import RowHeader from './RowHeader';
1414
import Tag from './Tag';
1515

16-
const fetchToday = async (slug?: string): Promise<Show[] | undefined> => {
16+
export const fetchToday = async (slug?: string): Promise<Show[] | undefined> => {
1717
// TODO: pull time zone from cloudflare header and render "on date" for the users client
1818
const parsed: Show[] = await ky(`${API_DOMAIN}/api/v2/artists/${slug}/shows/today`, {
1919
cache: 'no-cache',
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { RawParams } from '@/app/(main)/(home)/layout';
2+
import Row from './Row';
3+
import { fetchToday } from './TodayInHistoryColumn';
4+
import { simplePluralize } from '@/lib/utils';
5+
import { Suspense } from 'react';
6+
7+
const TodayInHistoryRow = async ({ artistSlug }: Pick<RawParams, 'artistSlug'>) => {
8+
return (
9+
<Row href={`/${artistSlug}/today-in-history`} activeSegments={{ 0: 'today-in-history' }}>
10+
<div>
11+
<div>Today In History</div>
12+
</div>
13+
<div className="min-w-[20%] text-right text-xxs text-[#979797]">
14+
<Suspense fallback={null}>
15+
<TodayMetadata artistSlug={artistSlug} />
16+
</Suspense>
17+
</div>
18+
</Row>
19+
);
20+
};
21+
22+
const TodayMetadata = async ({ artistSlug }: { artistSlug?: string }) => {
23+
if (!artistSlug) return null;
24+
25+
const data = await fetchToday(artistSlug);
26+
27+
return (
28+
<>
29+
<div>{simplePluralize('show', data?.length)}</div>
30+
<div>
31+
{simplePluralize(
32+
'tape',
33+
data?.reduce((memo, next) => memo + (next.source_count ?? 0), 0)
34+
)}
35+
</div>
36+
</>
37+
);
38+
};
39+
40+
export default TodayInHistoryRow;

src/components/YearsColumn.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Year } from '../types';
99
import Column from './Column';
1010
import Row from './Row';
1111
import { notFound } from 'next/navigation';
12+
import TodayInHistoryRow from './TodayInHistoryRow';
1213

1314
const fetchYears = async (slug?: string): Promise<Year[]> => {
1415
if (!slug) return [];
@@ -37,15 +38,7 @@ const YearsColumn = async ({ artistSlug }: Pick<RawParams, 'artistSlug'>) => {
3738

3839
return (
3940
<Column heading={artist?.name ?? 'Years'}>
40-
<Row href={`/${artistSlug}/today-in-history`} activeSegments={{ 0: 'today-in-history' }}>
41-
<div>
42-
<div>Today In History</div>
43-
</div>
44-
<div className="min-w-[20%] text-right text-xxs text-[#979797]">
45-
{/* <div>{simplePluralize('show', yearObj.show_count)}</div>
46-
<div>{simplePluralize('tape', yearObj.source_count)}</div> */}
47-
</div>
48-
</Row>
41+
<TodayInHistoryRow artistSlug={artistSlug} />
4942
{artistSlug &&
5043
artistYears.length &&
5144
sortActiveBands(artistSlug, artistYears).map((yearObj) => (

0 commit comments

Comments
 (0)