diff --git a/app/components/file_upload_preview/index.js b/app/components/file_upload_preview/index.js index c0f199359..5d5f75d07 100644 --- a/app/components/file_upload_preview/index.js +++ b/app/components/file_upload_preview/index.js @@ -21,6 +21,10 @@ const checkForFileUploadingInChannel = createSelector( return state.views.channel.drafts[channelId]; }, (draft) => { + if (!draft || !draft.files) { + return false; + } + return draft.files.some((f) => f.loading); } ); diff --git a/app/selectors/views.js b/app/selectors/views.js index 124049104..8d3ff8c59 100644 --- a/app/selectors/views.js +++ b/app/selectors/views.js @@ -1,7 +1,15 @@ +// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + import {createSelector} from 'reselect'; import {getCurrentChannel} from 'mattermost-redux/selectors/entities/channels'; +const emptyDraft = { + draft: '', + files: [] +}; + function getChannelDrafts(state) { return state.views.channel.drafts; } @@ -13,11 +21,15 @@ function getThreadDrafts(state) { export const getCurrentChannelDraft = createSelector( getChannelDrafts, getCurrentChannel, - (drafts, currentChannel) => drafts[currentChannel.id] + (drafts, currentChannel) => { + return drafts[currentChannel.id] || emptyDraft; + } ); export const getThreadDraft = createSelector( getThreadDrafts, (state, rootId) => rootId, - (drafts, rootId) => drafts[rootId] + (drafts, rootId) => { + return drafts[rootId] || emptyDraft; + } );