Web UI support for the new omnisearch

remotes/1727458204337373841/tmp_refs/heads/signup-info-prompt
Eugen Rochko 2017-03-22 04:09:09 +01:00
parent acfee0945c
commit 88f32708c3
4 changed files with 44 additions and 30 deletions

View File

@ -18,11 +18,13 @@ export function clearSearchSuggestions() {
}; };
}; };
export function readySearchSuggestions(value, accounts) { export function readySearchSuggestions(value, { accounts, hashtags, statuses }) {
return { return {
type: SEARCH_SUGGESTIONS_READY, type: SEARCH_SUGGESTIONS_READY,
value, value,
accounts accounts,
hashtags,
statuses
}; };
}; };
@ -32,7 +34,7 @@ export function fetchSearchSuggestions(value) {
return; return;
} }
api(getState).get('/api/v1/accounts/search', { api(getState).get('/api/v1/search', {
params: { params: {
q: value, q: value,
resolve: true, resolve: true,

View File

@ -11,28 +11,38 @@ const initialState = Immutable.Map({
suggestions: [] suggestions: []
}); });
const normalizeSuggestions = (state, value, accounts) => { const normalizeSuggestions = (state, value, accounts, hashtags, statuses) => {
let newSuggestions = [ let newSuggestions = [];
{
if (accounts.length > 0) {
newSuggestions.push({
title: 'account', title: 'account',
items: accounts.map(item => ({ items: accounts.map(item => ({
type: 'account', type: 'account',
id: item.id, id: item.id,
value: item.acct 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({ newSuggestions.push({
title: 'hashtag', title: 'hashtag',
items: [ items: hashtagItems
{
type: 'hashtag',
id: value,
value: `#${value}`
}
]
}); });
} }
@ -44,17 +54,17 @@ const normalizeSuggestions = (state, value, accounts) => {
export default function search(state = initialState, action) { export default function search(state = initialState, action) {
switch(action.type) { switch(action.type) {
case SEARCH_CHANGE: case SEARCH_CHANGE:
return state.set('value', action.value); return state.set('value', action.value);
case SEARCH_SUGGESTIONS_READY: case SEARCH_SUGGESTIONS_READY:
return normalizeSuggestions(state, action.value, action.accounts); return normalizeSuggestions(state, action.value, action.accounts, action.hashtags, action.statuses);
case SEARCH_RESET: case SEARCH_RESET:
return state.withMutations(map => { return state.withMutations(map => {
map.set('suggestions', []); map.set('suggestions', []);
map.set('value', ''); map.set('value', '');
map.set('loaded_value', ''); map.set('loaded_value', '');
}); });
default: default:
return state; return state;
} }
}; };

View File

@ -32,6 +32,7 @@ import {
FAVOURITED_STATUSES_FETCH_SUCCESS, FAVOURITED_STATUSES_FETCH_SUCCESS,
FAVOURITED_STATUSES_EXPAND_SUCCESS FAVOURITED_STATUSES_EXPAND_SUCCESS
} from '../actions/favourites'; } from '../actions/favourites';
import { SEARCH_SUGGESTIONS_READY } from '../actions/search';
import Immutable from 'immutable'; import Immutable from 'immutable';
const normalizeStatus = (state, status) => { const normalizeStatus = (state, status) => {
@ -108,6 +109,7 @@ export default function statuses(state = initialState, action) {
case NOTIFICATIONS_EXPAND_SUCCESS: case NOTIFICATIONS_EXPAND_SUCCESS:
case FAVOURITED_STATUSES_FETCH_SUCCESS: case FAVOURITED_STATUSES_FETCH_SUCCESS:
case FAVOURITED_STATUSES_EXPAND_SUCCESS: case FAVOURITED_STATUSES_EXPAND_SUCCESS:
case SEARCH_SUGGESTIONS_READY:
return normalizeStatuses(state, action.statuses); return normalizeStatuses(state, action.statuses);
case TIMELINE_DELETE: case TIMELINE_DELETE:
return deleteStatus(state, action.id, action.references); return deleteStatus(state, action.id, action.references);

View File

@ -1,6 +1,6 @@
object @search object @search
child accounts: :accounts do child :accounts, object_root: false do
extends 'api/v1/accounts/show' extends 'api/v1/accounts/show'
end end
@ -8,6 +8,6 @@ node(:hashtags) do |search|
search.hashtags.map(&:name) search.hashtags.map(&:name)
end end
child statuses: :statuses do child :statuses, object_root: false do
extends 'api/v1/statuses/show' extends 'api/v1/statuses/show'
end end