Rework store

This commit is contained in:
Aslan 2026-01-02 00:14:11 +01:00
parent ef526cd2db
commit 8881070cac
9 changed files with 119 additions and 122 deletions

View file

@ -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;
}
}