From 69f3f2fdce4ae21a037ca61d753279efcc70f0ec Mon Sep 17 00:00:00 2001
From: Harrison Healey <harrisonmhealey@gmail.com>
Date: Tue, 23 May 2017 10:17:06 -0400
Subject: PLT-6282 Make post list stay visible when post textbox height changes
 (#6323)

* PLT-6282 Changed post drafts to use an action when being stored

* PLT-6282 Triggered post list to update scroll position when post draft changes

* PLT-6282 Changed SuggestionBox to complete suggestions without an event
---
 webapp/stores/post_store.jsx | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

(limited to 'webapp/stores/post_store.jsx')

diff --git a/webapp/stores/post_store.jsx b/webapp/stores/post_store.jsx
index 5a1dc5cf8..770e232ca 100644
--- a/webapp/stores/post_store.jsx
+++ b/webapp/stores/post_store.jsx
@@ -4,7 +4,6 @@
 import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
 import EventEmitter from 'events';
 
-import ChannelStore from 'stores/channel_store.jsx';
 import BrowserStore from 'stores/browser_store.jsx';
 import UserStore from 'stores/user_store.jsx';
 
@@ -17,6 +16,7 @@ const EDIT_POST_EVENT = 'edit_post';
 const POSTS_VIEW_JUMP_EVENT = 'post_list_jump';
 const SELECTED_POST_CHANGE_EVENT = 'selected_post_change';
 const POST_PINNED_CHANGE_EVENT = 'post_pinned_change';
+const POST_DRAFT_CHANGE_EVENT = 'post_draft_change';
 
 class PostStoreClass extends EventEmitter {
     constructor() {
@@ -75,6 +75,18 @@ class PostStoreClass extends EventEmitter {
         this.removeListener(POSTS_VIEW_JUMP_EVENT, callback);
     }
 
+    emitPostDraftChange(channelId) {
+        this.emit(POST_DRAFT_CHANGE_EVENT + channelId, this.getPostDraft(channelId));
+    }
+
+    addPostDraftChangeListener(channelId, callback) {
+        this.on(POST_DRAFT_CHANGE_EVENT + channelId, callback);
+    }
+
+    removePostDraftChangeListener(channelId, callback) {
+        this.removeListener(POST_DRAFT_CHANGE_EVENT + channelId, callback);
+    }
+
     jumpPostsViewToBottom() {
         this.emitPostsViewJump(Constants.PostsViewJumpTypes.BOTTOM, null);
     }
@@ -585,21 +597,11 @@ class PostStoreClass extends EventEmitter {
         return draft;
     }
 
-    storeCurrentDraft(draft) {
-        var channelId = ChannelStore.getCurrentId();
+    storePostDraft(channelId, draft) {
         BrowserStore.setGlobalItem('draft_' + channelId, draft);
     }
 
-    getCurrentDraft() {
-        var channelId = ChannelStore.getCurrentId();
-        return this.getDraft(channelId);
-    }
-
-    storeDraft(channelId, draft) {
-        BrowserStore.setGlobalItem('draft_' + channelId, draft);
-    }
-
-    getDraft(channelId) {
+    getPostDraft(channelId) {
         return this.normalizeDraft(BrowserStore.getGlobalItem('draft_' + channelId));
     }
 
@@ -700,7 +702,7 @@ PostStore.dispatchToken = AppDispatcher.register((payload) => {
         break;
     case ActionTypes.CREATE_POST:
         PostStore.storePendingPost(action.post);
-        PostStore.storeDraft(action.post.channel_id, null);
+        PostStore.storePostDraft(action.post.channel_id, null);
         PostStore.jumpPostsViewToBottom();
         break;
     case ActionTypes.CREATE_COMMENT:
@@ -723,6 +725,10 @@ PostStore.dispatchToken = AppDispatcher.register((payload) => {
     case ActionTypes.RECEIVED_POST_UNPINNED:
         PostStore.emitPostPinnedChange();
         break;
+    case ActionTypes.POST_DRAFT_CHANGED:
+        PostStore.storePostDraft(action.channelId, action.draft);
+        PostStore.emitPostDraftChange(action.channelId);
+        break;
     default:
     }
 });
-- 
cgit v1.2.3-1-g7c22

