};
};
-export function readySearchSuggestions(value, accounts) {
+export function readySearchSuggestions(value, { accounts, hashtags, statuses }) {
return {
type: SEARCH_SUGGESTIONS_READY,
value,
- accounts
+ accounts,
+ hashtags,
+ statuses
};
};
return;
}
- api(getState).get('/api/v1/accounts/search', {
+ api(getState).get('/api/v1/search', {
params: {
q: value,
resolve: true,
suggestions: []
});
-const normalizeSuggestions = (state, value, accounts) => {
- let newSuggestions = [
- {
+const normalizeSuggestions = (state, value, accounts, hashtags, statuses) => {
+ let newSuggestions = [];
+
+ if (accounts.length > 0) {
+ newSuggestions.push({
title: 'account',
items: accounts.map(item => ({
type: 'account',
id: item.id,
value: item.acct
}))
+ });
+ }
+
+ if (value.indexOf('@') === -1 && value.indexOf(' ') === -1 || hashtags.length > 0) {
+ let hashtagItems = hashtags.map(item => ({
+ type: 'hashtag',
+ id: item,
+ value: `#${item}`
+ }));
+
+ if (value.indexOf('@') === -1 && value.indexOf(' ') === -1 && hashtags.indexOf(value) === -1) {
+ hashtagItems.unshift({
+ type: 'hashtag',
+ id: value,
+ value: `#${value}`
+ });
}
- ];
- if (value.indexOf('@') === -1 && value.indexOf(' ') === -1) {
newSuggestions.push({
title: 'hashtag',
- items: [
- {
- type: 'hashtag',
- id: value,
- value: `#${value}`
- }
- ]
+ items: hashtagItems
});
}
export default function search(state = initialState, action) {
switch(action.type) {
- case SEARCH_CHANGE:
- return state.set('value', action.value);
- case SEARCH_SUGGESTIONS_READY:
- return normalizeSuggestions(state, action.value, action.accounts);
- case SEARCH_RESET:
- return state.withMutations(map => {
- map.set('suggestions', []);
- map.set('value', '');
- map.set('loaded_value', '');
- });
- default:
- return state;
+ case SEARCH_CHANGE:
+ return state.set('value', action.value);
+ case SEARCH_SUGGESTIONS_READY:
+ return normalizeSuggestions(state, action.value, action.accounts, action.hashtags, action.statuses);
+ case SEARCH_RESET:
+ return state.withMutations(map => {
+ map.set('suggestions', []);
+ map.set('value', '');
+ map.set('loaded_value', '');
+ });
+ default:
+ return state;
}
};
FAVOURITED_STATUSES_FETCH_SUCCESS,
FAVOURITED_STATUSES_EXPAND_SUCCESS
} from '../actions/favourites';
+import { SEARCH_SUGGESTIONS_READY } from '../actions/search';
import Immutable from 'immutable';
const normalizeStatus = (state, status) => {
case NOTIFICATIONS_EXPAND_SUCCESS:
case FAVOURITED_STATUSES_FETCH_SUCCESS:
case FAVOURITED_STATUSES_EXPAND_SUCCESS:
+ case SEARCH_SUGGESTIONS_READY:
return normalizeStatuses(state, action.statuses);
case TIMELINE_DELETE:
return deleteStatus(state, action.id, action.references);
object @search
-child accounts: :accounts do
+child :accounts, object_root: false do
extends 'api/v1/accounts/show'
end
search.hashtags.map(&:name)
end
-child statuses: :statuses do
+child :statuses, object_root: false do
extends 'api/v1/statuses/show'
end