2022-05-14 11:07:32 -07:00
|
|
|
import {
|
|
|
|
Map as ImmutableMap,
|
|
|
|
Record as ImmutableRecord,
|
|
|
|
List as ImmutableList,
|
|
|
|
} from 'immutable';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2020-03-27 13:59:38 -07:00
|
|
|
import {
|
|
|
|
TRENDS_FETCH_REQUEST,
|
|
|
|
TRENDS_FETCH_SUCCESS,
|
|
|
|
TRENDS_FETCH_FAIL,
|
|
|
|
} from '../actions/trends';
|
|
|
|
|
2022-05-14 11:07:32 -07:00
|
|
|
import type { AnyAction } from 'redux';
|
|
|
|
|
|
|
|
const ReducerRecord = ImmutableRecord({
|
|
|
|
items: ImmutableList<ImmutableMap<string, any>>(),
|
2020-03-27 13:59:38 -07:00
|
|
|
isLoading: false,
|
|
|
|
});
|
|
|
|
|
2022-05-14 11:07:32 -07:00
|
|
|
export default function trendsReducer(state = ReducerRecord(), action: AnyAction) {
|
2022-05-11 10:40:34 -07:00
|
|
|
switch (action.type) {
|
2022-05-11 14:06:35 -07:00
|
|
|
case TRENDS_FETCH_REQUEST:
|
|
|
|
return state.set('isLoading', true);
|
|
|
|
case TRENDS_FETCH_SUCCESS:
|
|
|
|
return state.withMutations(map => {
|
2022-05-14 11:07:32 -07:00
|
|
|
map.set('items', ImmutableList(action.tags.map(ImmutableMap)));
|
2022-05-11 14:06:35 -07:00
|
|
|
map.set('isLoading', false);
|
|
|
|
});
|
|
|
|
case TRENDS_FETCH_FAIL:
|
|
|
|
return state.set('isLoading', false);
|
|
|
|
default:
|
|
|
|
return state;
|
2020-03-27 13:59:38 -07:00
|
|
|
}
|
2021-08-03 12:22:51 -07:00
|
|
|
}
|