Cancel edit message

This commit is contained in:
Diego Mello 2017-11-23 09:45:09 -02:00
parent 32fdea3de1
commit 272f6acd70
6 changed files with 22 additions and 3 deletions

View File

@ -35,6 +35,7 @@ export const MESSAGES = createRequestTypes('MESSAGES', [
'DELETE_SUCCESS',
'DELETE_FAILURE',
'EDIT_INIT',
'EDIT_CANCEL',
'EDIT_REQUEST',
'EDIT_SUCCESS',
'EDIT_FAILURE',

View File

@ -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,

View File

@ -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: '' });
}
}

View File

@ -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

View File

@ -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,

View File

@ -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 = () => {