Skip to content

Commit 428715c

Browse files
committed
Merge
2 parents 75a73cd + 9b11c2a commit 428715c

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/components/Row.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,19 @@ type RowProps = {
1414
active?: boolean;
1515
loading?: boolean;
1616
activeSegments?: Record<string, string | undefined>;
17+
fallbackParams?: Record<string, string>;
1718
isActiveOverride?: boolean;
1819
};
1920

20-
const Row = ({ children, href, activeSegments, isActiveOverride, loading, ...props }: RowProps) => {
21+
const Row = ({
22+
children,
23+
href,
24+
activeSegments,
25+
isActiveOverride,
26+
loading,
27+
fallbackParams,
28+
...props
29+
}: RowProps) => {
2130
const [isPending, startTransition] = useTransition();
2231
const params = useParams();
2332
const pathname = usePathname();
@@ -27,7 +36,9 @@ const Row = ({ children, href, activeSegments, isActiveOverride, loading, ...pro
2736

2837
// if every segment is true, then we're active
2938
if (isActiveOverride === undefined && activeSegments) {
30-
isActive = Object.entries(activeSegments).every(([key, value]) => params[key] === value);
39+
isActive = Object.entries(activeSegments).every(
40+
([key, value]) => (params[key] ?? fallbackParams?.[key]) === value
41+
);
3142
}
3243

3344
if (!href) {

src/lib/RelistenAPI.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import type { Artist, Tape, Year, ArtistShows, Show, Day } from '@/types';
88
export class RelistenAPI {
99
private static baseURL = API_DOMAIN;
1010

11+
// Validate artist slug format
12+
private static isValidArtistSlug(slug: string): boolean {
13+
return /^[a-z-]+$/i.test(slug);
14+
}
15+
1116
// Generic cached fetch method
1217
private static cachedFetch = cache(
1318
async <T>(
@@ -72,10 +77,8 @@ export class RelistenAPI {
7277
static fetchRandomShow = cache(async (artistSlug: string): Promise<Partial<Tape> | undefined> => {
7378
if (!artistSlug) return undefined;
7479

75-
// if doesnt match
76-
if (!/^[a-z-]+$/i.test(artistSlug)) {
80+
if (!this.isValidArtistSlug(artistSlug)) {
7781
console.error('Tried to load url that doesnt match artist slug format:', artistSlug);
78-
7982
return notFound();
8083
}
8184

@@ -88,6 +91,11 @@ export class RelistenAPI {
8891
static fetchYears = cache(async (slug?: string): Promise<Year[]> => {
8992
if (!slug) return [];
9093

94+
if (!this.isValidArtistSlug(slug)) {
95+
console.error('Tried to load url that doesnt match artist slug format:', slug);
96+
return notFound();
97+
}
98+
9199
return this.cachedFetch<Year[]>(`/api/v2/artists/${slug}/years`);
92100
});
93101

0 commit comments

Comments
 (0)