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

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