-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from jolynloh/feature/admin-add-test-cases
Add and store test cases and code templates
- Loading branch information
Showing
16 changed files
with
750 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
frontend/src/components/QuestionCodeTemplates/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import { HelpOutlined } from "@mui/icons-material"; | ||
import { | ||
Box, | ||
IconButton, | ||
Stack, | ||
TextField, | ||
ToggleButton, | ||
ToggleButtonGroup, | ||
Tooltip, | ||
Typography, | ||
} from "@mui/material"; | ||
import { useState } from "react"; | ||
import { CODE_TEMPLATES_TOOLTIP_MESSAGE } from "../../utils/constants"; | ||
|
||
interface QuestionCodeTemplatesProps { | ||
codeTemplates: { | ||
[key: string]: string; | ||
}; | ||
setCodeTemplates: React.Dispatch< | ||
React.SetStateAction<{ | ||
[key: string]: string; | ||
}> | ||
>; | ||
} | ||
|
||
const QuestionCodeTemplates: React.FC<QuestionCodeTemplatesProps> = ({ | ||
codeTemplates, | ||
setCodeTemplates, | ||
}) => { | ||
const [selectedLanguage, setSelectedLanguage] = useState<string>("python"); | ||
|
||
const handleLanguageChange = ( | ||
_: React.MouseEvent<HTMLElement>, | ||
language: string | ||
) => { | ||
if (language) { | ||
setSelectedLanguage(language); | ||
} | ||
}; | ||
|
||
const handleCodeChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
const { value } = event.target; | ||
setCodeTemplates((prevTemplates) => ({ | ||
...prevTemplates, | ||
[selectedLanguage]: value, | ||
})); | ||
}; | ||
|
||
const handleTabKeys = (event: any) => { | ||
const { value } = event.target; | ||
|
||
if (event.key === "Tab") { | ||
event.preventDefault(); | ||
|
||
const cursorPosition = event.target.selectionStart; | ||
const cursorEndPosition = event.target.selectionEnd; | ||
const tab = "\t"; | ||
|
||
event.target.value = | ||
value.substring(0, cursorPosition) + | ||
tab + | ||
value.substring(cursorEndPosition); | ||
|
||
event.target.selectionStart = cursorPosition + 1; | ||
event.target.selectionEnd = cursorPosition + 1; | ||
} | ||
}; | ||
|
||
return ( | ||
<Box display="flex" flexDirection="column" marginTop={2}> | ||
<Stack direction="row" alignItems="center"> | ||
<Typography variant="h6">Code Templates</Typography> | ||
<Tooltip | ||
title={ | ||
<Typography variant="body2"> | ||
<span | ||
dangerouslySetInnerHTML={{ | ||
__html: CODE_TEMPLATES_TOOLTIP_MESSAGE, | ||
}} | ||
/> | ||
</Typography> | ||
} | ||
placement="right" | ||
arrow | ||
> | ||
<IconButton> | ||
<HelpOutlined fontSize="small" /> | ||
</IconButton> | ||
</Tooltip> | ||
</Stack> | ||
<ToggleButtonGroup | ||
value={selectedLanguage} | ||
exclusive | ||
onChange={handleLanguageChange} | ||
sx={{ | ||
marginY: 2, | ||
height: 42, | ||
}} | ||
fullWidth | ||
> | ||
<ToggleButton value="python">Python</ToggleButton> | ||
<ToggleButton value="java">Java</ToggleButton> | ||
<ToggleButton value="c">C</ToggleButton> | ||
</ToggleButtonGroup> | ||
|
||
<TextField | ||
label={ | ||
codeTemplates[selectedLanguage] | ||
? `` | ||
: `${ | ||
selectedLanguage.charAt(0).toUpperCase() + | ||
selectedLanguage.slice(1) | ||
} Code Template` | ||
} | ||
variant="outlined" | ||
multiline | ||
rows={8} | ||
sx={{ | ||
"& .MuiOutlinedInput-root": { | ||
fontFamily: "monospace", | ||
}, | ||
}} | ||
value={codeTemplates[selectedLanguage]} | ||
onChange={handleCodeChange} | ||
onKeyDown={handleTabKeys} | ||
fullWidth | ||
/> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default QuestionCodeTemplates; |
Oops, something went wrong.