mattermost-mobile/app/screens/thread/thread_base.js
Elias Nahum 1a605891fe
MM-22401 Refactor Post Draft (#4122)
* Babel TS and Eslint config

* Channel is archived component

* Move Typing component

* Move Uploads component

* Add PostInput component

* QuickActions components

* Add PostDraft component

* Remove old PostTextbox component

* Rename post_textbox constant

* Fix Autocomplete

* Rename blur post draft event

* Fix references

* Feedback review

* Fix autocomplete for iOS
2020-05-06 06:30:51 -04:00

112 lines
3.2 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import {Keyboard} from 'react-native';
import {intlShape} from 'react-intl';
import {General, RequestStatus} from '@mm-redux/constants';
import Loading from 'app/components/loading';
import DeletedPost from 'app/components/deleted_post';
import {popTopScreen, mergeNavigationOptions} from 'app/actions/navigation';
export default class ThreadBase extends PureComponent {
static propTypes = {
actions: PropTypes.shape({
selectPost: PropTypes.func.isRequired,
}).isRequired,
componentId: PropTypes.string,
channelId: PropTypes.string.isRequired,
channelType: PropTypes.string,
displayName: PropTypes.string,
myMember: PropTypes.object.isRequired,
rootId: PropTypes.string.isRequired,
theme: PropTypes.object.isRequired,
postIds: PropTypes.array.isRequired,
channelIsArchived: PropTypes.bool,
threadLoadingStatus: PropTypes.object,
};
static defaultProps = {
postIds: [],
};
static contextTypes = {
intl: intlShape,
};
constructor(props, context) {
super(props);
const {channelType, displayName} = props;
const {formatMessage} = context.intl;
let title;
if (channelType === General.DM_CHANNEL) {
title = formatMessage({id: 'mobile.routes.thread_dm', defaultMessage: 'Direct Message Thread'});
} else {
title = formatMessage({id: 'mobile.routes.thread', defaultMessage: '{channelName} Thread'}, {channelName: displayName});
}
this.postDraft = React.createRef();
const options = {
topBar: {
title: {
text: title,
},
},
};
mergeNavigationOptions(props.componentId, options);
this.state = {
lastViewedAt: props.myMember && props.myMember.last_viewed_at,
};
}
componentWillReceiveProps(nextProps) {
if (this.props.postIds !== nextProps.postIds && !nextProps.postIds.length) {
this.close();
return;
}
if (!this.state.lastViewedAt) {
this.setState({lastViewedAt: nextProps.myMember && nextProps.myMember.last_viewed_at});
}
}
componentWillUnmount() {
this.props.actions.selectPost('');
}
close = () => {
const {componentId} = this.props;
popTopScreen(componentId);
};
hasRootPost = () => {
return this.props.postIds.includes(this.props.rootId);
};
hideKeyboard = () => {
Keyboard.dismiss();
};
renderFooter = () => {
const {theme, threadLoadingStatus} = this.props;
if (!this.hasRootPost() && threadLoadingStatus.status !== RequestStatus.STARTED) {
return (
<DeletedPost theme={theme}/>
);
} else if (threadLoadingStatus.status === RequestStatus.STARTED) {
return (
<Loading color={theme.centerChannelColor}/>
);
}
return null;
};
}