Skip to content

Commit 32bfb6a

Browse files
authored
Merge pull request #18 from ZiHawkEye/mission-editing
changed manage qn UI
2 parents 47e7da6 + 74dbeda commit 32bfb6a

File tree

1 file changed

+34
-28
lines changed

1 file changed

+34
-28
lines changed

src/components/incubator/editingWorkspaceSideContent/ManageQuestionTab.tsx

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ButtonGroup, Classes, Dialog, Intent } from '@blueprintjs/core';
1+
import { Button, ButtonGroup, Classes, Dialog, Intent } from '@blueprintjs/core';
22
import { IconNames } from '@blueprintjs/icons';
33
import * as React from 'react';
44

@@ -33,63 +33,70 @@ export class ManageQuestionTab extends React.Component<IProps, IState> {
3333
return (
3434
<div>
3535
{this.confirmSaveOverlay()}
36-
{this.manageQuestionTab()}
36+
{this.props.assessment.questions.map((q, index) => (
37+
<div key={index}>
38+
Question {index + 1}
39+
<br />
40+
<Button className="mcq-option col-xs-12" minimal={true}>
41+
<Markdown
42+
content={q.content.length > 200 ? q.content.substring(0, 200) + '...' : q.content}
43+
/>
44+
</Button>
45+
{this.manageQuestionTab(index)}
46+
<br />
47+
</div>
48+
))}
3749
</div>
3850
);
3951
}
4052

41-
private manageQuestionTab = () => {
42-
const index = this.props.questionId;
53+
private manageQuestionTab = (index: number) => {
4354
return (
4455
<div>
4556
{controlButton(
46-
'Clone Current Question',
57+
`Clone Question ${index + 1}`,
4758
IconNames.DOCUMENT,
4859
this.confirmSave(
49-
this.makeQuestion(() =>
50-
deepCopy(this.props.assessment.questions[this.props.questionId])
51-
)
60+
this.makeQuestion(() => deepCopy(this.props.assessment.questions[index]), index)
5261
)
5362
)}
63+
{controlButton(
64+
`Delete Question ${index + 1}`,
65+
IconNames.REMOVE,
66+
this.confirmSave(this.deleteQuestion(index))
67+
)}
5468
<br />
5569
{controlButton(
5670
'Insert Programming Question',
5771
IconNames.FONT,
58-
this.confirmSave(this.makeQuestion(programmingTemplate))
72+
this.confirmSave(this.makeQuestion(programmingTemplate, index))
5973
)}
6074
{controlButton(
6175
'Insert MCQ Question',
6276
IconNames.CONFIRM,
63-
this.confirmSave(this.makeQuestion(mcqTemplate))
64-
)}
65-
<br />
66-
{controlButton(
67-
'Delete Current Question',
68-
IconNames.REMOVE,
69-
this.confirmSave(this.deleteQuestion)
77+
this.confirmSave(this.makeQuestion(mcqTemplate, index))
7078
)}
7179
<br />
7280
{index > 0
7381
? controlButton(
74-
'Shift Question Left',
75-
IconNames.CARET_LEFT,
76-
this.confirmSave(this.shiftQuestion(-1))
82+
`Shift Question ${index + 1} Up`,
83+
IconNames.CARET_UP,
84+
this.confirmSave(this.shiftQuestion(-1, index))
7785
)
7886
: undefined}
7987
{index < this.props.assessment.questions.length - 1
8088
? controlButton(
81-
'Shift Question Right',
82-
IconNames.CARET_RIGHT,
83-
this.confirmSave(this.shiftQuestion(1))
89+
`Shift Question ${index + 1} Down`,
90+
IconNames.CARET_DOWN,
91+
this.confirmSave(this.shiftQuestion(1, index))
8492
)
8593
: undefined}
8694
</div>
8795
);
8896
};
8997

90-
private shiftQuestion = (dir: number) => () => {
98+
private shiftQuestion = (dir: number, index: number) => () => {
9199
const assessment = this.props.assessment;
92-
const index = this.props.questionId;
93100
const newIndex = index + dir;
94101
if (newIndex >= 0 && newIndex < assessment.questions.length) {
95102
const question = assessment.questions[index];
@@ -102,20 +109,19 @@ export class ManageQuestionTab extends React.Component<IProps, IState> {
102109
}
103110
};
104111

105-
private makeQuestion = (template: () => any) => () => {
112+
private makeQuestion = (template: () => any, index: number) => () => {
106113
const assessment = this.props.assessment;
107-
const index = this.props.questionId + 1;
114+
index = index + 1;
108115
const questions = assessment.questions;
109116
questions.splice(index, 0, template());
110117
assessment.questions = questions;
111118
this.props.updateAssessment(assessment);
112119
history.push('/incubator/-1/' + index.toString());
113120
};
114121

115-
private deleteQuestion = () => {
122+
private deleteQuestion = (index: number) => () => {
116123
const assessment = this.props.assessment;
117124
let questions = assessment.questions;
118-
const index = this.props.questionId;
119125
if (questions.length > 1) {
120126
questions = questions.slice(0, index).concat(questions.slice(index + 1));
121127
}

0 commit comments

Comments
 (0)