feat: add edit menu on mobile

This commit is contained in:
Tom (plebeius.eth)
2024-06-04 16:06:28 +02:00
parent 304d899ce7
commit 1d8452684b
5 changed files with 48 additions and 18 deletions
+21
View File
@@ -0,0 +1,21 @@
import { useAccount, useSubplebbit } from '@plebbit/plebbit-react-hooks';
interface EditCommentPrivileges {
commentAuthorAddress: string;
subplebbitAddress: string;
}
const useEditCommentPrivileges = ({ commentAuthorAddress, subplebbitAddress }: EditCommentPrivileges) => {
const accountAuthorAddress = useAccount().author?.address;
const { roles } = useSubplebbit({ subplebbitAddress }) || {};
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;
return { isCommentAuthorMod, isAccountMod, isAccountCommentAuthor };
};
export default useEditCommentPrivileges;