0
0
Fork 0

Change search pop-out in web UI (#24305)

This commit is contained in:
Eugen Rochko 2023-04-01 09:59:10 +02:00 committed by GitHub
parent 46483ae849
commit 2b11376411
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 447 additions and 91 deletions

View file

@ -6,13 +6,15 @@ import {
SEARCH_FETCH_SUCCESS,
SEARCH_SHOW,
SEARCH_EXPAND_SUCCESS,
SEARCH_RESULT_CLICK,
SEARCH_RESULT_FORGET,
} from '../actions/search';
import {
COMPOSE_MENTION,
COMPOSE_REPLY,
COMPOSE_DIRECT,
} from '../actions/compose';
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
import { Map as ImmutableMap, List as ImmutableList, OrderedSet as ImmutableOrderedSet, fromJS } from 'immutable';
const initialState = ImmutableMap({
value: '',
@ -21,6 +23,7 @@ const initialState = ImmutableMap({
results: ImmutableMap(),
isLoading: false,
searchTerm: '',
recent: ImmutableOrderedSet(),
});
export default function search(state = initialState, action) {
@ -61,6 +64,10 @@ export default function search(state = initialState, action) {
case SEARCH_EXPAND_SUCCESS:
const results = action.searchType === 'hashtags' ? fromJS(action.results.hashtags) : action.results[action.searchType].map(item => item.id);
return state.updateIn(['results', action.searchType], list => list.concat(results));
case SEARCH_RESULT_CLICK:
return state.update('recent', set => set.add(fromJS(action.result)));
case SEARCH_RESULT_FORGET:
return state.update('recent', set => set.filterNot(result => result.get('q') === action.q));
default:
return state;
}