pulsar-web/src/store/community/community.ts

34 lines
1 KiB
TypeScript

import { fetchCommunity } from "../../services/community";
import { CommunityActionTypes, CommunityAction } from "./actions";
import { ICommunityState } from "./types";
function communityReducer(
state: ICommunityState,
action: CommunityAction,
): ICommunityState {
switch (action.type) {
case CommunityActionTypes.FETCH_COMMUNITY_START:
fetchCommunity(action.payload);
return state;
case CommunityActionTypes.FETCH_COMMUNITY_FINISH:
return {
...state,
communities: {
...state.communities,
[action.payload.id]: action.payload,
},
};
case CommunityActionTypes.SET_COMMUNITY:
return {
...state,
communities: {
...state.communities,
[action.payload.id]: action.payload,
},
};
default:
return state;
}
}
export { communityReducer };