Skip to content

Commit

Permalink
ADD back questions markdown preview
Browse files Browse the repository at this point in the history
  • Loading branch information
wabscale committed Feb 12, 2022
1 parent 67a0105 commit 5b4bca5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
11 changes: 7 additions & 4 deletions api/anubis/views/public/questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
from sqlalchemy.sql import func

from anubis.lms.assignments import get_assignment_due_date
from anubis.lms.courses import is_course_admin
from anubis.lms.questions import get_assigned_questions
from anubis.models import AssignedQuestionResponse, AssignedStudentQuestion, Assignment, db
from anubis.utils.auth.http import require_user
from anubis.utils.auth.user import current_user
from anubis.utils.data import req_assert
from anubis.utils.http import error_response, success_response
from anubis.utils.http.decorators import json_endpoint, json_response, load_from_id, verify_shape, verify_data_shape
from anubis.utils.http.decorators import json_endpoint, json_response, load_from_id, verify_data_shape

questions_ = Blueprint("public-questions", __name__, url_prefix="/public/questions")

Expand Down Expand Up @@ -82,7 +81,7 @@ def public_questions_save(assignment_id: str, questions: list):
AssignedQuestionResponse.assigned_question_id.in_([
assigned_question.id for assigned_question in assigned_questions
]),
).group_by(AssignedQuestionResponse.assigned_question_id, AssignedQuestionResponse.id)\
).group_by(AssignedQuestionResponse.assigned_question_id, AssignedQuestionResponse.id) \
.having(func.max(AssignedQuestionResponse.created)).all()

req_assert(len(assigned_questions) > 0, message='No questions assigned')
Expand All @@ -107,10 +106,14 @@ def public_questions_save(assignment_id: str, questions: list):
req_assert(isinstance(response, str), message="response must be a string")

# Skip creating a new response if it matches the last one
skip = False
for last_response in last_responses:
if last_response.assigned_question_id == assignment_question_id:
if last_response.response == response:
continue
skip = True
break
if skip:
continue

# Create a new response
res = AssignedQuestionResponse(assigned_question_id=assigned_question.id, response=response)
Expand Down
25 changes: 23 additions & 2 deletions web/src/components/core/Questions/QuestionEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import React, {useState} from 'react';
import Typography from '@material-ui/core/Typography';
import {makeStyles} from '@material-ui/core/styles';
import AceEditor from 'react-ace';
import gfm from 'remark-gfm';
import ReactMarkdownWithHtml from 'react-markdown/with-html';

import 'ace-builds/src-min-noconflict/theme-monokai';
import 'ace-builds/src-min-noconflict/mode-c_cpp';
import 'ace-builds/src-min-noconflict/mode-python';
import 'ace-builds/src-min-noconflict/mode-markdown';
import Button from '@material-ui/core/Button';
import Dialog from '@material-ui/core/Dialog';
Expand All @@ -21,12 +24,20 @@ const useStyles = makeStyles((theme) => ({
root: {
minWidth: 500,
},
markdown: {
fontSize: '16px',
margin: theme.spacing(1),
},
subTitle: {
color: '#888888',
},
}));

export default function QuestionEditor({question, updateResponse, saveResponse}) {
const classes = useStyles();
const [showSolution, setShowSolution] = useState(false);
const response = question?.response?.text ?? '';
const mode = question?.question?.code_language || 'markdown';

return (
<Box className={classes.root}>
Expand All @@ -46,11 +57,21 @@ export default function QuestionEditor({question, updateResponse, saveResponse})
</Button>
</DialogActions>
</Dialog>
<Typography variant={'subtitle1'}>
<Typography variant={'subtitle1'} className={classes.subTitle}>
Question {question.question.pool}
</Typography>
<ReactMarkdownWithHtml
className={classes.markdown}
plugins={[gfm]}
allowDangerousHtml
>
{question?.question?.question ?? ''}
</ReactMarkdownWithHtml>
<Typography variant={'subtitle1'} className={classes.subTitle}>
Your Answer:
</Typography>
<AceEditor
mode={question.code_language ?? 'markdown'}
mode={mode}
theme="monokai"
value={response}
onChange={updateResponse}
Expand Down

0 comments on commit 5b4bca5

Please sign in to comment.