|  | 
|  | 1 | +/* @flow strict-local */ | 
|  | 2 | + | 
|  | 3 | +import React from 'react'; | 
|  | 4 | +import { View } from 'react-native'; | 
|  | 5 | +import type { NavigationScreenProp } from 'react-navigation'; | 
|  | 6 | +import type { Dispatch, Auth, ThemeName, UserOrBot } from '../types'; | 
|  | 7 | +import SpinningProgress from '../common/SpinningProgress'; | 
|  | 8 | +import type { MessageSnapshot } from '../api/modelTypes'; | 
|  | 9 | +import { connect } from '../react-redux'; | 
|  | 10 | +import { getAuth, getSettings, getAllUsersById } from '../selectors'; | 
|  | 11 | +import { Screen, ZulipWebView } from '../common'; | 
|  | 12 | +import { showToast } from '../utils/info'; | 
|  | 13 | +import * as api from '../api'; | 
|  | 14 | +import editHistoryHtml from '../webview/html/editHistoryHtml'; | 
|  | 15 | + | 
|  | 16 | +type SelectorProps = {| | 
|  | 17 | +  auth: Auth, | 
|  | 18 | +  usersById: Map<number, UserOrBot>, | 
|  | 19 | +  themeName: ThemeName, | 
|  | 20 | +|}; | 
|  | 21 | + | 
|  | 22 | +type Props = $ReadOnly<{| | 
|  | 23 | +  navigation: NavigationScreenProp<{ params: {| messageId: number |} }>, | 
|  | 24 | + | 
|  | 25 | +  dispatch: Dispatch, | 
|  | 26 | +  ...SelectorProps, | 
|  | 27 | +|}>; | 
|  | 28 | + | 
|  | 29 | +type State = $ReadOnly<{| | 
|  | 30 | +  messageHistory: MessageSnapshot[] | null, | 
|  | 31 | +|}>; | 
|  | 32 | + | 
|  | 33 | +class EditHistory extends React.Component<Props, State> { | 
|  | 34 | +  state = { | 
|  | 35 | +    messageHistory: null, | 
|  | 36 | +  }; | 
|  | 37 | + | 
|  | 38 | +  componentDidMount() { | 
|  | 39 | +    const { auth, navigation } = this.props; | 
|  | 40 | + | 
|  | 41 | +    api | 
|  | 42 | +      .getMessageHistory(auth, navigation.state.params.messageId) | 
|  | 43 | +      .then(response => { | 
|  | 44 | +        this.setState({ | 
|  | 45 | +          messageHistory: response.message_history, | 
|  | 46 | +        }); | 
|  | 47 | +      }) | 
|  | 48 | +      .catch(err => { | 
|  | 49 | +        navigation.goBack(); | 
|  | 50 | +        showToast('An error occurred while loading edit history'); | 
|  | 51 | +      }); | 
|  | 52 | +  } | 
|  | 53 | + | 
|  | 54 | +  render() { | 
|  | 55 | +    const { messageHistory } = this.state; | 
|  | 56 | + | 
|  | 57 | +    if (messageHistory === null) { | 
|  | 58 | +      return ( | 
|  | 59 | +        <Screen title="Edit History"> | 
|  | 60 | +          <View style={{ justifyContent: 'center', alignItems: 'center', flex: 1 }}> | 
|  | 61 | +            <SpinningProgress color="white" size={48} /> | 
|  | 62 | +          </View> | 
|  | 63 | +        </Screen> | 
|  | 64 | +      ); | 
|  | 65 | +    } | 
|  | 66 | +    const { usersById, auth, themeName } = this.props; | 
|  | 67 | + | 
|  | 68 | +    return ( | 
|  | 69 | +      <Screen title="Edit History"> | 
|  | 70 | +        <ZulipWebView | 
|  | 71 | +          html={editHistoryHtml(messageHistory, themeName, usersById, auth)} | 
|  | 72 | +          onError={(msg: mixed) => { | 
|  | 73 | +            // eslint-disable-next-line no-console | 
|  | 74 | +            console.error(msg); | 
|  | 75 | +          }} | 
|  | 76 | +        /> | 
|  | 77 | +      </Screen> | 
|  | 78 | +    ); | 
|  | 79 | +  } | 
|  | 80 | +} | 
|  | 81 | + | 
|  | 82 | +export default connect<SelectorProps, _, _>((state, props) => ({ | 
|  | 83 | +  auth: getAuth(state), | 
|  | 84 | +  usersById: getAllUsersById(state), | 
|  | 85 | +  themeName: getSettings(state).theme, | 
|  | 86 | +}))(EditHistory); | 
0 commit comments