enable editing comments published in anon mode

This commit is contained in:
Tom (plebeius.eth)
2024-09-03 22:06:07 +02:00
parent 0018df7f8a
commit 14f3f04137
3 changed files with 92 additions and 48 deletions
+18 -5
View File
@@ -1,4 +1,6 @@
import { useMemo } from 'react';
import { useAccount, useSubplebbit } from '@plebbit/plebbit-react-hooks';
import useAnonModeStore from '../stores/use-anon-mode-store';
interface AuthorPrivilegesProps {
commentAuthorAddress: string;
@@ -8,12 +10,23 @@ interface AuthorPrivilegesProps {
const useAuthorPrivileges = ({ commentAuthorAddress, subplebbitAddress }: AuthorPrivilegesProps) => {
const accountAuthorAddress = useAccount()?.author?.address;
const { roles } = useSubplebbit({ subplebbitAddress }) || {};
const { getAddressSigner } = useAnonModeStore();
const commentAuthorRole = roles?.[commentAuthorAddress]?.role;
const isCommentAuthorMod = commentAuthorRole === 'admin' || commentAuthorRole === 'owner' || commentAuthorRole === 'moderator';
const accountAuthorRole = roles?.[accountAuthorAddress]?.role;
const isAccountMod = accountAuthorRole === 'admin' || accountAuthorRole === 'owner' || accountAuthorRole === 'moderator';
const isAccountCommentAuthor = accountAuthorAddress === commentAuthorAddress;
const { isCommentAuthorMod, isAccountMod, isAccountCommentAuthor, commentAuthorRole, accountAuthorRole } = useMemo(() => {
const commentAuthorRole = roles?.[commentAuthorAddress]?.role;
const isCommentAuthorMod = commentAuthorRole === 'admin' || commentAuthorRole === 'owner' || commentAuthorRole === 'moderator';
const accountAuthorRole = roles?.[accountAuthorAddress]?.role;
const isAccountMod = accountAuthorRole === 'admin' || accountAuthorRole === 'owner' || accountAuthorRole === 'moderator';
let isAccountCommentAuthor = accountAuthorAddress === commentAuthorAddress;
if (!isAccountCommentAuthor) {
const existingSigner = getAddressSigner(commentAuthorAddress);
isAccountCommentAuthor = !!existingSigner;
}
return { isCommentAuthorMod, isAccountMod, isAccountCommentAuthor, commentAuthorRole, accountAuthorRole };
}, [roles, commentAuthorAddress, accountAuthorAddress, getAddressSigner]);
return { isCommentAuthorMod, isAccountMod, isAccountCommentAuthor, commentAuthorRole, accountAuthorRole };
};