Search: fix crash on paginating hashtags

api-accept
Alex Gleason 2 years ago
parent e734c7c967
commit a657b6374c
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7

@ -1,8 +1,9 @@
import { Map as ImmutableMap } from 'immutable';
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
import {
SEARCH_CHANGE,
SEARCH_CLEAR,
SEARCH_EXPAND_SUCCESS,
} from 'soapbox/actions/search';
import reducer from '../search';
@ -52,4 +53,53 @@ describe('search reducer', () => {
expect(reducer(state, action)).toEqual(expected);
});
});
describe(SEARCH_EXPAND_SUCCESS, () => {
it('imports hashtags as maps', () => {
const state = ImmutableMap({
value: 'artist',
submitted: true,
submittedValue: 'artist',
hidden: false,
results: ImmutableMap({
hashtags: ImmutableList(),
}),
filter: 'hashtags',
});
const action = {
type: SEARCH_EXPAND_SUCCESS,
results: {
accounts: [],
statuses: [],
hashtags: [{
name: 'artist',
url: 'https://gleasonator.com/tags/artist',
history: [],
}],
},
searchTerm: 'artist',
searchType: 'hashtags',
};
const expected = ImmutableMap({
value: 'artist',
submitted: true,
submittedValue: 'artist',
hidden: false,
results: ImmutableMap({
hashtags: fromJS([{
name: 'artist',
url: 'https://gleasonator.com/tags/artist',
history: [],
}]),
hashtagsHasMore: false,
hashtagsLoaded: true,
}),
filter: 'hashtags',
});
expect(reducer(state, action)).toEqual(expected);
});
});
});

@ -55,7 +55,15 @@ const paginateResults = (state, searchType, results, searchTerm) => {
if (state.get('value') === searchTerm) {
state.setIn(['results', `${searchType}HasMore`], results[searchType].length >= 20);
state.setIn(['results', `${searchType}Loaded`], true);
state.updateIn(['results', searchType], items => items.concat(results[searchType].map(item => item.id)));
state.updateIn(['results', searchType], items => {
const data = results[searchType];
// Hashtags are a list of maps. Others are IDs.
if (searchType === 'hashtags') {
return items.concat(fromJS(data));
} else {
return items.concat(toIds(data));
}
});
}
});
};

Loading…
Cancel
Save