Connect, collaborate, and grow with a community of TypeScript developers
fix: add solutions button not responding (#1092)
Ayush Kumar Yadav9bf33ca925d3
diff --git a/apps/web/src/app/[locale]/challenge/[slug]/solutions/_components/index.tsx b/apps/web/src/app/[locale]/challenge/[slug]/solutions/_components/index.tsxindex 6bd115a9..7d2dd37e 100644--- a/apps/web/src/app/[locale]/challenge/[slug]/solutions/_components/index.tsx+++ b/apps/web/src/app/[locale]/challenge/[slug]/solutions/_components/index.tsx@@ -50,7 +50,7 @@ export function Solutions({ challenge, slug }: Props) {const commentContainerRef = useRef<HTMLDivElement>(null);const [sortKey, setSortKey] = useState<(typeof sortKeys)[number]>(sortKeys[0]);const [page, setPage] = useState(1);- const queryKey = [`paginated-${challenge.id}-solutions`, sortKey.value, page];+ const queryKey = ['paginated-solutions', slug, page, sortKey.key, sortKey.order];const session = useSession();const handleChangePage = (page: number) => {@@ -78,7 +78,7 @@ export function Solutions({ challenge, slug }: Props) {const loggedInUserHasSolution = challenge.submission.length;return (- <div className="relative h-full">+ <div className="flex h-full flex-col">{view === 'editor' && (<SolutionEditor challenge={challenge} dismiss={() => setView('list')} />)}@@ -89,12 +89,12 @@ export function Solutions({ challenge, slug }: Props) {<>{status === 'loading' && <SolutionsSkeleton />}{status === 'success' && (- <div className="bg-background/70 dark:bg-muted/70 absolute right-0 top-0 flex w-full justify-end border-b border-zinc-300 p-2 backdrop-blur-sm dark:border-zinc-700">+ <div className="bg-background/70 dark:bg-muted/70 flex w-full justify-end border-b border-zinc-300 p-2 backdrop-blur-sm dark:border-zinc-700"><SubmitSolution disabled={Boolean(!loggedInUserHasSolution)} setView={setView} /></div>)}<div- className="custom-scrollable-element relative flex h-full flex-col overflow-y-auto pt-12"+ className="custom-scrollable-element relative flex h-full flex-col overflow-y-auto"ref={commentContainerRef}><div>diff --git a/apps/web/src/app/[locale]/challenge/[slug]/solutions/_components/solution-editor.tsx b/apps/web/src/app/[locale]/challenge/[slug]/solutions/_components/solution-editor.tsxindex 019b9d77..dc0e5c5f 100644--- a/apps/web/src/app/[locale]/challenge/[slug]/solutions/_components/solution-editor.tsx+++ b/apps/web/src/app/[locale]/challenge/[slug]/solutions/_components/solution-editor.tsx@@ -12,6 +12,7 @@ import { RichMarkdownEditor } from '~/components/rich-markdown-editor';import { createNoProfanitySchemaWithValidate } from '~/utils/antiProfanityZod';import type { ChallengeSolution } from '../getSolutionRouteData';import { postSolution } from './_actions';+import { useQueryClient } from '@tanstack/react-query';const getDefaultMarkdown = (solution: string) => `## Thoughts@@ -45,11 +46,12 @@ interface Props {export function SolutionEditor({ dismiss, challenge }: Props) {const { slug } = useParams();+ const queryClient = useQueryClient();const session = useSession();const form = useForm<FormSchema>({resolver: zodResolver(formSchema),defaultValues: {- title: `${session.user.name}'s Solution`,+ title: `${session.data?.user.name}'s Solution`,content: getDefaultMarkdown(challenge.submission[0]?.code ?? ''),},});@@ -61,7 +63,7 @@ export function SolutionEditor({ dismiss, challenge }: Props) {challengeId: challenge.id,description: data.content ?? '',slug: slug as string,- title: data.title ?? `${session.user.name}'s Solution`,+ title: data.title ?? `${session.data?.user.name}'s Solution`,userId: session.data?.user.id!,});@@ -75,6 +77,8 @@ export function SolutionEditor({ dismiss, challenge }: Props) {title: 'Uh oh! Something went wrong. Please try again.',});} finally {+ // Todo: It just works+ queryClient.refetchQueries([`paginated-solutions`, slug]);dismiss();}};