mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
enable editing comments published in anon mode
This commit is contained in:
+14
-10
@@ -1,5 +1,6 @@
|
||||
import { useAccount } from '@plebbit/plebbit-react-hooks';
|
||||
import useAnonModeStore from '../stores/use-anon-mode-store';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
|
||||
const useAnonMode = (postCid?: string) => {
|
||||
const { anonMode, threadSigners, setThreadSigner, setAddressSigner, getAddressSigner, setCurrentAnonSignerAddress } = useAnonModeStore((state) => ({
|
||||
@@ -11,11 +12,11 @@ const useAnonMode = (postCid?: string) => {
|
||||
setCurrentAnonSignerAddress: state.setCurrentAnonSignerAddress,
|
||||
}));
|
||||
|
||||
const threadSigner = postCid ? threadSigners[postCid] : undefined;
|
||||
const threadSigner = useMemo(() => (postCid ? threadSigners[postCid] : undefined), [postCid, threadSigners]);
|
||||
|
||||
const account = useAccount();
|
||||
|
||||
const getNewSigner = async () => {
|
||||
const getNewSigner = useCallback(async () => {
|
||||
if (anonMode) {
|
||||
if (!postCid || !threadSigner) {
|
||||
try {
|
||||
@@ -43,15 +44,18 @@ const useAnonMode = (postCid?: string) => {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}, [anonMode, postCid, threadSigner, account, setThreadSigner, setAddressSigner, setCurrentAnonSignerAddress]);
|
||||
|
||||
const getExistingSigner = (address: string) => {
|
||||
const signer = getAddressSigner(address);
|
||||
if (signer) {
|
||||
setCurrentAnonSignerAddress(signer.address);
|
||||
}
|
||||
return signer;
|
||||
};
|
||||
const getExistingSigner = useCallback(
|
||||
(address: string) => {
|
||||
const signer = getAddressSigner(address);
|
||||
if (signer) {
|
||||
setCurrentAnonSignerAddress(signer.address);
|
||||
}
|
||||
return signer;
|
||||
},
|
||||
[getAddressSigner, setCurrentAnonSignerAddress],
|
||||
);
|
||||
|
||||
return { anonMode, getNewSigner, getExistingSigner };
|
||||
};
|
||||
|
||||
@@ -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 };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user