2024-10-05 14:21:21 -07:00
|
|
|
import { Record as ImmutableRecord } from 'immutable';
|
2022-06-07 09:25:53 -07:00
|
|
|
|
2024-08-28 04:41:08 -07:00
|
|
|
import { TRENDING_STATUSES_FETCH_REQUEST, TRENDING_STATUSES_FETCH_SUCCESS } from 'pl-fe/actions/trending-statuses';
|
2022-06-07 09:25:53 -07:00
|
|
|
|
2024-08-11 01:48:58 -07:00
|
|
|
import type { Status } from 'pl-api';
|
2022-06-07 09:25:53 -07:00
|
|
|
import type { AnyAction } from 'redux';
|
|
|
|
|
|
|
|
const ReducerRecord = ImmutableRecord({
|
2024-10-05 14:21:21 -07:00
|
|
|
items: Array<string>(),
|
2022-06-07 09:25:53 -07:00
|
|
|
isLoading: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
type State = ReturnType<typeof ReducerRecord>;
|
|
|
|
|
2024-10-05 14:21:21 -07:00
|
|
|
const toIds = (items: Array<Status>) => items.map(item => item.id);
|
2022-06-07 09:25:53 -07:00
|
|
|
|
2024-08-11 01:48:58 -07:00
|
|
|
const importStatuses = (state: State, statuses: Array<Status>) =>
|
2024-05-12 16:18:04 -07:00
|
|
|
state.withMutations(state => {
|
2022-06-07 09:25:53 -07:00
|
|
|
state.set('items', toIds(statuses));
|
|
|
|
state.set('isLoading', false);
|
|
|
|
});
|
|
|
|
|
2024-05-12 16:18:04 -07:00
|
|
|
const trending_statuses = (state: State = ReducerRecord(), action: AnyAction) => {
|
2022-06-07 09:25:53 -07:00
|
|
|
switch (action.type) {
|
|
|
|
case TRENDING_STATUSES_FETCH_REQUEST:
|
|
|
|
return state.set('isLoading', true);
|
|
|
|
case TRENDING_STATUSES_FETCH_SUCCESS:
|
|
|
|
return importStatuses(state, action.statuses);
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
2024-05-12 16:18:04 -07:00
|
|
|
};
|
|
|
|
|
2024-05-13 10:00:42 -07:00
|
|
|
export { trending_statuses as default };
|