Merge branch 'search-hashtags-crash' into 'develop'
Search: fix crash on paginating hashtags See merge request soapbox-pub/soapbox-fe!1319
This commit is contained in:
commit
5284fa5313
|
@ -1,8 +1,9 @@
|
||||||
import { Map as ImmutableMap } from 'immutable';
|
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
SEARCH_CHANGE,
|
SEARCH_CHANGE,
|
||||||
SEARCH_CLEAR,
|
SEARCH_CLEAR,
|
||||||
|
SEARCH_EXPAND_SUCCESS,
|
||||||
} from 'soapbox/actions/search';
|
} from 'soapbox/actions/search';
|
||||||
|
|
||||||
import reducer from '../search';
|
import reducer from '../search';
|
||||||
|
@ -52,4 +53,53 @@ describe('search reducer', () => {
|
||||||
expect(reducer(state, action)).toEqual(expected);
|
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) {
|
if (state.get('value') === searchTerm) {
|
||||||
state.setIn(['results', `${searchType}HasMore`], results[searchType].length >= 20);
|
state.setIn(['results', `${searchType}HasMore`], results[searchType].length >= 20);
|
||||||
state.setIn(['results', `${searchType}Loaded`], true);
|
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…
Reference in New Issue