From 70157ef0e3bc0e8d6cc96ae41acdd204353d2269 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Thu, 10 Aug 2017 07:33:52 -0400 Subject: Fix pinned posts not updating when list empty (#7164) --- webapp/stores/search_store.jsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/webapp/stores/search_store.jsx b/webapp/stores/search_store.jsx index dd9b6dbdf..7db0ed92a 100644 --- a/webapp/stores/search_store.jsx +++ b/webapp/stores/search_store.jsx @@ -174,11 +174,14 @@ SearchStore.dispatchToken = AppDispatcher.register((payload) => { var action = payload.action; switch (action.type) { - case ActionTypes.RECEIVED_SEARCH: + case ActionTypes.RECEIVED_SEARCH: { + const results = SearchStore.getSearchResults() || {}; + const posts = Object.values(results.posts || {}); + const channelId = posts.length > 0 ? posts[0].channel_id : ''; if (SearchStore.getIsPinnedPosts() === action.is_pinned_posts && action.is_pinned_posts === true && - SearchStore.getSearchResults().posts && - ChannelStore.getCurrentId() !== Object.values(SearchStore.getSearchResults().posts)[0].channel_id) { + channelId !== '' && + ChannelStore.getCurrentId() !== channelId) { // ignore pin posts update after switch to a new channel return; } @@ -186,6 +189,7 @@ SearchStore.dispatchToken = AppDispatcher.register((payload) => { SearchStore.storeSearchResults(action.results, action.is_mention_search, action.is_flagged_posts, action.is_pinned_posts); SearchStore.emitSearchChange(); break; + } case ActionTypes.RECEIVED_SEARCH_TERM: if (action.do_search) { // while a search is in progress, hide results from previous search -- cgit v1.2.3-1-g7c22