| 1 |
import { Component } from '@wordpress/element'; |
| 2 |
import { withDispatch } from '@wordpress/data'; |
| 3 |
import { compose } from '@wordpress/compose'; |
| 4 |
import { __ } from '@wordpress/i18n'; |
| 5 |
|
| 6 |
class ButtonHint extends Component { |
| 7 |
/** |
| 8 |
* Callback to show hint of question |
| 9 |
*/ |
| 10 |
showHint = () => { |
| 11 |
const { showHint, question } = this.props; |
| 12 |
|
| 13 |
showHint( question.id, ! question.showHint ); |
| 14 |
}; |
| 15 |
|
| 16 |
render() { |
| 17 |
const { question } = this.props; |
| 18 |
|
| 19 |
return ( |
| 20 |
question.hint ? ( |
| 21 |
<button className="btn-show-hint" onClick={ this.showHint }> |
| 22 |
<span>{ __( 'Hint', 'learnpress' ) }</span> |
| 23 |
</button> |
| 24 |
) : '' |
| 25 |
); |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
export default compose( |
| 30 |
withDispatch( ( dispatch, { id } ) => { |
| 31 |
const { |
| 32 |
showHint, |
| 33 |
} = dispatch( 'learnpress/quiz' ); |
| 34 |
|
| 35 |
return { |
| 36 |
showHint( id, show ) { |
| 37 |
showHint( id, show ); |
| 38 |
}, |
| 39 |
}; |
| 40 |
} ) |
| 41 |
)( ButtonHint ); |
| 42 |
|