From 272f6acd700f54422ee7125c4c0f10985c90cd78 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Thu, 23 Nov 2017 09:45:09 -0200 Subject: [PATCH] Cancel edit message --- app/actions/actionsTypes.js | 1 + app/actions/messages.js | 6 ++++++ app/containers/MessageBox.js | 2 ++ app/containers/message/index.js | 4 ++-- app/reducers/messages.js | 6 ++++++ app/views/RoomView.js | 6 +++++- 6 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/actions/actionsTypes.js b/app/actions/actionsTypes.js index 4447c95d1..4d23dce22 100644 --- a/app/actions/actionsTypes.js +++ b/app/actions/actionsTypes.js @@ -35,6 +35,7 @@ export const MESSAGES = createRequestTypes('MESSAGES', [ 'DELETE_SUCCESS', 'DELETE_FAILURE', 'EDIT_INIT', + 'EDIT_CANCEL', 'EDIT_REQUEST', 'EDIT_SUCCESS', 'EDIT_FAILURE', diff --git a/app/actions/messages.js b/app/actions/messages.js index c2b8eea84..879efd65b 100644 --- a/app/actions/messages.js +++ b/app/actions/messages.js @@ -47,6 +47,12 @@ export function editInit(message) { }; } +export function editCancel() { + return { + type: types.MESSAGES.EDIT_CANCEL + }; +} + export function editRequest(message) { return { type: types.MESSAGES.EDIT_REQUEST, diff --git a/app/containers/MessageBox.js b/app/containers/MessageBox.js index 0c6222ebe..1b0c13a40 100644 --- a/app/containers/MessageBox.js +++ b/app/containers/MessageBox.js @@ -59,6 +59,8 @@ export default class MessageBox extends React.Component { if (this.props.message !== nextProps.message && nextProps.message) { this.component.setNativeProps({ text: nextProps.message.msg }); this.component.focus(); + } else if (!nextProps.message) { + this.component.setNativeProps({ text: '' }); } } diff --git a/app/containers/message/index.js b/app/containers/message/index.js index cf85f70f9..8f0f0d5e1 100644 --- a/app/containers/message/index.js +++ b/app/containers/message/index.js @@ -118,12 +118,12 @@ export default class Message extends React.Component { this.QUOTE_INDEX = this.options.length - 1; // Star if (this.props.Message_AllowStarring) { - this.options.push('Star Message'); + this.options.push('Star'); this.STAR_INDEX = this.options.length - 1; } // Pin if (this.props.Message_AllowPinning) { - this.options.push('Pin Message'); + this.options.push('Pin'); this.PIN_INDEX = this.options.length - 1; } // Delete diff --git a/app/reducers/messages.js b/app/reducers/messages.js index f3ca56425..37daaea6d 100644 --- a/app/reducers/messages.js +++ b/app/reducers/messages.js @@ -33,6 +33,12 @@ export default function messages(state = initialState, action) { message: action.message, editing: true }; + case types.MESSAGES.EDIT_CANCEL: + return { + ...state, + message: {}, + editing: false + }; case types.MESSAGES.EDIT_SUCCESS: return { ...state, diff --git a/app/views/RoomView.js b/app/views/RoomView.js index c5de43f4a..abe407833 100644 --- a/app/views/RoomView.js +++ b/app/views/RoomView.js @@ -7,6 +7,7 @@ import { bindActionCreators } from 'redux'; import * as actions from '../actions'; import { openRoom } from '../actions/room'; +import { editCancel } from '../actions/messages'; import realm from '../lib/realm'; import RocketChat from '../lib/rocketchat'; import Message from '../containers/message'; @@ -59,13 +60,15 @@ const styles = StyleSheet.create({ }), dispatch => ({ actions: bindActionCreators(actions, dispatch), - openRoom: room => dispatch(openRoom(room)) + openRoom: room => dispatch(openRoom(room)), + editCancel: () => dispatch(editCancel()) }) ) export default class RoomView extends React.Component { static propTypes = { navigation: PropTypes.object.isRequired, openRoom: PropTypes.func.isRequired, + editCancel: PropTypes.func, rid: PropTypes.string, sid: PropTypes.string, name: PropTypes.string, @@ -132,6 +135,7 @@ export default class RoomView extends React.Component { componentWillUnmount() { clearTimeout(this.timer); this.data.removeAllListeners(); + this.props.editCancel(); } onEndReached = () => {