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

View File

@ -26,26 +26,9 @@ import styles from './styles';
import SafeAreaView from '../../containers/SafeAreaView'; import SafeAreaView from '../../containers/SafeAreaView';
class CreateChannelView extends React.Component { 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 = { propTypes = {
navigation: PropTypes.object, navigation: PropTypes.object,
route: PropTypes.object,
server: PropTypes.string, server: PropTypes.string,
user: PropTypes.object, user: PropTypes.object,
create: PropTypes.func, create: PropTypes.func,
@ -58,26 +41,26 @@ class CreateChannelView extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
const { navigation } = props; const { route } = props;
navigation.setParams({ submit: this.submit }); this.channel = route.params?.channel;
this.channel = navigation.getParam('channel'); const message = route.params?.message ?? {};
const message = navigation.getParam('message', {});
this.state = { this.state = {
channel: this.channel, channel: this.channel,
message, message,
name: message.msg || '', name: message?.msg || '',
users: [], users: [],
reply: '' reply: ''
}; };
this.setHeader();
} }
componentDidUpdate(prevProps, prevState) { componentDidUpdate(prevProps, prevState) {
const { const {
loading, failure, error, result, navigation loading, failure, error, result
} = this.props; } = this.props;
if (!isEqual(this.state, prevState)) { if (!isEqual(this.state, prevState)) {
navigation.setParams({ showSubmit: this.valid() }); this.setHeader();
} }
if (!loading && loading !== prevProps.loading) { 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 = () => { submit = () => {
const { const {
name: t_name, channel: { prid, rid }, message: { id: pmid }, reply, users name: t_name, channel: { prid, rid }, message: { id: pmid }, reply, users