Skip to content

Commit

Permalink
feat: add error messages for invalid test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ckcherry23 committed Nov 15, 2023
1 parent a1b6823 commit 2228814
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions frontend/src/pages/questions/_form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ if __name__ == "__main__":
target = int(input())
print(" ".join(twoSum(nums, target)))`,

'java': `import java.util.*;
'java': `import java.util.*;
class Solution {
public int[] twoSum(int[] nums, int target) {
Expand All @@ -66,7 +66,7 @@ class Solution {
}
}`,

'c++': `#include <iostream>
'c++': `#include <iostream>
#include <vector>
using namespace std;
Expand Down Expand Up @@ -105,7 +105,7 @@ interface QuestionsFormProps {
export default function QuestionsForm({
form,
onSubmit,
onDelete = () => {},
onDelete = () => { },
type = "add",
loading = false,
}: QuestionsFormProps) {
Expand Down Expand Up @@ -179,7 +179,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" }} defaultValue={"Write your question here in markdown format. Your question may be sanitized to remove harmful HTML tags."} value={field.value} onChange={(e) => {
field.onChange(e);
forceUpdate();
}} />
Expand Down Expand Up @@ -210,7 +210,7 @@ export default function QuestionsForm({
})}
<div className="flex gap-x-4">
<Button variant="outline" className="border-primary text-primary" onClick={(e) => {
e.stopPropagation(); e.preventDefault();
e.stopPropagation(); e.preventDefault();
form.setValue('testCasesInputs', [...testCasesInputs, ""]);
form.setValue('testCasesOutputs', [...testCasesOutputs, ""]);
forceUpdate();
Expand All @@ -222,6 +222,8 @@ export default function QuestionsForm({
forceUpdate();
}}>Clear Test Cases</Button>
</div>
{ form.getFieldState('testCasesInputs').invalid && <p className="text-destructive text-sm">Test case inputs cannot be empty</p> }
{ form.getFieldState('testCasesOutputs').invalid && <p className="text-destructive text-sm">Test case outputs cannot be empty</p> }
<FormField
control={form.control}
name="defaultCode.c++"
Expand All @@ -246,9 +248,9 @@ export default function QuestionsForm({
<FormLabel>Default Java Code</FormLabel>
<FormControl>
<Editor height="50vh" defaultLanguage="java" theme="vs-dark" defaultValue={defaultCodes["java"]} value={field.value} onChange={(e) => {
field.onChange(e);
forceUpdate();
}} />
field.onChange(e);
forceUpdate();
}} />
</FormControl>
<FormMessage />
</FormItem>
Expand All @@ -261,10 +263,10 @@ export default function QuestionsForm({
<FormItem>
<FormLabel>Default Python Code</FormLabel>
<FormControl>
<Editor height="50vh" defaultLanguage="python" theme="vs-dark" defaultValue={defaultCodes["python"]} value={field.value} onChange={(e) => {
field.onChange(e);
forceUpdate();
}} />
<Editor height="50vh" defaultLanguage="python" theme="vs-dark" defaultValue={defaultCodes["python"]} value={field.value} onChange={(e) => {
field.onChange(e);
forceUpdate();
}} />
</FormControl>
<FormMessage />
</FormItem>
Expand Down Expand Up @@ -293,8 +295,9 @@ export default function QuestionsForm({
) : (
<div className="flex gap-x-6">
<Button type="submit" disabled={loading} onClick={e => {
e.stopPropagation(); e.preventDefault();
onSubmit(form.getValues());
e.stopPropagation();
e.preventDefault();
onSubmit(form.getValues());
}}>Save Changes</Button>
<Button
variant="outline"
Expand Down

0 comments on commit 2228814

Please sign in to comment.