Communities and channels
This commit is contained in:
parent
79dbeb6b7a
commit
280158470a
34 changed files with 558 additions and 62 deletions
|
|
@ -1,5 +1,13 @@
|
|||
import { fetchCommunityApi } from "../../api/community";
|
||||
import {
|
||||
fetchCommunityApi,
|
||||
fetchCommunityChannelsApi,
|
||||
fetchCommunityRolesApi,
|
||||
fetchCommunityMembersApi,
|
||||
} from "../../api/community";
|
||||
import { CommunityActionTypes } from "../../store/community";
|
||||
import { ChannelActionTypes } from "../../store/channel";
|
||||
import { RoleActionTypes } from "../../store/role";
|
||||
import { UserActionTypes } from "../../store/user";
|
||||
import { dispatch } from "../../store/state";
|
||||
|
||||
const fetchCommunity = async (id: string) => {
|
||||
|
|
@ -13,4 +21,63 @@ const fetchCommunity = async (id: string) => {
|
|||
});
|
||||
};
|
||||
|
||||
export { fetchCommunity };
|
||||
const fetchCommunityChannels = async (id: string) => {
|
||||
const data = await fetchCommunityChannelsApi({
|
||||
id: id,
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: CommunityActionTypes.FETCH_COMMUNITY_CHANNELS_FINISH,
|
||||
payload: data,
|
||||
});
|
||||
|
||||
data.channels.forEach((channel) => {
|
||||
dispatch({
|
||||
type: ChannelActionTypes.SET_CHANNEL,
|
||||
payload: channel,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const fetchCommunityRoles = async (id: string) => {
|
||||
const data = await fetchCommunityRolesApi({
|
||||
id: id,
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: CommunityActionTypes.FETCH_COMMUNITY_ROLES_FINISH,
|
||||
payload: data,
|
||||
});
|
||||
|
||||
data.roles.forEach((role) => {
|
||||
dispatch({
|
||||
type: RoleActionTypes.SET_ROLE,
|
||||
payload: role,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const fetchCommunityMembers = async (id: string) => {
|
||||
const data = await fetchCommunityMembersApi({
|
||||
id: id,
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: CommunityActionTypes.FETCH_COMMUNITY_MEMBERS_FINISH,
|
||||
payload: data,
|
||||
});
|
||||
|
||||
data.members.forEach((member) => {
|
||||
dispatch({
|
||||
type: UserActionTypes.SET_USER,
|
||||
payload: member,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export {
|
||||
fetchCommunity,
|
||||
fetchCommunityChannels,
|
||||
fetchCommunityRoles,
|
||||
fetchCommunityMembers,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue