Skip to content

Commit

Permalink
Add default solution and description
Browse files Browse the repository at this point in the history
  • Loading branch information
chunweii committed Nov 15, 2023
1 parent 780ee56 commit af7ef0a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions frontend/src/pages/questions/_form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
}, []);

Expand Down Expand Up @@ -179,7 +187,7 @@ export default function QuestionsForm({
<FormItem>
<FormLabel>Question Description</FormLabel>
<FormControl>
<Editor height="50vh" defaultLanguage="markdown" theme="vs-dark" options={{ wordWrap: "on" }} defaultValue={"Write your question here in markdown format. Your question may be sanitized to remove harmful HTML tags."} value={field.value} onChange={(e) => {
<Editor height="50vh" defaultLanguage="markdown" theme="vs-dark" options={{ wordWrap: "on" }} value={field.value} onChange={(e) => {
field.onChange(e);
forceUpdate();
}} />
Expand Down

0 comments on commit af7ef0a

Please sign in to comment.