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

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