Web UI support for the new omnisearch
This commit is contained in:
		
							parent
							
								
									acfee0945c
								
							
						
					
					
						commit
						88f32708c3
					
				
					 4 changed files with 44 additions and 30 deletions
				
			
		| 
						 | 
				
			
			@ -18,11 +18,13 @@ export function clearSearchSuggestions() {
 | 
			
		|||
  };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export function readySearchSuggestions(value, accounts) {
 | 
			
		||||
export function readySearchSuggestions(value, { accounts, hashtags, statuses }) {
 | 
			
		||||
  return {
 | 
			
		||||
    type: SEARCH_SUGGESTIONS_READY,
 | 
			
		||||
    value,
 | 
			
		||||
    accounts
 | 
			
		||||
    accounts,
 | 
			
		||||
    hashtags,
 | 
			
		||||
    statuses
 | 
			
		||||
  };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -32,7 +34,7 @@ export function fetchSearchSuggestions(value) {
 | 
			
		|||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    api(getState).get('/api/v1/accounts/search', {
 | 
			
		||||
    api(getState).get('/api/v1/search', {
 | 
			
		||||
      params: {
 | 
			
		||||
        q: value,
 | 
			
		||||
        resolve: true,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,28 +11,38 @@ const initialState = Immutable.Map({
 | 
			
		|||
  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
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -44,17 +54,17 @@ const normalizeSuggestions = (state, value, accounts) => {
 | 
			
		|||
 | 
			
		||||
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;
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -32,6 +32,7 @@ import {
 | 
			
		|||
  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) => {
 | 
			
		||||
| 
						 | 
				
			
			@ -108,6 +109,7 @@ export default function statuses(state = initialState, action) {
 | 
			
		|||
  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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
object @search
 | 
			
		||||
 | 
			
		||||
child accounts: :accounts do
 | 
			
		||||
child :accounts, object_root: false do
 | 
			
		||||
  extends 'api/v1/accounts/show'
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -8,6 +8,6 @@ node(:hashtags) do |search|
 | 
			
		|||
  search.hashtags.map(&:name)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
child statuses: :statuses do
 | 
			
		||||
child :statuses, object_root: false do
 | 
			
		||||
  extends 'api/v1/statuses/show'
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue