Skip to content

Commit c04c404

Browse files
committed
Fix default sorting
1 parent 4fb5cf3 commit c04c404

14 files changed

+100
-56
lines changed

src/components/ArtistsColumn.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ArtistsColumnWithControls from './ArtistsColumnWithControls';
55
const ArtistsColumn = async () => {
66
const [artists, initialFilters] = await Promise.all([
77
RelistenAPI.fetchArtists(),
8-
getServerFilters('/'),
8+
getServerFilters('root', true),
99
]);
1010

1111
return <ArtistsColumnWithControls artists={artists} initialFilters={initialFilters} />;

src/components/ArtistsColumnWithControls.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ type ArtistsColumnWithControlsProps = {
1919
};
2020

2121
const ArtistsColumnWithControls = ({ artists, initialFilters }: ArtistsColumnWithControlsProps) => {
22-
const { alphaDesc, toggleFilter, clearFilters } = useFilterState(initialFilters);
22+
const { alphaAsc, toggleFilter, clearFilters } = useFilterState(initialFilters, 'root');
2323

2424
const toggles = [
2525
{
2626
type: 'sort' as const,
27-
isActive: alphaDesc, // Show as active when Z-A
27+
isActive: alphaAsc, // Show as active when Z-A (ascending)
2828
onToggle: () => toggleFilter('alpha'),
29-
title: alphaDesc ? 'A-Z' : 'Z-A',
29+
title: alphaAsc ? 'Z-A' : 'A-Z',
3030
},
3131
];
3232

@@ -37,16 +37,18 @@ const ArtistsColumnWithControls = ({ artists, initialFilters }: ArtistsColumnWit
3737
return sortedGroups.map(([type, groupArtists]) => {
3838
const sorted = [...groupArtists];
3939

40-
// Apply alphabetical sorting (default is asc/A-Z, desc is Z-A)
41-
if (alphaDesc) {
40+
// Apply alphabetical sorting (default is desc/A-Z when no filter set)
41+
if (alphaAsc) {
42+
// Z-A (ascending)
4243
sorted.sort((a, b) => (b.name || '').localeCompare(a.name || ''));
4344
} else {
45+
// Default: A-Z (descending)
4446
sorted.sort((a, b) => (a.name || '').localeCompare(b.name || ''));
4547
}
4648

4749
return [type, sorted] as [string, Artist[]];
4850
});
49-
}, [artists, alphaDesc]);
51+
}, [artists, alphaAsc]);
5052

5153
const totalArtistCount = artists.length;
5254
const filteredArtistCount = processedArtists.reduce(

src/components/ColumnWithToggleControls.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ const ColumnWithToggleControls = ({
6262
toggle.icon
6363
) : toggle.type === 'sort' ? (
6464
toggle.isActive ? (
65-
<ChevronDown className="w-3 h-3" />
66-
) : (
6765
<ChevronUp className="w-3 h-3" />
66+
) : (
67+
<ChevronDown className="w-3 h-3" />
6868
)
6969
) : null}
7070
{toggle.label && <span>{toggle.label}</span>}

src/components/RecentTapesColumn.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import RecentTapesColumnWithControls from './RecentTapesColumnWithControls';
88
const RecentTapesColumn = async ({ artistSlug, year }: Pick<RawParams, 'artistSlug' | 'year'>) => {
99
const [shows, initialFilters] = await Promise.all([
1010
RelistenAPI.fetchRecentlyAdded(artistSlug),
11-
getServerFilters(`/${artistSlug}`),
11+
getServerFilters(`${artistSlug}:shows`, true),
1212
]).catch(() => {
1313
notFound();
1414
});

src/components/RecentTapesColumnWithControls.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,21 @@ const RecentTapesColumnWithControls = ({
2525
shows,
2626
initialFilters,
2727
}: RecentTapesColumnWithControlsProps) => {
28-
const { dateDesc, sbdOnly, toggleFilter, clearFilters } = useFilterState(initialFilters);
28+
const { dateAsc, sbdOnly, toggleFilter, clearFilters } = useFilterState(
29+
initialFilters,
30+
`${artistSlug}:shows`
31+
);
2932

3033
const toggles = [
3134
{
3235
type: 'sort' as const,
33-
isActive: !dateDesc, // Show as active when reversed (oldest first)
36+
isActive: dateAsc, // Show as active when oldest first (ascending)
3437
onToggle: () => toggleFilter('date'),
35-
title: !dateDesc ? 'Newest First' : 'Oldest First',
38+
title: !dateAsc ? 'Newest First' : 'Oldest First',
3639
},
3740
{
3841
type: 'filter' as const,
39-
isActive: sbdOnly,
42+
isActive: !!sbdOnly,
4043
onToggle: () => toggleFilter('sbd'),
4144
title: sbdOnly ? 'All Shows' : 'SBD Only',
4245
label: 'SBD',
@@ -56,13 +59,13 @@ const RecentTapesColumnWithControls = ({
5659
processedShows = sortActiveBands(artistSlug, processedShows);
5760
}
5861

59-
// Reverse if needed (default is newest first/desc, so reverse when date is asc)
60-
if (!dateDesc) {
61-
processedShows.reverse();
62+
// Reverse if needed (default is desc/newest first when no filter set)
63+
if (!dateAsc) {
64+
processedShows.reverse(); // Change to oldest first
6265
}
6366

6467
return processedShows;
65-
}, [shows, artistSlug, dateDesc, sbdOnly]);
68+
}, [shows, artistSlug, dateAsc, sbdOnly]);
6669

6770
const tours = {};
6871

src/components/ShowsColumn.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const ShowsColumn = async ({ artistSlug, year }: Pick<RawParams, 'artistSlug' |
1313

1414
const [artistShows, initialFilters] = await Promise.all([
1515
RelistenAPI.fetchShows(artistSlug, year),
16-
getServerFilters(`/${artistSlug}`),
16+
getServerFilters(`${artistSlug}:shows`, true),
1717
]).catch(() => {
1818
notFound();
1919
});

src/components/ShowsColumnWithControls.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,21 @@ const ShowsColumnWithControls = ({
2525
shows,
2626
initialFilters,
2727
}: ShowsColumnWithControlsProps) => {
28-
const { dateDesc, sbdOnly, toggleFilter, clearFilters } = useFilterState(initialFilters);
28+
const { dateAsc, sbdOnly, toggleFilter, clearFilters } = useFilterState(
29+
initialFilters,
30+
`${artistSlug}:shows`
31+
);
2932

3033
const toggles = [
3134
{
3235
type: 'sort' as const,
33-
isActive: !dateDesc, // Show as active when reversed (oldest first)
36+
isActive: dateAsc, // Show as active when oldest first (ascending)
3437
onToggle: () => toggleFilter('date'),
35-
title: !dateDesc ? 'Newest First' : 'Oldest First',
38+
title: !dateAsc ? 'Newest First' : 'Oldest First',
3639
},
3740
{
3841
type: 'filter' as const,
39-
isActive: sbdOnly,
42+
isActive: !!sbdOnly,
4043
onToggle: () => toggleFilter('sbd'),
4144
title: sbdOnly ? 'All Shows' : 'SBD Only',
4245
label: 'SBD',
@@ -56,13 +59,13 @@ const ShowsColumnWithControls = ({
5659
processedShows = sortActiveBands(artistSlug, processedShows);
5760
}
5861

59-
// Reverse if needed (default is newest first/desc, so reverse when date is asc)
60-
if (!dateDesc) {
61-
processedShows.reverse();
62+
// Reverse if needed (default is desc/newest first when no filter set)
63+
if (!dateAsc) {
64+
processedShows.reverse(); // Change to oldest first
6265
}
6366

6467
return processedShows;
65-
}, [shows, artistSlug, dateDesc, sbdOnly]);
68+
}, [shows, artistSlug, dateAsc, sbdOnly]);
6669

6770
const tours = {};
6871

src/components/TodayInHistoryColumn.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const TodayInHistoryColumn = async ({
1111
}: Pick<RawParams, 'artistSlug' | 'year'>) => {
1212
const [shows, initialFilters] = await Promise.all([
1313
RelistenAPI.fetchTodayInHistory(artistSlug),
14-
getServerFilters(`/${artistSlug}`),
14+
getServerFilters(`${artistSlug}:shows`, true),
1515
]).catch(() => {
1616
notFound();
1717
});

src/components/TodayInHistoryColumnWithControls.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,21 @@ const TodayInHistoryColumnWithControls = ({
2525
shows,
2626
initialFilters,
2727
}: TodayInHistoryColumnWithControlsProps) => {
28-
const { dateDesc, sbdOnly, toggleFilter, clearFilters } = useFilterState(initialFilters);
28+
const { dateAsc, sbdOnly, toggleFilter, clearFilters } = useFilterState(
29+
initialFilters,
30+
`${artistSlug}:shows`
31+
);
2932

3033
const toggles = [
3134
{
3235
type: 'sort' as const,
33-
isActive: !dateDesc, // Show as active when reversed (oldest first)
36+
isActive: dateAsc, // Show as active when oldest first (ascending)
3437
onToggle: () => toggleFilter('date'),
35-
title: !dateDesc ? 'Newest First' : 'Oldest First',
38+
title: !dateAsc ? 'Newest First' : 'Oldest First',
3639
},
3740
{
3841
type: 'filter' as const,
39-
isActive: sbdOnly,
42+
isActive: !!sbdOnly,
4043
onToggle: () => toggleFilter('sbd'),
4144
title: sbdOnly ? 'All Shows' : 'SBD Only',
4245
label: 'SBD',
@@ -56,13 +59,13 @@ const TodayInHistoryColumnWithControls = ({
5659
processedShows = sortActiveBands(artistSlug, processedShows);
5760
}
5861

59-
// Reverse if needed (default is newest first/desc, so reverse when date is asc)
60-
if (!dateDesc) {
61-
processedShows.reverse();
62+
// Reverse if needed (default is desc/newest first when no filter set)
63+
if (!dateAsc) {
64+
processedShows.reverse(); // Change to oldest first
6265
}
6366

6467
return processedShows;
65-
}, [shows, artistSlug, dateDesc, sbdOnly]);
68+
}, [shows, artistSlug, dateAsc, sbdOnly]);
6669

6770
const tours = {};
6871

src/components/YearsColumn.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const YearsColumn = async ({ artistSlug }: Pick<RawParams, 'artistSlug'>) => {
1010
const [artists, artistYears, initialFilters] = await Promise.all([
1111
RelistenAPI.fetchArtists(),
1212
RelistenAPI.fetchYears(artistSlug),
13-
getServerFilters(`/${artistSlug}`),
13+
getServerFilters(artistSlug || '', true),
1414
]).catch(() => {
1515
notFound();
1616
});

0 commit comments

Comments
 (0)