Clear failed images from post draft when posting (#1244)
* Clear failed images from post draft when posting * feedback review * clone files array only once in the failed reducer
This commit is contained in:
parent
27f355abc5
commit
849c8cc4af
6 changed files with 46 additions and 3 deletions
|
|
@ -107,6 +107,14 @@ export function handleClearFiles(channelId, rootId) {
|
|||
};
|
||||
}
|
||||
|
||||
export function handleClearFailedFiles(channelId, rootId) {
|
||||
return {
|
||||
type: ViewTypes.CLEAR_FAILED_FILES_FOR_POST_DRAFT,
|
||||
channelId,
|
||||
rootId
|
||||
};
|
||||
}
|
||||
|
||||
export function handleRemoveFile(clientId, channelId, rootId) {
|
||||
return {
|
||||
type: ViewTypes.REMOVE_FILE_FROM_POST_DRAFT,
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users';
|
|||
import {executeCommand} from 'app/actions/views/command';
|
||||
import {addReactionToLatestPost} from 'app/actions/views/emoji';
|
||||
import {handlePostDraftChanged, handlePostDraftSelectionChanged} from 'app/actions/views/channel';
|
||||
import {handleClearFiles, handleRemoveLastFile, handleUploadFiles} from 'app/actions/views/file_upload';
|
||||
import {handleClearFiles, handleClearFailedFiles, handleRemoveLastFile, handleUploadFiles} from 'app/actions/views/file_upload';
|
||||
import {handleCommentDraftChanged, handleCommentDraftSelectionChanged} from 'app/actions/views/thread';
|
||||
import {getTheme} from 'mattermost-redux/selectors/entities/preferences';
|
||||
import {getCurrentChannelDraft, getThreadDraft} from 'app/selectors/views';
|
||||
|
|
@ -42,6 +42,7 @@ function mapDispatchToProps(dispatch) {
|
|||
createPost,
|
||||
executeCommand,
|
||||
handleClearFiles,
|
||||
handleClearFailedFiles,
|
||||
handleCommentDraftChanged,
|
||||
handlePostDraftChanged,
|
||||
handleRemoveLastFile,
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ class PostTextbox extends PureComponent {
|
|||
handleCommentDraftChanged: PropTypes.func.isRequired,
|
||||
handlePostDraftChanged: PropTypes.func.isRequired,
|
||||
handleClearFiles: PropTypes.func.isRequired,
|
||||
handleClearFailedFiles: PropTypes.func.isRequired,
|
||||
handleRemoveLastFile: PropTypes.func.isRequired,
|
||||
handleUploadFiles: PropTypes.func.isRequired,
|
||||
userTyping: PropTypes.func.isRequired,
|
||||
|
|
@ -208,7 +209,7 @@ class PostTextbox extends PureComponent {
|
|||
return;
|
||||
}
|
||||
|
||||
const {files} = this.props;
|
||||
const {actions, channelId, files, rootId} = this.props;
|
||||
const {value} = this.state;
|
||||
|
||||
const isReactionMatch = value.match(IS_REACTION_REGEX);
|
||||
|
|
@ -235,7 +236,11 @@ class PostTextbox extends PureComponent {
|
|||
text: intl.formatMessage({id: 'mobile.channel_info.alertNo', defaultMessage: 'No'})
|
||||
}, {
|
||||
text: intl.formatMessage({id: 'mobile.channel_info.alertYes', defaultMessage: 'Yes'}),
|
||||
onPress: this.sendMessage
|
||||
onPress: () => {
|
||||
// Remove only failed files
|
||||
actions.handleClearFailedFiles(channelId, rootId);
|
||||
this.sendMessage();
|
||||
}
|
||||
}],
|
||||
);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ const ViewTypes = keyMirror({
|
|||
RETRY_UPLOAD_FILE_FOR_POST: null,
|
||||
|
||||
CLEAR_FILES_FOR_POST_DRAFT: null,
|
||||
CLEAR_FAILED_FILES_FOR_POST_DRAFT: null,
|
||||
|
||||
REMOVE_FILE_FROM_POST_DRAFT: null,
|
||||
REMOVE_LAST_FILE_FROM_POST_DRAFT: null,
|
||||
|
|
|
|||
|
|
@ -188,6 +188,18 @@ function handleRemoveLastFileFromPostDraft(state, action) {
|
|||
};
|
||||
}
|
||||
|
||||
function handleRemoveFailedFilesFromPostDraft(state, action) {
|
||||
if (action.rootId) {
|
||||
return state;
|
||||
}
|
||||
|
||||
const files = state[action.channelId].files.filter((f) => !f.failed);
|
||||
return {
|
||||
...state,
|
||||
[action.channelId]: Object.assign({}, state[action.channelId], {files})
|
||||
};
|
||||
}
|
||||
|
||||
function drafts(state = {}, action) { // eslint-disable-line complexity
|
||||
switch (action.type) {
|
||||
case ViewTypes.POST_DRAFT_CHANGED:
|
||||
|
|
@ -208,6 +220,8 @@ function drafts(state = {}, action) { // eslint-disable-line complexity
|
|||
return handleUploadFilesFailure(state, action);
|
||||
case ViewTypes.CLEAR_FILES_FOR_POST_DRAFT:
|
||||
return handleClearFilesForPostDraft(state, action);
|
||||
case ViewTypes.CLEAR_FAILED_FILES_FOR_POST_DRAFT:
|
||||
return handleRemoveFailedFilesFromPostDraft(state, action);
|
||||
case ViewTypes.REMOVE_FILE_FROM_POST_DRAFT:
|
||||
return handleRemoveFileFromPostDraft(state, action);
|
||||
case ViewTypes.REMOVE_LAST_FILE_FROM_POST_DRAFT:
|
||||
|
|
|
|||
|
|
@ -192,6 +192,18 @@ function handleRemoveLastFromPostDraft(state, action) {
|
|||
};
|
||||
}
|
||||
|
||||
function handleRemoveFailedFilesFromPostDraft(state, action) {
|
||||
if (!action.rootId) {
|
||||
return state;
|
||||
}
|
||||
|
||||
const files = state[action.rootId].files.filter((f) => !f.failed);
|
||||
return {
|
||||
...state,
|
||||
[action.rootId]: Object.assign({}, state[action.rootId], {files})
|
||||
};
|
||||
}
|
||||
|
||||
function drafts(state = {}, action) { // eslint-disable-line complexity
|
||||
switch (action.type) {
|
||||
case ViewTypes.COMMENT_DRAFT_CHANGED:
|
||||
|
|
@ -212,6 +224,8 @@ function drafts(state = {}, action) { // eslint-disable-line complexity
|
|||
return handleUploadFilesFailure(state, action);
|
||||
case ViewTypes.CLEAR_FILES_FOR_POST_DRAFT:
|
||||
return handleClearFilesForPostDraft(state, action);
|
||||
case ViewTypes.CLEAR_FAILED_FILES_FOR_POST_DRAFT:
|
||||
return handleRemoveFailedFilesFromPostDraft(state, action);
|
||||
case ViewTypes.REMOVE_FILE_FROM_POST_DRAFT:
|
||||
return handleRemoveFileFromPostDraft(state, action);
|
||||
case ViewTypes.REMOVE_LAST_FILE_FROM_POST_DRAFT:
|
||||
|
|
|
|||
Loading…
Reference in a new issue