2022-02-25 10:34:33 +11:00
|
|
|
import {
|
|
|
|
TRENDS_TAGS_FETCH_REQUEST,
|
|
|
|
TRENDS_TAGS_FETCH_SUCCESS,
|
|
|
|
TRENDS_TAGS_FETCH_FAIL,
|
|
|
|
TRENDS_LINKS_FETCH_REQUEST,
|
|
|
|
TRENDS_LINKS_FETCH_SUCCESS,
|
|
|
|
TRENDS_LINKS_FETCH_FAIL,
|
|
|
|
} from 'mastodon/actions/trends';
|
2019-08-07 01:57:52 +10:00
|
|
|
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
|
|
|
|
|
|
|
|
const initialState = ImmutableMap({
|
2022-02-25 10:34:33 +11:00
|
|
|
tags: ImmutableMap({
|
|
|
|
items: ImmutableList(),
|
|
|
|
isLoading: false,
|
|
|
|
}),
|
|
|
|
|
|
|
|
links: ImmutableMap({
|
|
|
|
items: ImmutableList(),
|
|
|
|
isLoading: false,
|
|
|
|
}),
|
2019-08-07 01:57:52 +10:00
|
|
|
});
|
|
|
|
|
|
|
|
export default function trendsReducer(state = initialState, action) {
|
|
|
|
switch(action.type) {
|
2022-02-25 10:34:33 +11:00
|
|
|
case TRENDS_TAGS_FETCH_REQUEST:
|
|
|
|
return state.setIn(['tags', 'isLoading'], true);
|
|
|
|
case TRENDS_TAGS_FETCH_SUCCESS:
|
|
|
|
return state.withMutations(map => {
|
|
|
|
map.setIn(['tags', 'items'], fromJS(action.trends));
|
|
|
|
map.setIn(['tags', 'isLoading'], false);
|
|
|
|
});
|
|
|
|
case TRENDS_TAGS_FETCH_FAIL:
|
|
|
|
return state.setIn(['tags', 'isLoading'], false);
|
|
|
|
case TRENDS_LINKS_FETCH_REQUEST:
|
|
|
|
return state.setIn(['links', 'isLoading'], true);
|
|
|
|
case TRENDS_LINKS_FETCH_SUCCESS:
|
2019-08-07 01:57:52 +10:00
|
|
|
return state.withMutations(map => {
|
2022-02-25 10:34:33 +11:00
|
|
|
map.setIn(['links', 'items'], fromJS(action.trends));
|
|
|
|
map.setIn(['links', 'isLoading'], false);
|
2019-08-07 01:57:52 +10:00
|
|
|
});
|
2022-02-25 10:34:33 +11:00
|
|
|
case TRENDS_LINKS_FETCH_FAIL:
|
|
|
|
return state.setIn(['links', 'isLoading'], false);
|
2019-08-07 01:57:52 +10:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
2022-12-19 02:51:37 +11:00
|
|
|
}
|