Rework store
This commit is contained in:
parent
ef526cd2db
commit
8881070cac
9 changed files with 119 additions and 122 deletions
|
|
@ -1,33 +1,25 @@
|
|||
import { fetchCommunity } from "../../services/community";
|
||||
import { setState } from "../state";
|
||||
import { CommunityActionTypes, CommunityAction } from "./actions";
|
||||
import { ICommunityState } from "./types";
|
||||
|
||||
function communityReducer(
|
||||
state: ICommunityState,
|
||||
action: CommunityAction,
|
||||
): ICommunityState {
|
||||
function communityReducer(state: ICommunityState, action: CommunityAction) {
|
||||
switch (action.type) {
|
||||
case CommunityActionTypes.FETCH_COMMUNITY_START:
|
||||
fetchCommunity(action.payload);
|
||||
return state;
|
||||
break;
|
||||
case CommunityActionTypes.FETCH_COMMUNITY_FINISH:
|
||||
return {
|
||||
...state,
|
||||
communities: {
|
||||
...state.communities,
|
||||
[action.payload.id]: action.payload,
|
||||
},
|
||||
};
|
||||
setState("community", "communities", {
|
||||
...state.communities,
|
||||
[action.payload.id]: action.payload,
|
||||
});
|
||||
break;
|
||||
case CommunityActionTypes.SET_COMMUNITY:
|
||||
return {
|
||||
...state,
|
||||
communities: {
|
||||
...state.communities,
|
||||
[action.payload.id]: action.payload,
|
||||
},
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
setState("community", "communities", {
|
||||
...state.communities,
|
||||
[action.payload.id]: action.payload,
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue