Deleted posts now update in search results and flagged posts (#4618)
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
48d64f3f68
Коммит
3c65a20f45
@@ -19,7 +19,7 @@ import React from 'react';
|
|||||||
import {FormattedMessage, FormattedHTMLMessage} from 'react-intl';
|
import {FormattedMessage, FormattedHTMLMessage} from 'react-intl';
|
||||||
|
|
||||||
function getStateFromStores() {
|
function getStateFromStores() {
|
||||||
const results = SearchStore.getSearchResults();
|
const results = JSON.parse(JSON.stringify(SearchStore.getSearchResults()));
|
||||||
|
|
||||||
const channels = new Map();
|
const channels = new Map();
|
||||||
|
|
||||||
|
|||||||
@@ -111,42 +111,132 @@ export default class SearchResultsItem extends React.Component {
|
|||||||
compactClass = 'post--compact';
|
compactClass = 'post--compact';
|
||||||
}
|
}
|
||||||
|
|
||||||
let flag;
|
let message;
|
||||||
let flagFunc;
|
let flagContent;
|
||||||
let flagVisible = '';
|
let rhsControls;
|
||||||
let flagTooltip = (
|
if (post.state === Constants.POST_DELETED) {
|
||||||
<Tooltip id='flagTooltip'>
|
message = (
|
||||||
<FormattedMessage
|
<p>
|
||||||
id='flag_post.flag'
|
<FormattedMessage
|
||||||
defaultMessage='Flag for follow up'
|
id='post_body.deleted'
|
||||||
/>
|
defaultMessage='(message deleted)'
|
||||||
</Tooltip>
|
/>
|
||||||
);
|
</p>
|
||||||
if (this.props.isFlagged) {
|
);
|
||||||
flagVisible = 'visible';
|
} else {
|
||||||
flagTooltip = (
|
let flag;
|
||||||
|
let flagFunc;
|
||||||
|
let flagVisible = '';
|
||||||
|
let flagTooltip = (
|
||||||
<Tooltip id='flagTooltip'>
|
<Tooltip id='flagTooltip'>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
id='flag_post.unflag'
|
id='flag_post.flag'
|
||||||
defaultMessage='Unflag'
|
defaultMessage='Flag for follow up'
|
||||||
/>
|
/>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
);
|
);
|
||||||
flagFunc = this.unflagPost;
|
|
||||||
flag = (
|
if (this.props.isFlagged) {
|
||||||
<span
|
flagVisible = 'visible';
|
||||||
className='icon'
|
flagTooltip = (
|
||||||
dangerouslySetInnerHTML={{__html: flagIcon}}
|
<Tooltip id='flagTooltip'>
|
||||||
|
<FormattedMessage
|
||||||
|
id='flag_post.unflag'
|
||||||
|
defaultMessage='Unflag'
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
flagFunc = this.unflagPost;
|
||||||
|
flag = (
|
||||||
|
<span
|
||||||
|
className='icon'
|
||||||
|
dangerouslySetInnerHTML={{__html: flagIcon}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
flag = (
|
||||||
|
<span
|
||||||
|
className='icon'
|
||||||
|
dangerouslySetInnerHTML={{__html: flagIcon}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
flagFunc = this.flagPost;
|
||||||
|
}
|
||||||
|
|
||||||
|
flagContent = (
|
||||||
|
<OverlayTrigger
|
||||||
|
delayShow={Constants.OVERLAY_TIME_DELAY}
|
||||||
|
placement='top'
|
||||||
|
overlay={flagTooltip}
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
href='#'
|
||||||
|
className={'flag-icon__container ' + flagVisible}
|
||||||
|
onClick={flagFunc}
|
||||||
|
>
|
||||||
|
{flag}
|
||||||
|
</a>
|
||||||
|
</OverlayTrigger>
|
||||||
|
);
|
||||||
|
|
||||||
|
rhsControls = (
|
||||||
|
<li className='col__controls'>
|
||||||
|
<a
|
||||||
|
href='#'
|
||||||
|
className='comment-icon__container search-item__comment'
|
||||||
|
onClick={this.handleFocusRHSClick}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className='comment-icon'
|
||||||
|
dangerouslySetInnerHTML={{__html: Constants.REPLY_ICON}}
|
||||||
|
/>
|
||||||
|
</a>
|
||||||
|
<a
|
||||||
|
onClick={
|
||||||
|
() => {
|
||||||
|
if (Utils.isMobile()) {
|
||||||
|
AppDispatcher.handleServerAction({
|
||||||
|
type: ActionTypes.RECEIVED_SEARCH,
|
||||||
|
results: null
|
||||||
|
});
|
||||||
|
|
||||||
|
AppDispatcher.handleServerAction({
|
||||||
|
type: ActionTypes.RECEIVED_SEARCH_TERM,
|
||||||
|
term: null,
|
||||||
|
do_search: false,
|
||||||
|
is_mention_search: false
|
||||||
|
});
|
||||||
|
|
||||||
|
AppDispatcher.handleServerAction({
|
||||||
|
type: ActionTypes.RECEIVED_POST_SELECTED,
|
||||||
|
postId: null
|
||||||
|
});
|
||||||
|
|
||||||
|
this.hideSidebar();
|
||||||
|
}
|
||||||
|
this.shrinkSidebar();
|
||||||
|
browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/pl/' + post.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
className='search-item__jump'
|
||||||
|
>
|
||||||
|
<FormattedMessage
|
||||||
|
id='search_item.jump'
|
||||||
|
defaultMessage='Jump'
|
||||||
|
/>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
|
||||||
|
message = (
|
||||||
|
<PostMessageContainer
|
||||||
|
post={post}
|
||||||
|
options={{
|
||||||
|
searchTerm: this.props.term,
|
||||||
|
mentionHighlight: this.props.isMentionSearch
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
flag = (
|
|
||||||
<span
|
|
||||||
className='icon'
|
|
||||||
dangerouslySetInnerHTML={{__html: flagIcon}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
flagFunc = this.flagPost;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -187,75 +277,12 @@ export default class SearchResultsItem extends React.Component {
|
|||||||
minute='2-digit'
|
minute='2-digit'
|
||||||
/>
|
/>
|
||||||
</time>
|
</time>
|
||||||
<OverlayTrigger
|
{flagContent}
|
||||||
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
|
|
||||||
href='#'
|
|
||||||
className='comment-icon__container search-item__comment'
|
|
||||||
onClick={this.handleFocusRHSClick}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
className='comment-icon'
|
|
||||||
dangerouslySetInnerHTML={{__html: Constants.REPLY_ICON}}
|
|
||||||
/>
|
|
||||||
</a>
|
|
||||||
<a
|
|
||||||
onClick={
|
|
||||||
() => {
|
|
||||||
if (Utils.isMobile()) {
|
|
||||||
AppDispatcher.handleServerAction({
|
|
||||||
type: ActionTypes.RECEIVED_SEARCH,
|
|
||||||
results: null
|
|
||||||
});
|
|
||||||
|
|
||||||
AppDispatcher.handleServerAction({
|
|
||||||
type: ActionTypes.RECEIVED_SEARCH_TERM,
|
|
||||||
term: null,
|
|
||||||
do_search: false,
|
|
||||||
is_mention_search: false
|
|
||||||
});
|
|
||||||
|
|
||||||
AppDispatcher.handleServerAction({
|
|
||||||
type: ActionTypes.RECEIVED_POST_SELECTED,
|
|
||||||
postId: null
|
|
||||||
});
|
|
||||||
|
|
||||||
this.hideSidebar();
|
|
||||||
}
|
|
||||||
this.shrinkSidebar();
|
|
||||||
browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/pl/' + post.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
className='search-item__jump'
|
|
||||||
>
|
|
||||||
<FormattedMessage
|
|
||||||
id='search_item.jump'
|
|
||||||
defaultMessage='Jump'
|
|
||||||
/>
|
|
||||||
</a>
|
|
||||||
</li>
|
</li>
|
||||||
|
{rhsControls}
|
||||||
</ul>
|
</ul>
|
||||||
<div className='search-item-snippet'>
|
<div className='search-item-snippet'>
|
||||||
<PostMessageContainer
|
{message}
|
||||||
post={post}
|
|
||||||
options={{
|
|
||||||
searchTerm: this.props.term,
|
|
||||||
mentionHighlight: this.props.isMentionSearch
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ export default class SuggestionBox extends React.Component {
|
|||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
// Clear any suggestions when the SuggestionBox is cleared
|
// Clear any suggestions when the SuggestionBox is cleared
|
||||||
if (nextProps.value === '' && this.props.value !== nextProps.value) {
|
if (nextProps.value === '' && this.props.value !== nextProps.value) {
|
||||||
GlobalActions.emitClearSuggestions(this.suggestionId);
|
// TODO - Find a better way to not "dispatch during dispatch"
|
||||||
|
setTimeout(() => GlobalActions.emitClearSuggestions(this.suggestionId), 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,6 +96,21 @@ class SearchStoreClass extends EventEmitter {
|
|||||||
this.isMentionSearch = isMentionSearch;
|
this.isMentionSearch = isMentionSearch;
|
||||||
this.isFlaggedPosts = isFlaggedPosts;
|
this.isFlaggedPosts = isFlaggedPosts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deletePost(post) {
|
||||||
|
const results = this.getSearchResults();
|
||||||
|
if (results == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (post.id in results.posts) {
|
||||||
|
// make sure to copy the post so that component state changes work properly
|
||||||
|
results.posts[post.id] = Object.assign({}, post, {
|
||||||
|
state: Constants.POST_DELETED,
|
||||||
|
file_ids: []
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var SearchStore = new SearchStoreClass();
|
var SearchStore = new SearchStoreClass();
|
||||||
@@ -115,6 +130,10 @@ SearchStore.dispatchToken = AppDispatcher.register((payload) => {
|
|||||||
case ActionTypes.SHOW_SEARCH:
|
case ActionTypes.SHOW_SEARCH:
|
||||||
SearchStore.emitShowSearch();
|
SearchStore.emitShowSearch();
|
||||||
break;
|
break;
|
||||||
|
case ActionTypes.POST_DELETED:
|
||||||
|
SearchStore.deletePost(action.post);
|
||||||
|
SearchStore.emitSearchChange();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user