Communities and channels

This commit is contained in:
Aslan 2026-01-07 21:01:01 -05:00
parent 79dbeb6b7a
commit 280158470a
34 changed files with 558 additions and 62 deletions

View file

@ -1,23 +1,59 @@
import { fetchCommunity } from "../../services/community";
import {
fetchCommunity,
fetchCommunityChannels,
fetchCommunityRoles,
fetchCommunityMembers,
} from "../../services/community";
import { setState } from "../state";
import { CommunityActionTypes, CommunityAction } from "./actions";
import { ICommunityState } from "./types";
function communityReducer(state: ICommunityState, action: CommunityAction) {
switch (action.type) {
case CommunityActionTypes.SET_COMMUNITY:
setState(
"community",
"communities",
action.payload.id,
action.payload,
);
break;
case CommunityActionTypes.SET_ACTIVE_COMMUNITY:
setState("community", "active", action.payload);
break;
case CommunityActionTypes.FETCH_COMMUNITY_START:
fetchCommunity(action.payload);
break;
case CommunityActionTypes.FETCH_COMMUNITY_FINISH:
setState("community", "communities", {
...state.communities,
[action.payload.id]: action.payload,
setState(
"community",
"communities",
action.payload.id,
action.payload,
);
break;
case CommunityActionTypes.FETCH_COMMUNITY_CHANNELS_START:
fetchCommunityChannels(action.payload);
break;
case CommunityActionTypes.FETCH_COMMUNITY_CHANNELS_FINISH:
setState("community", "communities", action.payload.id, {
channels: action.payload.channels.map((channel) => channel.id),
});
break;
case CommunityActionTypes.SET_COMMUNITY:
setState("community", "communities", {
...state.communities,
[action.payload.id]: action.payload,
case CommunityActionTypes.FETCH_COMMUNITY_ROLES_START:
fetchCommunityRoles(action.payload);
break;
case CommunityActionTypes.FETCH_COMMUNITY_ROLES_FINISH:
setState("community", "communities", action.payload.id, {
roles: action.payload.roles.map((role) => role.id),
});
break;
case CommunityActionTypes.FETCH_COMMUNITY_MEMBERS_START:
fetchCommunityMembers(action.payload);
break;
case CommunityActionTypes.FETCH_COMMUNITY_MEMBERS_FINISH:
setState("community", "communities", action.payload.id, {
members: action.payload.members.map((member) => member.id),
});
break;
}