You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ReloadButton.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import React, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3. import { translate } from '../../base/i18n';
  4. import { _reloadNow } from '../actions';
  5. /**
  6. * Implements a React Component for button for the overlays that will reload
  7. * the page.
  8. */
  9. class ReloadButton extends Component {
  10. /**
  11. * PageReloadOverlay component's property types.
  12. *
  13. * @static
  14. */
  15. static propTypes = {
  16. /**
  17. * Reloads the page.
  18. *
  19. * @type {Function}
  20. */
  21. _reloadNow: React.PropTypes.func,
  22. /**
  23. * The function to translate human-readable text.
  24. *
  25. * @public
  26. * @type {Function}
  27. */
  28. t: React.PropTypes.func,
  29. /**
  30. * The translation key for the text in the button.
  31. *
  32. * @type {string}
  33. */
  34. textKey: React.PropTypes.string.isRequired
  35. };
  36. /**
  37. * Renders the button for relaod the page if necessary.
  38. *
  39. * @private
  40. * @returns {ReactElement}
  41. */
  42. render() {
  43. const className
  44. = 'button-control button-control_overlay button-control_center';
  45. /* eslint-disable react/jsx-handler-names */
  46. return (
  47. <button
  48. className = { className }
  49. onClick = { this.props._reloadNow }>
  50. { this.props.t(this.props.textKey) }
  51. </button>
  52. );
  53. /* eslint-enable react/jsx-handler-names */
  54. }
  55. }
  56. /**
  57. * Maps part of redux actions to component's props.
  58. *
  59. * @param {Function} dispatch - Redux's {@code dispatch} function.
  60. * @private
  61. * @returns {Object}
  62. */
  63. function _mapDispatchToProps(dispatch: Function): Object {
  64. return {
  65. /**
  66. * Dispatches the redux action to reload the page.
  67. *
  68. * @protected
  69. * @returns {Object} Dispatched action.
  70. */
  71. _reloadNow() {
  72. return dispatch(_reloadNow());
  73. }
  74. };
  75. }
  76. export default translate(connect(undefined, _mapDispatchToProps)(ReloadButton));