Skip to content

Commit d1d65f8

Browse files
committed
Fixing
1 parent 9125d92 commit d1d65f8

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

app/play/page.tsx

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import React, { useState } from 'react';
3+
import React, { useState, Suspense } from 'react';
44
import { useSearchParams } from 'next/navigation';
55
import Link from 'next/link';
66
import { useCardsForReview, useCreateReviewEventMutation } from '@/hooks/queryHooks';
@@ -19,7 +19,8 @@ function buildPlayQueryString(currentParams: URLSearchParams, newParams: Record<
1919
return params.toString();
2020
}
2121

22-
export default function GlobalPlayPage() {
22+
// Original page content moved to this client component
23+
function PlayPageClientContent() {
2324
const searchParams = useSearchParams();
2425
const { token, isLoading: isAuthLoading } = useAuth();
2526

@@ -59,7 +60,6 @@ export default function GlobalPlayPage() {
5960
onSuccess: () => {
6061
const nextIndex = currentCardIndex + 1;
6162
setCurrentCardIndex(nextIndex);
62-
// Don't automatically refetch, let user decide to play again
6363
},
6464
onError: (err) => {
6565
alert(`Failed to record review: ${err.message}`);
@@ -69,11 +69,10 @@ export default function GlobalPlayPage() {
6969
};
7070

7171
const handlePlayAgain = () => {
72-
refetch(); // Refetch the card sequence
72+
refetch();
7373
setCurrentCardIndex(0);
7474
};
7575

76-
// Determine loading state
7776
const isLoading = isAuthLoading || isLoadingCards;
7877

7978
if (isLoading) {
@@ -106,7 +105,6 @@ export default function GlobalPlayPage() {
106105
);
107106
}
108107

109-
// Finished state
110108
if (currentCardIndex >= reviewSequence.length) {
111109
return (
112110
<div className="text-center space-y-6 py-10">
@@ -133,26 +131,24 @@ export default function GlobalPlayPage() {
133131
<h1 className="text-lg sm:text-xl font-semibold text-gray-700 text-center order-first sm:order-none">
134132
Reviewing All Decks ({strategy === 'missedFirst' ? 'Missed First' : 'Random'}, {limit})
135133
</h1>
136-
{/* Strategy Switch Links */}
137134
<div className="text-center sm:text-right text-xs sm:min-w-[100px]">
138135
{strategy === 'random' ? (
139136
<Link
140137
href={`/play?${buildPlayQueryString(searchParams, { strategy: 'missedFirst' })}`}
141138
className="text-primary hover:underline"
142-
replace // Use replace to avoid bloating history
139+
replace
143140
>
144141
Switch to Missed First
145142
</Link>
146143
) : (
147144
<Link
148145
href={`/play?${buildPlayQueryString(searchParams, { strategy: 'random' })}`}
149146
className="text-primary hover:underline"
150-
replace // Use replace to avoid bloating history
147+
replace
151148
>
152149
Switch to Random
153150
</Link>
154151
)}
155-
{/* TODO: Add options for limit, flipped? */}
156152
</div>
157153
</div>
158154
<hr className="border-gray-300" />
@@ -169,4 +165,22 @@ export default function GlobalPlayPage() {
169165
/>
170166
</div>
171167
);
168+
}
169+
170+
// Loading component for Suspense fallback
171+
function LoadingState() {
172+
return (
173+
<div className="flex justify-center items-center py-10">
174+
<Spinner /> <span className="ml-2 text-gray-500">Loading play options...</span>
175+
</div>
176+
);
177+
}
178+
179+
// Default export is now the server component wrapping the client component in Suspense
180+
export default function GlobalPlayPage() {
181+
return (
182+
<Suspense fallback={<LoadingState />}>
183+
<PlayPageClientContent />
184+
</Suspense>
185+
);
172186
}

0 commit comments

Comments
 (0)