From 8aee5e30578b3e7cfd6aa5263f4a78bc0e389590 Mon Sep 17 00:00:00 2001 From: doombubbles Date: Thu, 16 Jan 2025 16:39:25 -0800 Subject: [PATCH] Minor graphql fixes --- spellsource-web/src/lib/apollo.tsx | 7 +++---- spellsource-web/src/lib/art-generation.ts | 7 +++++-- spellsource-web/src/pages/_app.tsx | 5 +---- spellsource-web/src/pages/api/art/generate.ts | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/spellsource-web/src/lib/apollo.tsx b/spellsource-web/src/lib/apollo.tsx index 7c26b80151..b8d785ae44 100644 --- a/spellsource-web/src/lib/apollo.tsx +++ b/spellsource-web/src/lib/apollo.tsx @@ -2,19 +2,18 @@ import { ApolloClient, ApolloProvider, createHttpLink, InMemoryCache } from "@ap import { setContext } from "@apollo/client/link/context"; import { FunctionComponent, PropsWithChildren, RefObject, useEffect, useRef, useState } from "react"; import { useSession } from "next-auth/react"; -import { usePrevious } from "react-use"; import { graphqlHost } from "./config"; export const ApolloClientProvider: FunctionComponent = ({ children }) => { const { data: session, status } = useSession(); - const prevStatus = usePrevious(status); const tokenRef = useRef(session?.token?.accessToken ?? null); const [apolloClient] = useState(() => createApolloClient(tokenRef)); useEffect(() => { - if (prevStatus === "authenticated" && status === "unauthenticated") { - console.log("Clearing the cache"); + if (status === "authenticated") { apolloClient.resetStore(); + } else { + apolloClient.clearStore(); } }, [status]); diff --git a/spellsource-web/src/lib/art-generation.ts b/spellsource-web/src/lib/art-generation.ts index 7cd057b156..0f6b36f19e 100644 --- a/spellsource-web/src/lib/art-generation.ts +++ b/spellsource-web/src/lib/art-generation.ts @@ -80,8 +80,11 @@ export const generateArt = async (p1: any) => { }), }) .then(async (res) => { - if (isArray(res.body)) { - await onGenerateArt(block, res.body); + const body = await res.json(); + if (isArray(body)) { + await onGenerateArt(block, body); + } else { + console.error(body); } }) .finally(() => onRequestStop(block)); diff --git a/spellsource-web/src/pages/_app.tsx b/spellsource-web/src/pages/_app.tsx index 1e67b06dff..47c10ce9cd 100644 --- a/spellsource-web/src/pages/_app.tsx +++ b/spellsource-web/src/pages/_app.tsx @@ -5,7 +5,6 @@ import { ApolloClientProvider } from "../lib/apollo"; import { SessionProvider } from "next-auth/react"; import "bootstrap/dist/css/bootstrap.min.css"; import Head from "next/head"; -import { SSRProvider } from "react-bootstrap"; export default ({ Component, pageProps }: AppProps) => { return ( @@ -14,9 +13,7 @@ export default ({ Component, pageProps }: AppProps) => { - - - + ); diff --git a/spellsource-web/src/pages/api/art/generate.ts b/spellsource-web/src/pages/api/art/generate.ts index 46a45f884a..16dd85e40f 100644 --- a/spellsource-web/src/pages/api/art/generate.ts +++ b/spellsource-web/src/pages/api/art/generate.ts @@ -101,7 +101,7 @@ export default async (req: NextApiRequest, res: NextApiResponse) => { return; } - const result = await generateArt(req.body); + const result = await generateArt(JSON.parse(req.body)); res.status(200).json(result); };