Add infinite scrolling for search results in web UI (#26784)
This commit is contained in:
parent
548c032dbb
commit
5d20733d8d
7 changed files with 255 additions and 171 deletions
|
@ -1,4 +1,4 @@
|
|||
import { Map as ImmutableMap, List as ImmutableList, OrderedSet as ImmutableOrderedSet, fromJS } from 'immutable';
|
||||
import { Map as ImmutableMap, OrderedSet as ImmutableOrderedSet, fromJS } from 'immutable';
|
||||
|
||||
import {
|
||||
COMPOSE_MENTION,
|
||||
|
@ -12,6 +12,7 @@ import {
|
|||
SEARCH_FETCH_FAIL,
|
||||
SEARCH_FETCH_SUCCESS,
|
||||
SEARCH_SHOW,
|
||||
SEARCH_EXPAND_REQUEST,
|
||||
SEARCH_EXPAND_SUCCESS,
|
||||
SEARCH_RESULT_CLICK,
|
||||
SEARCH_RESULT_FORGET,
|
||||
|
@ -24,6 +25,7 @@ const initialState = ImmutableMap({
|
|||
results: ImmutableMap(),
|
||||
isLoading: false,
|
||||
searchTerm: '',
|
||||
type: null,
|
||||
recent: ImmutableOrderedSet(),
|
||||
});
|
||||
|
||||
|
@ -37,6 +39,8 @@ export default function search(state = initialState, action) {
|
|||
map.set('results', ImmutableMap());
|
||||
map.set('submitted', false);
|
||||
map.set('hidden', false);
|
||||
map.set('searchTerm', '');
|
||||
map.set('type', null);
|
||||
});
|
||||
case SEARCH_SHOW:
|
||||
return state.set('hidden', false);
|
||||
|
@ -48,23 +52,27 @@ export default function search(state = initialState, action) {
|
|||
return state.withMutations(map => {
|
||||
map.set('isLoading', true);
|
||||
map.set('submitted', true);
|
||||
map.set('type', action.searchType);
|
||||
});
|
||||
case SEARCH_FETCH_FAIL:
|
||||
return state.set('isLoading', false);
|
||||
case SEARCH_FETCH_SUCCESS:
|
||||
return state.withMutations(map => {
|
||||
map.set('results', ImmutableMap({
|
||||
accounts: ImmutableList(action.results.accounts.map(item => item.id)),
|
||||
statuses: ImmutableList(action.results.statuses.map(item => item.id)),
|
||||
hashtags: fromJS(action.results.hashtags),
|
||||
accounts: ImmutableOrderedSet(action.results.accounts.map(item => item.id)),
|
||||
statuses: ImmutableOrderedSet(action.results.statuses.map(item => item.id)),
|
||||
hashtags: ImmutableOrderedSet(fromJS(action.results.hashtags)),
|
||||
}));
|
||||
|
||||
map.set('searchTerm', action.searchTerm);
|
||||
map.set('type', action.searchType);
|
||||
map.set('isLoading', false);
|
||||
});
|
||||
case SEARCH_EXPAND_REQUEST:
|
||||
return state.set('type', action.searchType);
|
||||
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));
|
||||
const results = action.searchType === 'hashtags' ? ImmutableOrderedSet(fromJS(action.results.hashtags)) : action.results[action.searchType].map(item => item.id);
|
||||
return state.updateIn(['results', action.searchType], list => list.union(results));
|
||||
case SEARCH_RESULT_CLICK:
|
||||
return state.update('recent', set => set.add(fromJS(action.result)));
|
||||
case SEARCH_RESULT_FORGET:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue