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.

SharedDocument.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // @flow
  2. import React, { PureComponent } from 'react';
  3. import { View } from 'react-native';
  4. import { WebView } from 'react-native-webview';
  5. import type { Dispatch } from 'redux';
  6. import { ColorSchemeRegistry } from '../../../base/color-scheme';
  7. import { translate } from '../../../base/i18n';
  8. import { JitsiModal } from '../../../base/modal';
  9. import { LoadingIndicator } from '../../../base/react';
  10. import { connect } from '../../../base/redux';
  11. import { toggleDocument } from '../../actions';
  12. import { SHARE_DOCUMENT_VIEW_ID } from '../../constants';
  13. import { getSharedDocumentUrl } from '../../functions';
  14. import styles, { INDICATOR_COLOR } from './styles';
  15. /**
  16. * The type of the React {@code Component} props of {@code ShareDocument}.
  17. */
  18. type Props = {
  19. /**
  20. * URL for the shared document.
  21. */
  22. _documentUrl: string,
  23. /**
  24. * Color schemed style of the header component.
  25. */
  26. _headerStyles: Object,
  27. /**
  28. * True if the chat window should be rendered.
  29. */
  30. _isOpen: boolean,
  31. /**
  32. * The Redux dispatch function.
  33. */
  34. dispatch: Dispatch<any>,
  35. /**
  36. * Function to be used to translate i18n labels.
  37. */
  38. t: Function
  39. };
  40. /**
  41. * Implements a React native component that renders the shared document window.
  42. */
  43. class SharedDocument extends PureComponent<Props> {
  44. /**
  45. * Instantiates a new instance.
  46. *
  47. * @inheritdoc
  48. */
  49. constructor(props: Props) {
  50. super(props);
  51. this._onClose = this._onClose.bind(this);
  52. this._onError = this._onError.bind(this);
  53. this._renderLoading = this._renderLoading.bind(this);
  54. }
  55. /**
  56. * Implements React's {@link Component#render()}.
  57. *
  58. * @inheritdoc
  59. */
  60. render() {
  61. const { _documentUrl } = this.props;
  62. return (
  63. <JitsiModal
  64. headerProps = {{
  65. headerLabelKey: 'documentSharing.title'
  66. }}
  67. modalId = { SHARE_DOCUMENT_VIEW_ID }
  68. showHeaderWithNavigation = { true }
  69. style = { styles.webView }>
  70. <WebView
  71. onError = { this._onError }
  72. renderLoading = { this._renderLoading }
  73. source = {{ uri: _documentUrl }}
  74. startInLoadingState = { true } />
  75. </JitsiModal>
  76. );
  77. }
  78. _onClose: () => boolean
  79. /**
  80. * Closes the window.
  81. *
  82. * @returns {boolean}
  83. */
  84. _onClose() {
  85. const { _isOpen, dispatch } = this.props;
  86. if (_isOpen) {
  87. dispatch(toggleDocument());
  88. return true;
  89. }
  90. return false;
  91. }
  92. _onError: () => void;
  93. /**
  94. * Callback to handle the error if the page fails to load.
  95. *
  96. * @returns {void}
  97. */
  98. _onError() {
  99. const { _isOpen, dispatch } = this.props;
  100. if (_isOpen) {
  101. dispatch(toggleDocument());
  102. }
  103. }
  104. _renderLoading: () => React$Component<any>;
  105. /**
  106. * Renders the loading indicator.
  107. *
  108. * @returns {React$Component<any>}
  109. */
  110. _renderLoading() {
  111. return (
  112. <View style = { styles.indicatorWrapper }>
  113. <LoadingIndicator
  114. color = { INDICATOR_COLOR }
  115. size = 'large' />
  116. </View>
  117. );
  118. }
  119. }
  120. /**
  121. * Maps (parts of) the redux state to {@link SharedDocument} React {@code Component} props.
  122. *
  123. * @param {Object} state - The redux store/state.
  124. * @private
  125. * @returns {Object}
  126. */
  127. export function _mapStateToProps(state: Object) {
  128. const { editing } = state['features/etherpad'];
  129. const documentUrl = getSharedDocumentUrl(state);
  130. return {
  131. _documentUrl: documentUrl,
  132. _headerStyles: ColorSchemeRegistry.get(state, 'Header'),
  133. _isOpen: editing
  134. };
  135. }
  136. export default translate(connect(_mapStateToProps)(SharedDocument));