Skip to content

Commit 47c7c7d

Browse files
Add summary to preview (#3904)
- Joins all content_html together by solution_type - Supports 'detailed' and 'summary' solution types in preview
1 parent 218b046 commit 47c7c7d

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

shared/src/components/question/index.jsx

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,27 @@ class Question extends React.Component {
135135
}
136136

137137
if (this.hasSolution()) {
138-
solution =
139-
<div className="detailed-solution">
140-
<div className="header">
141-
Detailed solution:
142-
</div>
143-
<ArbitraryHtmlAndMath
144-
{...htmlAndMathProps}
145-
className="solution"
146-
block={true}
147-
html={map(collaborator_solutions.filter(
148-
(sol) => sol.solution_type === 'detailed'
149-
), 'content_html').join('')} />
150-
</div>;
138+
const solutionTypes = ['detailed', 'summary'];
139+
solution = solutionTypes.map((type) => {
140+
const solutionHTML = collaborator_solutions
141+
.filter((sol) => sol.solution_type === type)
142+
.map((sol) => sol.content_html)
143+
.join('');
144+
return solutionHTML === ''
145+
? null
146+
: (
147+
<div className="detailed-solution">
148+
<div className="header">
149+
{`${type[0].toUpperCase()}${type.slice(1)} solution:`}
150+
</div>
151+
<ArbitraryHtmlAndMath
152+
{...htmlAndMathProps}
153+
className="solution"
154+
block={true}
155+
html={solutionHTML} />
156+
</div>
157+
);
158+
})
151159
}
152160

153161
return (

0 commit comments

Comments
 (0)