CreateDiscussionView

This commit is contained in:
Diego Mello 2020-05-27 14:07:43 -03:00
parent 6c132cbbcd
commit 97ae9bce13
2 changed files with 30 additions and 29 deletions

View File

@ -53,6 +53,7 @@ import AttachmentView from '../views/AttachmentView';
import ModalBlockView from '../views/ModalBlockView';
import JitsiMeetView from '../views/JitsiMeetView';
import StatusView from '../views/StatusView';
import CreateDiscussionView from '../views/CreateDiscussionView';
// ChatsStack
const Chats = createStackNavigator();
@ -100,7 +101,6 @@ const ChatsStack = () => {
<Chats.Screen
name='SelectedUsersView'
component={SelectedUsersView}
options={SelectedUsersView.navigationOptions}
/>
<Chats.Screen
name='InviteUsersView'
@ -247,13 +247,16 @@ const NewMessageStack = () => {
<NewMessage.Screen
name='SelectedUsersViewCreateChannel'
component={SelectedUsersView}
options={props => SelectedUsersView.navigationOptions({ ...props })}
/>
<NewMessage.Screen
name='CreateChannelView'
component={CreateChannelView}
options={CreateChannelView.navigationOptions}
/>
<NewMessage.Screen
name='CreateDiscussionView'
component={CreateDiscussionView}
/>
</NewMessage.Navigator>
);
};
@ -278,12 +281,10 @@ const InsideStackModal = () => {
<InsideStack.Screen
name='AttachmentView'
component={AttachmentView}
options={AttachmentView.navigationOptions}
/>
<InsideStack.Screen
name='StatusView'
component={StatusView}
options={StatusView.navigationOptions}
/>
<InsideStack.Screen
name='ModalBlockView'

View File

@ -26,26 +26,9 @@ import styles from './styles';
import SafeAreaView from '../../containers/SafeAreaView';
class CreateChannelView extends React.Component {
static navigationOptions = ({ navigation, route }) => {
const submit = route.params?.submit ?? (() => {});
const showSubmit = route.params?.showSubmit ?? route.params?.message;
return {
title: I18n.t('Create_Discussion'),
headerRight: (
showSubmit
? (
<CustomHeaderButtons>
<Item title={I18n.t('Create')} onPress={submit} testID='create-discussion-submit' />
</CustomHeaderButtons>
)
: null
),
headerLeft: <CloseModalButton navigation={navigation} />
};
}
propTypes = {
navigation: PropTypes.object,
route: PropTypes.object,
server: PropTypes.string,
user: PropTypes.object,
create: PropTypes.func,
@ -58,26 +41,26 @@ class CreateChannelView extends React.Component {
constructor(props) {
super(props);
const { navigation } = props;
navigation.setParams({ submit: this.submit });
this.channel = navigation.getParam('channel');
const message = navigation.getParam('message', {});
const { route } = props;
this.channel = route.params?.channel;
const message = route.params?.message ?? {};
this.state = {
channel: this.channel,
message,
name: message.msg || '',
name: message?.msg || '',
users: [],
reply: ''
};
this.setHeader();
}
componentDidUpdate(prevProps, prevState) {
const {
loading, failure, error, result, navigation
loading, failure, error, result
} = this.props;
if (!isEqual(this.state, prevState)) {
navigation.setParams({ showSubmit: this.valid() });
this.setHeader();
}
if (!loading && loading !== prevProps.loading) {
@ -98,6 +81,23 @@ class CreateChannelView extends React.Component {
}
}
setHeader = () => {
const { navigation } = this.props;
navigation.setOptions({
title: I18n.t('Create_Discussion'),
headerRight: (
this.valid()
? () => (
<CustomHeaderButtons>
<Item title={I18n.t('Create')} onPress={this.submit} testID='create-discussion-submit' />
</CustomHeaderButtons>
)
: null
),
headerLeft: () => <CloseModalButton navigation={navigation} />
});
}
submit = () => {
const {
name: t_name, channel: { prid, rid }, message: { id: pmid }, reply, users