mirror of https://github.com/Siphonay/mastodon
Web UI support for the new omnisearch
This commit is contained in:
parent
acfee0945c
commit
88f32708c3
|
@ -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,
|
||||||
|
|
|
@ -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) {
|
if (value.indexOf('@') === -1 && value.indexOf(' ') === -1 || hashtags.length > 0) {
|
||||||
newSuggestions.push({
|
let hashtagItems = hashtags.map(item => ({
|
||||||
title: 'hashtag',
|
type: 'hashtag',
|
||||||
items: [
|
id: item,
|
||||||
{
|
value: `#${item}`
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (value.indexOf('@') === -1 && value.indexOf(' ') === -1 && hashtags.indexOf(value) === -1) {
|
||||||
|
hashtagItems.unshift({
|
||||||
type: 'hashtag',
|
type: 'hashtag',
|
||||||
id: value,
|
id: value,
|
||||||
value: `#${value}`
|
value: `#${value}`
|
||||||
|
});
|
||||||
}
|
}
|
||||||
]
|
|
||||||
|
newSuggestions.push({
|
||||||
|
title: 'hashtag',
|
||||||
|
items: hashtagItems
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +57,7 @@ export default function search(state = initialState, action) {
|
||||||
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', []);
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue