Store post drafts (#241)

This commit is contained in:
Chris Duarte 2017-02-13 07:25:11 -08:00 committed by Harrison Healey
parent 263fd50887
commit e0631c2663
5 changed files with 32 additions and 11 deletions

View file

@ -135,10 +135,11 @@ export function handleSelectChannel(channelId) {
};
}
export function handlePostDraftChanged(postDraft) {
export function handlePostDraftChanged(channelId, postDraft) {
return async (dispatch, getState) => {
dispatch({
type: ViewTypes.POST_DRAFT_CHANGED,
channelId,
postDraft
}, getState);
};

View file

@ -62,9 +62,13 @@ export default class PostTextbox extends React.PureComponent {
};
this.props.actions.createPost(this.props.teamId, post);
this.props.onChangeText('');
this.handleTextChange('');
};
handleTextChange = (text) => {
this.props.onChangeText(this.props.channelId, text);
}
render() {
const theme = this.props.theme;
@ -101,7 +105,7 @@ export default class PostTextbox extends React.PureComponent {
<TextInputWithLocalizedPlaceholder
ref='input'
value={this.props.value}
onChangeText={this.props.onChangeText}
onChangeText={this.handleTextChange}
onContentSizeChange={this.handleContentSizeChange}
placeholder={placeholder}
placeholderTextColor={changeOpacity(theme.centerChannelColor, 0.5)}

View file

@ -269,6 +269,9 @@ const state = {
rightDrawerRoute: null
},
views: {
channel: {
drafts: {}
},
i18n: {
locale: ''
},

View file

@ -7,17 +7,30 @@ import {ViewTypes} from 'app/constants';
import {ChannelTypes} from 'service/constants';
function postDraft(state = '', action) {
function drafts(state = {}, action) {
switch (action.type) {
case ViewTypes.POST_DRAFT_CHANGED:
return action.postDraft;
case ChannelTypes.SELECT_CHANNEL:
return '';
case ViewTypes.POST_DRAFT_CHANGED: {
return {
...state,
[action.channelId]: action.postDraft
};
}
case ChannelTypes.SELECT_CHANNEL: {
let data = {...state};
if (!data[action.data]) {
data = {
...state,
[action.data]: ''
};
}
return data;
}
default:
return state;
}
}
export default combineReducers({
postDraft
drafts
});

View file

@ -33,7 +33,7 @@ export default class Channel extends React.PureComponent {
}).isRequired,
currentTeam: React.PropTypes.object,
currentChannel: React.PropTypes.object,
postDraft: React.PropTypes.string.isRequired,
drafts: React.PropTypes.object.isRequired,
theme: React.PropTypes.object.isRequired,
subscribeToHeaderEvent: React.PropTypes.func,
unsubscribeFromHeaderEvent: React.PropTypes.func
@ -128,7 +128,7 @@ export default class Channel extends React.PureComponent {
<ChannelPostList channel={currentChannel}/>
<PostTextbox
ref={this.attachPostTextbox}
value={this.props.postDraft}
value={this.props.drafts[this.props.currentChannel.id]}
teamId={teamId}
channelId={currentChannel.id}
onChangeText={this.props.actions.handlePostDraftChanged}