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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. style = { styles.webView }>
  69. <WebView
  70. onError = { this._onError }
  71. renderLoading = { this._renderLoading }
  72. source = {{ uri: _documentUrl }}
  73. startInLoadingState = { true } />
  74. </JitsiModal>
  75. );
  76. }
  77. _onClose: () => boolean
  78. /**
  79. * Closes the window.
  80. *
  81. * @returns {boolean}
  82. */
  83. _onClose() {
  84. const { _isOpen, dispatch } = this.props;
  85. if (_isOpen) {
  86. dispatch(toggleDocument());
  87. return true;
  88. }
  89. return false;
  90. }
  91. _onError: () => void;
  92. /**
  93. * Callback to handle the error if the page fails to load.
  94. *
  95. * @returns {void}
  96. */
  97. _onError() {
  98. const { _isOpen, dispatch } = this.props;
  99. if (_isOpen) {
  100. dispatch(toggleDocument());
  101. }
  102. }
  103. _renderLoading: () => React$Component<any>;
  104. /**
  105. * Renders the loading indicator.
  106. *
  107. * @returns {React$Component<any>}
  108. */
  109. _renderLoading() {
  110. return (
  111. <View style = { styles.indicatorWrapper }>
  112. <LoadingIndicator
  113. color = { INDICATOR_COLOR }
  114. size = 'large' />
  115. </View>
  116. );
  117. }
  118. }
  119. /**
  120. * Maps (parts of) the redux state to {@link SharedDocument} React {@code Component} props.
  121. *
  122. * @param {Object} state - The redux store/state.
  123. * @private
  124. * @returns {Object}
  125. */
  126. export function _mapStateToProps(state: Object) {
  127. const { editing } = state['features/etherpad'];
  128. const documentUrl = getSharedDocumentUrl(state);
  129. return {
  130. _documentUrl: documentUrl,
  131. _headerStyles: ColorSchemeRegistry.get(state, 'Header'),
  132. _isOpen: editing
  133. };
  134. }
  135. export default translate(connect(_mapStateToProps)(SharedDocument));