mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
refactor: migrate 5chan to the community hooks API (#1073)
* refactor(community-api): migrate 5chan to community hooks * fix(review): address PR feedback * fix(review): preserve legacy board context fallbacks * fix(review): address latest bot feedback * fix(review): use communityAddress in edit menu privileges
This commit is contained in:
@@ -1,18 +1,20 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useAccount } from '@bitsocialnet/bitsocial-react-hooks';
|
||||
import { useSubplebbitField } from './use-stable-subplebbit';
|
||||
import { useCommunityField } from './use-stable-community';
|
||||
|
||||
interface AuthorPrivilegesProps {
|
||||
commentAuthorAddress: string;
|
||||
subplebbitAddress: string;
|
||||
subplebbitAddress?: string;
|
||||
communityAddress?: string;
|
||||
postCid?: string;
|
||||
}
|
||||
|
||||
const useAuthorPrivileges = ({ commentAuthorAddress, subplebbitAddress }: AuthorPrivilegesProps) => {
|
||||
const useAuthorPrivileges = ({ commentAuthorAddress, subplebbitAddress, communityAddress }: AuthorPrivilegesProps) => {
|
||||
const account = useAccount();
|
||||
const targetAddress = communityAddress ?? subplebbitAddress;
|
||||
const accountAuthorAddress = account?.author?.address;
|
||||
// Only subscribe to roles field to avoid rerenders from updatingState changes
|
||||
const roles = useSubplebbitField(subplebbitAddress, (subplebbit) => subplebbit?.roles);
|
||||
const roles = useCommunityField(targetAddress, (community) => community?.roles);
|
||||
const { isCommentAuthorMod, isAccountMod, isAccountCommentAuthor, commentAuthorRole, accountAuthorRole } = useMemo(() => {
|
||||
const commentAuthorRole = roles?.[commentAuthorAddress]?.role;
|
||||
const isCommentAuthorMod = commentAuthorRole === 'admin' || commentAuthorRole === 'owner' || commentAuthorRole === 'moderator';
|
||||
|
||||
Reference in New Issue
Block a user