Skip to content

Commit 919e6ab

Browse files
committed
fix(sets): fix links to sets
1 parent 03a7e79 commit 919e6ab

File tree

6 files changed

+38
-30
lines changed

6 files changed

+38
-30
lines changed

src/hooks/queries/sets/useSetBySlug.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ import { useQuery } from "@tanstack/react-query";
22
import { supabase } from "@/integrations/supabase/client";
33
import { FestivalSet, setsKeys } from "./useSets";
44

5-
// Business logic function
6-
async function fetchSetBySlug(slug: string): Promise<FestivalSet> {
5+
async function fetchSetBySlug({
6+
slug,
7+
editionId,
8+
}: {
9+
slug: string;
10+
editionId: string;
11+
}): Promise<FestivalSet> {
712
const { data, error } = await supabase
813
.from("sets")
914
.select(
@@ -20,6 +25,7 @@ async function fetchSetBySlug(slug: string): Promise<FestivalSet> {
2025
`,
2126
)
2227
.eq("slug", slug)
28+
.eq("festival_edition_id", editionId)
2329
.eq("archived", false)
2430
.single();
2531

@@ -46,10 +52,13 @@ async function fetchSetBySlug(slug: string): Promise<FestivalSet> {
4652
}
4753

4854
// Hook
49-
export function useSetBySlugQuery(slug: string) {
55+
export function useSetBySlugQuery({
56+
slug,
57+
editionId,
58+
}: { slug?: string; editionId?: string } = {}) {
5059
return useQuery({
51-
queryKey: setsKeys.bySlug(slug),
52-
queryFn: () => fetchSetBySlug(slug),
53-
enabled: !!slug,
60+
queryKey: setsKeys.bySlug({ slug, editionId }),
61+
queryFn: () => fetchSetBySlug({ slug: slug!, editionId: editionId! }),
62+
enabled: !!slug && !!editionId,
5463
});
5564
}

src/hooks/queries/sets/useSets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const setsKeys = {
1717
list: (filters?: unknown) => [...setsKeys.lists(), filters] as const,
1818
details: () => [...setsKeys.all, "detail"] as const,
1919
detail: (id: string) => [...setsKeys.details(), id] as const,
20-
bySlug: (slug: string) => [...setsKeys.details(), "slug", slug] as const,
20+
bySlug: (params: unknown) => [...setsKeys.details(), params] as const,
2121
byEdition: (editionId: string) =>
2222
[...setsKeys.all, "edition", editionId] as const,
2323
};

src/pages/EditionView/tabs/ArtistsTab/SetCard/SetImage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function SetImage({ className = "", size = "lg" }: SetImageProps) {
2020
const containerClass = `${sizeClasses[size]} ${className} overflow-hidden rounded-lg hover:opacity-90 transition-opacity cursor-pointer`;
2121

2222
return (
23-
<Link to={`./sets/${set.slug}`} className="block flex-shrink-0">
23+
<Link to={`./${set.slug}`} className="block flex-shrink-0">
2424
{isMultiArtist ? (
2525
<MixedArtistImage
2626
artists={set.artists}

src/pages/EditionView/tabs/ScheduleTab/horizontal/SetHeader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function SetHeader({ set }: SetHeaderProps) {
99
return (
1010
<div className="mb-2">
1111
<Link
12-
to={`./sets/${set.slug}`}
12+
to={`../../sets/${set.slug}`}
1313
className="text-white font-semibold hover:text-purple-300 transition-colors block text-sm whitespace-nowrap overflow-hidden text-ellipsis"
1414
>
1515
{set.name}

src/pages/SetDetails.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,30 @@ import { SetGroupVoting } from "./SetDetails/SetGroupVoting";
1010
import { ArtistNotes } from "./SetDetails/SetNotes";
1111
import { useUrlState } from "@/hooks/useUrlState";
1212
import { useSetDetail } from "./SetDetails/useSetDetail";
13+
import { useSetBySlugQuery } from "@/hooks/queries/sets/useSetBySlug";
14+
import { useFestivalEdition } from "@/contexts/FestivalEditionContext";
15+
import { useAuth } from "@/contexts/AuthContext";
1316

1417
export function SetDetails() {
18+
const { user } = useAuth();
1519
const { setSlug } = useParams<{ setSlug: string }>();
16-
20+
const { edition } = useFestivalEdition();
1721
const { state: urlState } = useUrlState();
18-
const {
19-
currentSet,
20-
user,
21-
userVote,
22-
loading,
23-
handleVote,
24-
getVoteCount,
25-
netVoteScore,
26-
} = useSetDetail(setSlug);
22+
const setQuery = useSetBySlugQuery({
23+
slug: setSlug,
24+
editionId: edition?.id,
25+
});
26+
const { userVote, loading, handleVote, getVoteCount, netVoteScore } =
27+
useSetDetail(setQuery.data?.id);
2728

2829
if (loading) {
2930
return <ArtistLoadingState />;
3031
}
3132

32-
if (!currentSet) {
33+
if (!setQuery.data) {
3334
return <ArtistNotFoundState />;
3435
}
35-
36+
const currentSet = setQuery.data;
3637
const isMultiArtistSet = currentSet.artists.length > 1;
3738
const primaryArtist = currentSet.artists[0];
3839

src/pages/SetDetails/useSetDetail.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useOfflineVoting } from "@/hooks/useOfflineVoting";
44
import { useUserPermissionsQuery } from "@/hooks/queries/auth/useUserPermissions";
55
import { useOfflineSetsData } from "@/hooks/useOfflineSetsData";
66

7-
export function useSetDetail(slug: string | undefined) {
7+
export function useSetDetail(setId: string | undefined) {
88
const { user, loading: authLoading } = useAuth();
99
const { data: canEdit = false, isLoading: isLoadingPermissions } =
1010
useUserPermissionsQuery(user?.id, "edit_artists");
@@ -14,16 +14,16 @@ export function useSetDetail(slug: string | undefined) {
1414

1515
const sets = setsQuery.sets;
1616
const currentSet = useMemo(() => {
17-
if (!slug || !sets.length) {
17+
if (!setId || !sets.length) {
1818
return null;
1919
}
2020

21-
return sets.find((a) => a.slug === slug) || null;
22-
}, [slug, sets]);
21+
return sets.find((a) => a.id === setId) || null;
22+
}, [setId, sets]);
2323

2424
async function handleVoteAction(voteType: number) {
25-
if (!currentSet?.id) return;
26-
await handleVote(currentSet.id, voteType);
25+
if (!setId) return;
26+
await handleVote(setId, voteType);
2727
}
2828

2929
function getVoteCount(voteType: number) {
@@ -38,11 +38,9 @@ export function useSetDetail(slug: string | undefined) {
3838
? 2 * getVoteCount(2) + getVoteCount(1) - getVoteCount(-1)
3939
: 0;
4040

41-
const userVote = userVotes[currentSet?.id || ""] || null;
41+
const userVote = userVotes[setId || ""] || null;
4242

4343
return {
44-
currentSet,
45-
user,
4644
userVote,
4745
loading: authLoading || isLoadingPermissions || setsQuery.loading,
4846
canEdit,

0 commit comments

Comments
 (0)