import { CommunityPolicyEnum, AccountCommunityType } from "@openchat/types" import {…
- User
import { CommunityPolicyEnum, AccountCommunityType } from "@openchat/types" import { Models } from "@openchat/models" import { useBanByCommunityAndIdentity, useCommunity, useCurrentIdentityId, useAccountCommunityBy, } from "@openchat/ui" import { useEffect, useState } from "react" import { useNavigate } from "react-router-dom" import { AppController, AppStore } from "../../../app/app.globals" import { useDashboardSettings } from "../../../hook/use-dashboard-settings.hook.js" import { Button } from "../../../ui-component/button/button.component" import { memoComponent } from "@openchat/ui" import { CommunityInfo } from "./community-info.component" import styles from "./community-panel.styles.module.css"
export const CommunityPanel = memoComponent("CommunityPanel", () => { // --------------------------------------------------------------------------- // variables // ---------------------------------------------------------------------------
const { selectedTab } = useDashboardSettings() const navigate = useNavigate() const communityId = selectedTab.type === "community" ? selectedTab.communityId : null const accountCommunity = useAccountCommunityBy({ communityId, }) const [isLoaded, setLoading] = useState(false) const [hasMembership, setMembership] = useState(false) const [hasJoinRequest, setJoinRequest] = useState(false) const [isDeleted, setDeleted] = useState(false) const [isDisabled, setIsDisabled] = useState(false)
const currentIdentityId = useCurrentIdentityId() const currentUserBan = useBanByCommunityAndIdentity( communityId, currentIdentityId, ) const isBanned = !!currentUserBan const community = useCommunity(communityId)
// --------------------------------------------------------------------------- // effects // ---------------------------------------------------------------------------
useEffect(() => { loadCommunity() }, [accountCommunity, communityId])
// --------------------------------------------------------------------------- // functions // ---------------------------------------------------------------------------
async function loadCommunity() { if (!accountCommunity || !communityId) return if (accountCommunity.isDeleted === true) { setDeleted(true) return }
code// if we already have community, we don't need to check an access if (AppStore.for(Models.Changeset).has(communityId)) { setLoading(true) return } // for private communities we need to check if current user is a community member // todo: re-implement // if (accountCommunity.policy === CommunityPolicyEnum.private) { // // if user doesn't have a membership - he will be asked to send a petition, // // in the case if petition was not sent yet // const hasJoinRequest = await AppController.joinRequest.checkIfSent( // accountCommunity.communityId, // ) // setJoinRequest(hasJoinRequest) // } if (accountCommunity && !community) { await AppController.community.import(accountCommunity.communityId) } setLoading(true) - Assistant