Verified Commit 7c83acc3 authored by Hugo Kerstens's avatar Hugo Kerstens
Browse files

Different texts for single page unstructured exam

parent 83178b73
...@@ -16,18 +16,19 @@ const groupBy = (array, key) => ...@@ -16,18 +16,19 @@ const groupBy = (array, key) =>
}, {}) }, {})
const ExamContent = (props) => { const ExamContent = (props) => {
if (props.problems.length === 0) { const problemCount = props.problems.length
return <p className='is-size-5 has-text-centered'>No problems</p> const pages = problemCount > 0 ? groupBy(props.problems, 'page') : {0: []}
}
const pages = groupBy(props.problems, 'page') const pageCount = Object.keys(pages).length
const pageTitle = pageCount === 1 && 'Problem list'
const addPageButtonText = pageCount === 1 ? 'Specify pages' : 'Add page'
return ( return (
<div> <div>
{Object.keys(pages).map(page => ( {Object.keys(pages).map(page => (
<div className='card page-card' key={page}> <div className='card page-card' key={page}>
<header className='card-header'> <header className='card-header'>
<p className='card-header-title'> <p className='card-header-title'>
{`Page ${(parseInt(page) + 1)}`} {pageTitle || `Page ${(parseInt(page) + 1)}`}
</p> </p>
<a <a
className='card-header-icon' className='card-header-icon'
...@@ -40,7 +41,7 @@ const ExamContent = (props) => { ...@@ -40,7 +41,7 @@ const ExamContent = (props) => {
</header> </header>
<div className='card-content'> <div className='card-content'>
<div className='content'> <div className='content'>
{pages[page].map(p => ( {problemCount ? pages[page].map(p => (
<button <button
className={'button problem is-fullwidth ' + className={'button problem is-fullwidth ' +
(props.selectedProblemId === p.id ? 'is-primary' : '')} (props.selectedProblemId === p.id ? 'is-primary' : '')}
...@@ -49,11 +50,16 @@ const ExamContent = (props) => { ...@@ -49,11 +50,16 @@ const ExamContent = (props) => {
> >
{p.name} {p.name}
</button> </button>
))} )) : <p>No problems</p>}
</div> </div>
</div> </div>
</div> </div>
))} ))}
<button
className='button problem is-link is-fullwidth'
onClick={props.addPage}>
<span>{addPageButtonText}</span>
</button>
</div> </div>
) )
} }
...@@ -310,13 +316,8 @@ class PanelEditUnstructured extends React.Component { ...@@ -310,13 +316,8 @@ class PanelEditUnstructured extends React.Component {
problems={this.state.problems} problems={this.state.problems}
selectedProblemId={this.state.selectedProblemId} selectedProblemId={this.state.selectedProblemId}
selectProblem={this.selectProblem} selectProblem={this.selectProblem}
createProblem={this.createProblem} /> createProblem={this.createProblem}
addPage={this.addPage} />
<button
className='button problem is-link is-fullwidth'
onClick={this.addPage}>
<span>Add Page</span>
</button>
</div> </div>
</div> </div>
</div> </div>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment