From a8e772fa4878e3004e5399d85b7105dee3859312 Mon Sep 17 00:00:00 2001
From: Harrison Healey <harrisonmhealey@gmail.com>
Date: Mon, 31 Oct 2016 10:52:00 -0400
Subject: Cleaned up code for ensuring post drafts are non-null (#4382)

---
 webapp/components/create_post.jsx | 24 ++----------------------
 1 file changed, 2 insertions(+), 22 deletions(-)

(limited to 'webapp/components/create_post.jsx')

diff --git a/webapp/components/create_post.jsx b/webapp/components/create_post.jsx
index ae25fc74e..e7bf2b92a 100644
--- a/webapp/components/create_post.jsx
+++ b/webapp/components/create_post.jsx
@@ -40,7 +40,6 @@ export default class CreatePost extends React.Component {
 
         this.lastTime = 0;
 
-        this.getCurrentDraft = this.getCurrentDraft.bind(this);
         this.handleSubmit = this.handleSubmit.bind(this);
         this.postMsgKeyPress = this.postMsgKeyPress.bind(this);
         this.handleChange = this.handleChange.bind(this);
@@ -61,7 +60,7 @@ export default class CreatePost extends React.Component {
 
         PostStore.clearDraftUploads();
 
-        const draft = this.getCurrentDraft();
+        const draft = PostStore.getCurrentDraft();
 
         this.state = {
             channelId: ChannelStore.getCurrentId(),
@@ -77,25 +76,6 @@ export default class CreatePost extends React.Component {
         };
     }
 
-    getCurrentDraft() {
-        const draft = PostStore.getCurrentDraft();
-        const safeDraft = {fileInfos: [], messageText: '', uploadsInProgress: []};
-
-        if (draft) {
-            if (draft.message) {
-                safeDraft.messageText = draft.message;
-            }
-            if (draft.fileInfos) {
-                safeDraft.fileInfos = draft.fileInfos;
-            }
-            if (draft.uploadsInProgress) {
-                safeDraft.uploadsInProgress = draft.uploadsInProgress;
-            }
-        }
-
-        return safeDraft;
-    }
-
     handleSubmit(e) {
         e.preventDefault();
 
@@ -358,7 +338,7 @@ export default class CreatePost extends React.Component {
     onChange() {
         const channelId = ChannelStore.getCurrentId();
         if (this.state.channelId !== channelId) {
-            const draft = this.getCurrentDraft();
+            const draft = PostStore.getCurrentDraft();
 
             this.setState({channelId, messageText: draft.messageText, initialText: draft.messageText, submitting: false, serverError: null, postError: null, fileInfos: draft.fileInfos, uploadsInProgress: draft.uploadsInProgress});
         }
-- 
cgit v1.2.3-1-g7c22

