From af7ef0a7dffad0a047978a667cb1dfd4f47be5c6 Mon Sep 17 00:00:00 2001 From: chunweii <47494777+chunweii@users.noreply.github.com> Date: Wed, 15 Nov 2023 13:12:04 +0800 Subject: [PATCH] Add default solution and description --- frontend/src/pages/questions/_form.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/frontend/src/pages/questions/_form.tsx b/frontend/src/pages/questions/_form.tsx index 487c3c06..cfaaa7f4 100644 --- a/frontend/src/pages/questions/_form.tsx +++ b/frontend/src/pages/questions/_form.tsx @@ -22,8 +22,8 @@ export const formSchema = z.object({ difficulty: z.enum(['easy', 'medium', 'hard']), topics: z.array(z.string().min(2).max(100)), description: z.string().min(2).max(10000), - testCasesInputs: z.array(z.string().min(1).max(10000)), - testCasesOutputs: z.array(z.string().min(1).max(10000)), + testCasesInputs: z.array(z.string().min(0).max(10000)), + testCasesOutputs: z.array(z.string().min(0).max(10000)), defaultCode: z.object({ "python": z.string().min(0).max(10000), "java": z.string().min(0).max(10000), @@ -117,7 +117,15 @@ export default function QuestionsForm({ const topics = ["Algorithms", "Arrays", "Bit Manipulation", "Brainteaser", "Data Structures", "Databases", "Graph", "Recursion", "Strings"].map(createTopic); useEffect(() => { - form.setValue('defaultCode', defaultCodes); + if (!form.getValues().defaultCode) { + form.setValue('defaultCode', defaultCodes); + } + if (!form.getValues().solution) { + form.setValue('solution', {python: defaultCodes['python']}); + } + if (!form.getValues().description) { + form.setValue('description', "Write your question here in markdown format. Your question may be sanitized to remove harmful HTML tags."); + } // eslint-disable-next-line react-hooks/exhaustive-deps }, []); @@ -179,7 +187,7 @@ export default function QuestionsForm({ Question Description - { + { field.onChange(e); forceUpdate(); }} />