Fix full-text search query quotation, improve tag search performance with an index,
add ability to open status by URL from search (fix #53)
This commit is contained in:
parent
c89ccbab09
commit
5aa3df017b
14 changed files with 106 additions and 20 deletions
|
@ -1,11 +1,16 @@
|
|||
import Avatar from '../../../components/avatar';
|
||||
import DisplayName from '../../../components/display_name';
|
||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||
|
||||
const AutosuggestAccount = ({ account }) => (
|
||||
<div style={{ overflow: 'hidden' }}>
|
||||
<div style={{ overflow: 'hidden' }} className='autosuggest-account'>
|
||||
<div style={{ float: 'left', marginRight: '5px' }}><Avatar src={account.get('avatar')} size={18} /></div>
|
||||
<DisplayName account={account} />
|
||||
</div>
|
||||
);
|
||||
|
||||
AutosuggestAccount.propTypes = {
|
||||
account: ImmutablePropTypes.map.isRequired
|
||||
};
|
||||
|
||||
export default AutosuggestAccount;
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
import { FormattedMessage } from 'react-intl';
|
||||
import DisplayName from '../../../components/display_name';
|
||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||
|
||||
const AutosuggestStatus = ({ status }) => (
|
||||
<div style={{ overflow: 'hidden' }} className='autosuggest-status'>
|
||||
<FormattedMessage id='search.status_by' defaultMessage='Status by {name}' values={{ name: <strong>@{status.getIn(['account', 'acct'])}</strong> }} />
|
||||
</div>
|
||||
);
|
||||
|
||||
AutosuggestStatus.propTypes = {
|
||||
status: ImmutablePropTypes.map.isRequired
|
||||
};
|
||||
|
||||
export default AutosuggestStatus;
|
|
@ -2,6 +2,7 @@ import PureRenderMixin from 'react-addons-pure-render-mixin';
|
|||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||
import Autosuggest from 'react-autosuggest';
|
||||
import AutosuggestAccountContainer from '../containers/autosuggest_account_container';
|
||||
import AutosuggestStatusContainer from '../containers/autosuggest_status_container';
|
||||
import { debounce } from 'react-decoration';
|
||||
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
||||
|
||||
|
@ -14,8 +15,10 @@ const getSuggestionValue = suggestion => suggestion.value;
|
|||
const renderSuggestion = suggestion => {
|
||||
if (suggestion.type === 'account') {
|
||||
return <AutosuggestAccountContainer id={suggestion.id} />;
|
||||
} else if (suggestion.type === 'hashtag') {
|
||||
return <span>#{suggestion.id}</span>;
|
||||
} else {
|
||||
return <span>#{suggestion.id}</span>
|
||||
return <AutosuggestStatusContainer id={suggestion.id} />;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -78,8 +81,10 @@ const Search = React.createClass({
|
|||
onSuggestionSelected (_, { suggestion }) {
|
||||
if (suggestion.type === 'account') {
|
||||
this.context.router.push(`/accounts/${suggestion.id}`);
|
||||
} else {
|
||||
} else if(suggestion.type === 'hashtag') {
|
||||
this.context.router.push(`/timelines/tag/${suggestion.id}`);
|
||||
} else {
|
||||
this.context.router.push(`/statuses/${suggestion.id}`);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
import { connect } from 'react-redux';
|
||||
import AutosuggestStatus from '../components/autosuggest_status';
|
||||
import { makeGetStatus } from '../../../selectors';
|
||||
|
||||
const makeMapStateToProps = () => {
|
||||
const getStatus = makeGetStatus();
|
||||
|
||||
const mapStateToProps = (state, { id }) => ({
|
||||
status: getStatus(state, id)
|
||||
});
|
||||
|
||||
return mapStateToProps;
|
||||
};
|
||||
|
||||
export default connect(makeMapStateToProps)(AutosuggestStatus);
|
|
@ -90,7 +90,6 @@ export default function accounts(state = initialState, action) {
|
|||
case REBLOGS_FETCH_SUCCESS:
|
||||
case FAVOURITES_FETCH_SUCCESS:
|
||||
case COMPOSE_SUGGESTIONS_READY:
|
||||
case SEARCH_SUGGESTIONS_READY:
|
||||
case FOLLOW_REQUESTS_FETCH_SUCCESS:
|
||||
case FOLLOW_REQUESTS_EXPAND_SUCCESS:
|
||||
case BLOCKS_FETCH_SUCCESS:
|
||||
|
@ -98,6 +97,7 @@ export default function accounts(state = initialState, action) {
|
|||
return normalizeAccounts(state, action.accounts);
|
||||
case NOTIFICATIONS_REFRESH_SUCCESS:
|
||||
case NOTIFICATIONS_EXPAND_SUCCESS:
|
||||
case SEARCH_SUGGESTIONS_READY:
|
||||
return normalizeAccountsFromStatuses(normalizeAccounts(state, action.accounts), action.statuses);
|
||||
case TIMELINE_REFRESH_SUCCESS:
|
||||
case TIMELINE_EXPAND_SUCCESS:
|
||||
|
|
|
@ -32,7 +32,7 @@ const normalizeSuggestions = (state, value, accounts, hashtags, statuses) => {
|
|||
value: `#${item}`
|
||||
}));
|
||||
|
||||
if (value.indexOf('@') === -1 && value.indexOf(' ') === -1 && hashtags.indexOf(value) === -1) {
|
||||
if (value.indexOf('@') === -1 && value.indexOf(' ') === -1 && !value.startsWith('http://') && !value.startsWith('https://') && hashtags.indexOf(value) === -1) {
|
||||
hashtagItems.unshift({
|
||||
type: 'hashtag',
|
||||
id: value,
|
||||
|
@ -40,9 +40,22 @@ const normalizeSuggestions = (state, value, accounts, hashtags, statuses) => {
|
|||
});
|
||||
}
|
||||
|
||||
if (hashtagItems.length > 0) {
|
||||
newSuggestions.push({
|
||||
title: 'hashtag',
|
||||
items: hashtagItems
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (statuses.length > 0) {
|
||||
newSuggestions.push({
|
||||
title: 'hashtag',
|
||||
items: hashtagItems
|
||||
title: 'status',
|
||||
items: statuses.map(item => ({
|
||||
type: 'status',
|
||||
id: item.id,
|
||||
value: item.id
|
||||
}))
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1421,3 +1421,13 @@ button.active i.fa-retweet {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
.autosuggest-status {
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
|
||||
strong {
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue