From 4a2fbcaf983e3180e00bb846f4ed65a2670b9251 Mon Sep 17 00:00:00 2001
From: Joram Wilander <jwawilander@gmail.com>
Date: Thu, 18 Aug 2016 18:37:09 -0400
Subject: Add flagging functionality to search results (#3803)

---
 webapp/components/search_results_item.jsx | 57 +++++++++++++++++++------------
 1 file changed, 36 insertions(+), 21 deletions(-)

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

diff --git a/webapp/components/search_results_item.jsx b/webapp/components/search_results_item.jsx
index 65abc516e..ada5e0ea6 100644
--- a/webapp/components/search_results_item.jsx
+++ b/webapp/components/search_results_item.jsx
@@ -9,7 +9,7 @@ import UserStore from 'stores/user_store.jsx';
 
 import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
 import * as GlobalActions from 'actions/global_actions.jsx';
-import {unflagPost, getFlaggedPosts} from 'actions/post_actions.jsx';
+import {flagPost, unflagPost} from 'actions/post_actions.jsx';
 
 import * as TextFormatting from 'utils/text_formatting.jsx';
 import * as Utils from 'utils/utils.jsx';
@@ -30,6 +30,7 @@ export default class SearchResultsItem extends React.Component {
         this.handleFocusRHSClick = this.handleFocusRHSClick.bind(this);
         this.shrinkSidebar = this.shrinkSidebar.bind(this);
         this.unflagPost = this.unflagPost.bind(this);
+        this.flagPost = this.flagPost.bind(this);
     }
 
     hideSidebar() {
@@ -47,11 +48,14 @@ export default class SearchResultsItem extends React.Component {
         GlobalActions.emitPostFocusRightHandSideFromSearch(this.props.post, this.props.isMentionSearch);
     }
 
+    flagPost(e) {
+        e.preventDefault();
+        flagPost(this.props.post.id);
+    }
+
     unflagPost(e) {
         e.preventDefault();
-        unflagPost(this.props.post.id,
-            () => getFlaggedPosts()
-        );
+        unflagPost(this.props.post.id);
     }
 
     render() {
@@ -110,6 +114,7 @@ export default class SearchResultsItem extends React.Component {
         }
 
         let flag;
+        let flagFunc;
         let flagVisible = '';
         let flagTooltip = (
             <Tooltip id='flagTooltip'>
@@ -129,24 +134,21 @@ export default class SearchResultsItem extends React.Component {
                     />
                 </Tooltip>
             );
+            flagFunc = this.unflagPost;
             flag = (
-                <OverlayTrigger
-                    delayShow={Constants.OVERLAY_TIME_DELAY}
-                    placement='top'
-                    overlay={flagTooltip}
-                >
-                    <a
-                        href='#'
-                        className={'flag-icon__container ' + flagVisible}
-                        onClick={this.unflagPost}
-                    >
-                        <span
-                            className='icon'
-                            dangerouslySetInnerHTML={{__html: flagIcon}}
-                        />
-                    </a>
-                </OverlayTrigger>
+                <span
+                    className='icon'
+                    dangerouslySetInnerHTML={{__html: flagIcon}}
+                />
             );
+        } else {
+            flag = (
+                <span
+                    className='icon'
+                    dangerouslySetInnerHTML={{__html: flagIcon}}
+                />
+            );
+            flagFunc = this.flagPost;
         }
 
         return (
@@ -187,7 +189,19 @@ export default class SearchResultsItem extends React.Component {
                                             minute='2-digit'
                                         />
                                     </time>
-                                    {flag}
+                                    <OverlayTrigger
+                                        delayShow={Constants.OVERLAY_TIME_DELAY}
+                                        placement='top'
+                                        overlay={flagTooltip}
+                                    >
+                                        <a
+                                            href='#'
+                                            className={'flag-icon__container ' + flagVisible}
+                                            onClick={flagFunc}
+                                        >
+                                            {flag}
+                                        </a>
+                                    </OverlayTrigger>
                                 </li>
                                 <li className='col__controls'>
                                     <a
@@ -256,6 +270,7 @@ SearchResultsItem.propTypes = {
     channel: React.PropTypes.object,
     compactDisplay: React.PropTypes.bool,
     isMentionSearch: React.PropTypes.bool,
+    isFlaggedSearch: React.PropTypes.bool,
     term: React.PropTypes.string,
     useMilitaryTime: React.PropTypes.bool.isRequired,
     shrink: React.PropTypes.function,
-- 
cgit v1.2.3-1-g7c22

