Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

PageReloadOverlay.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // @flow
  2. import React from 'react';
  3. import { Text } from 'react-native';
  4. import { appNavigate, reloadNow } from '../../../app/actions';
  5. import { ColorSchemeRegistry } from '../../../base/color-scheme';
  6. import { ConfirmDialog } from '../../../base/dialog';
  7. import { translate } from '../../../base/i18n';
  8. import { connect } from '../../../base/redux';
  9. import { StyleType } from '../../../base/styles';
  10. import { setFatalError, setPageReloadOverlayCanceled } from '../../actions';
  11. import AbstractPageReloadOverlay, {
  12. abstractMapStateToProps,
  13. type Props as AbstractProps
  14. } from '../AbstractPageReloadOverlay';
  15. import OverlayFrame from './OverlayFrame';
  16. type Props = AbstractProps & {
  17. /**
  18. * The color-schemed stylesheet of the base/dialog feature.
  19. */
  20. _dialogStyles: StyleType
  21. }
  22. /**
  23. * Implements a React Component for page reload overlay. Shown before the
  24. * conference is reloaded. Shows a warning message and counts down towards the
  25. * reload.
  26. */
  27. class PageReloadOverlay extends AbstractPageReloadOverlay<Props> {
  28. _interval: IntervalID;
  29. /**
  30. * Initializes a new PageReloadOverlay instance.
  31. *
  32. * @param {Object} props - The read-only properties with which the new
  33. * instance is to be initialized.
  34. * @public
  35. */
  36. constructor(props) {
  37. super(props);
  38. this._onCancel = this._onCancel.bind(this);
  39. this._onReloadNow = this._onReloadNow.bind(this);
  40. }
  41. _onCancel: () => void;
  42. /**
  43. * Handle clicking of the "Cancel" button. It will navigate back to the
  44. * welcome page.
  45. *
  46. * @private
  47. * @returns {void}
  48. */
  49. _onCancel() {
  50. clearInterval(this._interval);
  51. this.props.dispatch(setPageReloadOverlayCanceled(this.props.error));
  52. this.props.dispatch(setFatalError(undefined));
  53. this.props.dispatch(appNavigate(undefined));
  54. }
  55. _onReloadNow: () => void;
  56. /**
  57. * Handle clicking on the "Reload Now" button. It will navigate to the same
  58. * conference URL as before immediately, without waiting for the timer to
  59. * kick in.
  60. *
  61. * @private
  62. * @returns {void}
  63. */
  64. _onReloadNow() {
  65. clearInterval(this._interval);
  66. this.props.dispatch(reloadNow());
  67. }
  68. /**
  69. * Implements React's {@link Component#render()}.
  70. *
  71. * @inheritdoc
  72. * @returns {ReactElement}
  73. */
  74. render() {
  75. const { _dialogStyles, t } = this.props;
  76. const { message, timeLeft, title } = this.state;
  77. return (
  78. <OverlayFrame>
  79. <ConfirmDialog
  80. cancelKey = 'dialog.Cancel'
  81. okKey = 'dialog.rejoinNow'
  82. onCancel = { this._onCancel }
  83. onSubmit = { this._onReloadNow }>
  84. <Text style = { _dialogStyles.text }>
  85. { `${t(title)} ${t(message, { seconds: timeLeft })}` }
  86. </Text>
  87. </ConfirmDialog>
  88. </OverlayFrame>
  89. );
  90. }
  91. }
  92. /**
  93. * Maps part of the Redux state to the props of this component.
  94. *
  95. * @param {Object} state - The Redux state.
  96. * @returns {{
  97. * _dialogStyles: StyleType
  98. * }}
  99. */
  100. function _mapStateToProps(state) {
  101. return {
  102. ...abstractMapStateToProps(state),
  103. _dialogStyles: ColorSchemeRegistry.get(state, 'Dialog')
  104. };
  105. }
  106. export default translate(connect(_mapStateToProps)(PageReloadOverlay));