Skip to content

Commit

Permalink
fix: remove AnimatePresence from Game page and add animation to next …
Browse files Browse the repository at this point in the history
…round
  • Loading branch information
agrattan0820 committed Jul 26, 2024
1 parent 2613004 commit 0bc997b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 20 deletions.
30 changes: 14 additions & 16 deletions apps/client/src/app/room/[code]/game/[gameId]/game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,22 +174,20 @@ export default function Game({ gameInfo, session }: GameProps) {
<div className="absolute right-4 top-4 z-50 mt-4 md:right-8 md:top-8">
<Menu session={session} roomCode={gameInfo.game.roomCode} />
</div>
<AnimatePresence mode="wait">
{isMounted ? (
<CurrentGameComponent
key={state.value as string}
gameInfo={gameInfo}
state={state}
send={send}
hostId={hostId}
submittedPlayerIds={submittedPlayerIds}
currFaceOffQuestion={currFaceOffQuestion}
votedPlayers={votedPlayers}
leaderboard={leaderboard}
session={session}
/>
) : null}
</AnimatePresence>
{isMounted ? (
<CurrentGameComponent
key={state.value as string}
gameInfo={gameInfo}
state={state}
send={send}
hostId={hostId}
submittedPlayerIds={submittedPlayerIds}
currFaceOffQuestion={currFaceOffQuestion}
votedPlayers={votedPlayers}
leaderboard={leaderboard}
session={session}
/>
) : null}
</section>
</main>
);
Expand Down
1 change: 1 addition & 0 deletions apps/client/src/components/game/face-off.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const FaceOff = ({
setLoading(false);
setVoteSubmitted(true);
};

return (
<div className="mx-auto max-w-2xl">
{currQuestionGenerations ? (
Expand Down
8 changes: 6 additions & 2 deletions apps/client/src/components/game/next-round.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ type NextRoundProps = {

const NextRound = ({ nextQueryNum, totalQueries }: NextRoundProps) => {
return (
<h2 className="relative text-center text-3xl md:text-5xl">
<motion.h2
initial={{ y: 10, opacity: 0 }}
animate={{ y: 0, opacity: 1 }}
className="relative text-center text-3xl md:text-5xl"
>
Round{" "}
<span className="relative">
<span className="opacity-0">{nextQueryNum}</span>
Expand Down Expand Up @@ -37,7 +41,7 @@ const NextRound = ({ nextQueryNum, totalQueries }: NextRoundProps) => {
</span>
</span>{" "}
of {totalQueries}
</h2>
</motion.h2>
);
};

Expand Down
39 changes: 37 additions & 2 deletions apps/client/src/utils/query-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,49 @@
"use client";

import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import {
isServer,
QueryClient,
QueryClientProvider,
} from "@tanstack/react-query";

const queryClient = new QueryClient();
function makeQueryClient() {
return new QueryClient({
defaultOptions: {
queries: {
// With SSR, we usually want to set some default staleTime
// above 0 to avoid refetching immediately on the client
staleTime: 60 * 1000,
},
},
});
}

let browserQueryClient: QueryClient | undefined = undefined;

function getQueryClient() {
if (isServer) {
// Server: always make a new query client
return makeQueryClient();
} else {
// Browser: make a new query client if we don't already have one
// This is very important, so we don't re-make a new client if React
// suspends during the initial render. This may not be needed if we
// have a suspense boundary BELOW the creation of the query client
if (!browserQueryClient) browserQueryClient = makeQueryClient();
return browserQueryClient;
}
}

export default function QueryProvider({
children,
}: {
children: React.ReactNode;
}) {
// NOTE: Avoid useState when initializing the query client if you don't
// have a suspense boundary between this and the code that may
// suspend because React will throw away the client on the initial
// render if it suspends and there is no boundary
const queryClient = getQueryClient();
return (
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
);
Expand Down

0 comments on commit 0bc997b

Please sign in to comment.