mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
refactor: remove broken anon mode feature
- delete the anon mode hook/store and stop wiring publish flows through alternate signers - strip the settings UI, avatar warning, reply indicators, and FAQ text that referenced the toggle - drop the anon mode translation keys via scripts/update-translations.js
This commit is contained in:
@@ -14,9 +14,7 @@ import { alertChallengeVerificationFailed } from '../../lib/utils/challenge-util
|
||||
import useChallengesStore from '../../stores/use-challenges-store';
|
||||
import _ from 'lodash';
|
||||
import useIsMobile from '../../hooks/use-is-mobile';
|
||||
import useAnonMode from '../../hooks/use-anon-mode';
|
||||
import useAuthorPrivileges from '../../hooks/use-author-privileges';
|
||||
import useAnonModeStore from '../../stores/use-anon-mode-store';
|
||||
|
||||
const { addChallenge } = useChallengesStore.getState();
|
||||
|
||||
@@ -39,9 +37,6 @@ const EditMenu = ({ post }: { post: Comment }) => {
|
||||
const [isContentEditorOpen, setIsContentEditorOpen] = useState(false);
|
||||
|
||||
const account = useAccount();
|
||||
const { getNewSigner, getExistingSigner } = useAnonMode(post?.postCid);
|
||||
const { getThreadSigner } = useAnonModeStore();
|
||||
|
||||
const [signer, setSigner] = useState<any>(account?.signer);
|
||||
|
||||
const { isCommentAuthorMod, isAccountMod, isAccountCommentAuthor } = useAuthorPrivileges({
|
||||
@@ -50,35 +45,13 @@ const EditMenu = ({ post }: { post: Comment }) => {
|
||||
postCid,
|
||||
});
|
||||
|
||||
const checkSigner = useCallback(async () => {
|
||||
const checkSigner = useCallback(() => {
|
||||
if (isAccountCommentAuthor) {
|
||||
if (author?.address !== account?.author?.address) {
|
||||
// Check for existing thread signer first
|
||||
const threadSigner = getThreadSigner(postCid);
|
||||
if (threadSigner && threadSigner?.address === author?.address) {
|
||||
setSigner(threadSigner);
|
||||
return;
|
||||
}
|
||||
|
||||
// If no thread signer, check for existing address signer
|
||||
const existingSigner = getExistingSigner(author?.address);
|
||||
if (existingSigner) {
|
||||
setSigner(existingSigner);
|
||||
return;
|
||||
}
|
||||
|
||||
// If no existing signer, create a new one
|
||||
const newSigner = await getNewSigner();
|
||||
if (newSigner) {
|
||||
setSigner(newSigner);
|
||||
}
|
||||
} else {
|
||||
setSigner(account?.signer);
|
||||
}
|
||||
setSigner(account?.signer);
|
||||
} else {
|
||||
setSigner(null);
|
||||
}
|
||||
}, [isAccountCommentAuthor, author?.address, postCid, account?.author?.address, account?.signer, getThreadSigner, getExistingSigner, getNewSigner]);
|
||||
}, [isAccountCommentAuthor, account?.signer]);
|
||||
|
||||
useEffect(() => {
|
||||
checkSigner();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useLocation, useNavigate, useParams } from 'react-router-dom';
|
||||
import { Comment, setAccount, useAccount, useAccountComment, useAccountSubplebbits, useEditedComment } from '@plebbit/plebbit-react-hooks';
|
||||
@@ -9,7 +9,6 @@ import { getHasThumbnail, getLinkMediaInfo } from '../../lib/utils/media-utils';
|
||||
import { formatMarkdown } from '../../lib/utils/post-utils';
|
||||
import { isValidURL } from '../../lib/utils/url-utils';
|
||||
import { isAllView, isDescriptionView, isModView, isPostPageView, isRulesView, isSubscriptionsView } from '../../lib/utils/view-utils';
|
||||
import useAnonMode from '../../hooks/use-anon-mode';
|
||||
import { useDefaultSubplebbits } from '../../hooks/use-default-subplebbits';
|
||||
import { useResolvedSubplebbitAddress } from '../../hooks/use-resolved-subplebbit-address';
|
||||
import useFetchGifFirstFrame from '../../hooks/use-fetch-gif-first-frame';
|
||||
@@ -64,10 +63,6 @@ const PostFormTable = ({ closeForm, postCid }: { closeForm: () => void; postCid:
|
||||
const { accountSubplebbits } = useAccountSubplebbits();
|
||||
const accountSubplebbitAddresses = Object.keys(accountSubplebbits);
|
||||
|
||||
const { anonMode, getNewSigner, getExistingSigner } = useAnonMode(postCid);
|
||||
const comment = useSubplebbitsPagesStore((state) => state.comments[postCid]);
|
||||
const address = comment?.author?.address;
|
||||
|
||||
const [lengthError, setLengthError] = useState<string | null>(null);
|
||||
|
||||
const checkContentLength = useRef(
|
||||
@@ -93,27 +88,6 @@ const PostFormTable = ({ closeForm, postCid }: { closeForm: () => void; postCid:
|
||||
}
|
||||
};
|
||||
|
||||
const getAnonAddressForPost = useCallback(async () => {
|
||||
if (anonMode) {
|
||||
const newSigner = (await getNewSigner()) || {};
|
||||
setPublishPostOptions({
|
||||
signer: newSigner,
|
||||
author: {
|
||||
address: newSigner.address,
|
||||
displayName: displayName || undefined,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
setPublishPostOptions({
|
||||
signer: undefined,
|
||||
author: {
|
||||
address: account?.author?.address,
|
||||
displayName: displayName || undefined,
|
||||
},
|
||||
});
|
||||
}
|
||||
}, [anonMode, getNewSigner, account, setPublishPostOptions, displayName]);
|
||||
|
||||
const onPublishPost = () => {
|
||||
const currentTitle = subjectRef.current?.value.trim() || '';
|
||||
const currentContent = textRef.current?.value.trim() || '';
|
||||
@@ -166,57 +140,11 @@ const PostFormTable = ({ closeForm, postCid }: { closeForm: () => void; postCid:
|
||||
}
|
||||
}, [postIndex, resetPublishPostOptions, navigate]);
|
||||
|
||||
useEffect(() => {
|
||||
if (anonMode) {
|
||||
setPublishPostOptions({
|
||||
signer: undefined,
|
||||
author: {
|
||||
address: undefined,
|
||||
displayName: displayName || undefined,
|
||||
},
|
||||
});
|
||||
getAnonAddressForPost();
|
||||
} else {
|
||||
setPublishPostOptions({
|
||||
signer: undefined,
|
||||
author: {
|
||||
...account?.author,
|
||||
displayName: displayName || account?.author?.displayName,
|
||||
},
|
||||
});
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [anonMode]);
|
||||
|
||||
// in post page, publish a reply to the post
|
||||
const isInPostView = isPostPageView(location.pathname, params);
|
||||
const cid = params?.commentCid as string;
|
||||
const { setPublishReplyOptions, resetPublishReplyOptions, replyIndex, publishReply } = usePublishReply({ cid, subplebbitAddress });
|
||||
|
||||
const getAnonAddressForReply = useCallback(async () => {
|
||||
const existingSigner = await getExistingSigner(address);
|
||||
if (existingSigner) {
|
||||
setPublishReplyOptions({
|
||||
signer: existingSigner,
|
||||
author: {
|
||||
address: existingSigner.address,
|
||||
displayName: displayName || undefined,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
const newSigner = await getNewSigner();
|
||||
if (newSigner) {
|
||||
setPublishReplyOptions({
|
||||
signer: newSigner,
|
||||
author: {
|
||||
address: newSigner.address,
|
||||
displayName: displayName || undefined,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}, [address, getExistingSigner, getNewSigner, setPublishReplyOptions, displayName]);
|
||||
|
||||
const handleContentChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||
const formattedContent = formatMarkdown(e.target.value);
|
||||
isInPostView ? setPublishReplyOptions({ content: formattedContent }) : setPublishPostOptions({ content: formattedContent });
|
||||
@@ -256,17 +184,6 @@ const PostFormTable = ({ closeForm, postCid }: { closeForm: () => void; postCid:
|
||||
}
|
||||
}, [replyIndex, resetPublishReplyOptions, closeForm]);
|
||||
|
||||
useEffect(() => {
|
||||
if (anonMode) {
|
||||
if (isInPostView) {
|
||||
getAnonAddressForReply();
|
||||
} else {
|
||||
getAnonAddressForPost();
|
||||
}
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [anonMode, isInPostView]);
|
||||
|
||||
// on android, auto upload file to image hosting sites with open api
|
||||
const [isUploading, setIsUploading] = useState(false);
|
||||
const [uploadedFileName, setUploadedFileName] = useState<string | null>(null);
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useLocation, useParams } from 'react-router-dom';
|
||||
import { Trans, useTranslation } from 'react-i18next';
|
||||
import { setAccount, useAccount } from '@plebbit/plebbit-react-hooks';
|
||||
import useSubplebbitsStore from '@plebbit/plebbit-react-hooks/dist/stores/subplebbits';
|
||||
import useSubplebbitsPagesStore from '@plebbit/plebbit-react-hooks/dist/stores/subplebbits-pages';
|
||||
import Plebbit from '@plebbit/plebbit-js';
|
||||
import { formatMarkdown } from '../../lib/utils/post-utils';
|
||||
import { getFormattedTimeAgo } from '../../lib/utils/time-utils';
|
||||
@@ -15,7 +14,6 @@ import useIsMobile from '../../hooks/use-is-mobile';
|
||||
import styles from './reply-modal.module.css';
|
||||
import { LinkTypePreviewer } from '../post-form';
|
||||
import _ from 'lodash';
|
||||
import useAnonMode from '../../hooks/use-anon-mode';
|
||||
import FileUploader from '../../plugins/file-uploader';
|
||||
import { Capacitor } from '@capacitor/core';
|
||||
import { useSpring, animated } from '@react-spring/web';
|
||||
@@ -46,34 +44,6 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, postCid, scrollY, s
|
||||
const urlRef = useRef<HTMLInputElement>(null);
|
||||
const { selectedText } = useSelectedTextStore();
|
||||
|
||||
const { anonMode, getNewSigner, getExistingSigner } = useAnonMode(postCid);
|
||||
const comment = useSubplebbitsPagesStore((state) => state.comments[postCid]);
|
||||
const address = comment?.author?.address;
|
||||
|
||||
const getAnonAddressForReply = useCallback(async () => {
|
||||
const existingSigner = await getExistingSigner(address);
|
||||
if (existingSigner) {
|
||||
setPublishReplyOptions({
|
||||
signer: existingSigner,
|
||||
author: {
|
||||
address: existingSigner.address,
|
||||
displayName: displayName || undefined,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
const newSigner = await getNewSigner();
|
||||
if (newSigner) {
|
||||
setPublishReplyOptions({
|
||||
signer: newSigner,
|
||||
author: {
|
||||
address: newSigner.address,
|
||||
displayName: displayName || undefined,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}, [address, getExistingSigner, getNewSigner, setPublishReplyOptions, displayName]);
|
||||
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [lengthError, setLengthError] = useState<string | null>(null);
|
||||
|
||||
@@ -115,28 +85,6 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, postCid, scrollY, s
|
||||
publishReply();
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (anonMode) {
|
||||
setPublishReplyOptions({
|
||||
signer: undefined,
|
||||
author: {
|
||||
address: undefined,
|
||||
displayName: displayName || undefined,
|
||||
},
|
||||
});
|
||||
getAnonAddressForReply();
|
||||
} else {
|
||||
setPublishReplyOptions({
|
||||
signer: undefined,
|
||||
author: {
|
||||
...account?.author,
|
||||
displayName: displayName || account?.author?.displayName,
|
||||
},
|
||||
});
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [anonMode]);
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof replyIndex === 'number') {
|
||||
resetPublishReplyOptions();
|
||||
|
||||
@@ -5,7 +5,6 @@ import { Comment, useAccount } from '@plebbit/plebbit-react-hooks';
|
||||
import { useFloating, offset, shift, size, autoUpdate, Placement } from '@floating-ui/react';
|
||||
import { useDefaultSubplebbits } from '../../hooks/use-default-subplebbits';
|
||||
import { getBoardPath } from '../../lib/utils/route-utils';
|
||||
import useAnonModeStore from '../../stores/use-anon-mode-store';
|
||||
import useIsMobile from '../../hooks/use-is-mobile';
|
||||
import styles from '../../views/post/post.module.css';
|
||||
import { Post } from '../../views/post';
|
||||
@@ -159,8 +158,6 @@ const DesktopQuotePreview = ({ backlinkReply, quotelinkReply, isBacklinkReply, i
|
||||
);
|
||||
|
||||
const account = useAccount();
|
||||
const { getThreadSigner } = useAnonModeStore();
|
||||
const threadSigner = quotelinkReply?.postCid ? getThreadSigner(quotelinkReply?.postCid) : null;
|
||||
|
||||
const quotelinkBoardPath = quotelinkReply?.subplebbitAddress ? getBoardPath(quotelinkReply.subplebbitAddress, defaultSubplebbits) : undefined;
|
||||
const quotelinkRoute = quotelinkReply?.cid ? (quotelinkBoardPath ? `/${quotelinkBoardPath}/thread/${quotelinkReply.cid}` : `/thread/${quotelinkReply.cid}`) : '#';
|
||||
@@ -176,7 +173,7 @@ const DesktopQuotePreview = ({ backlinkReply, quotelinkReply, isBacklinkReply, i
|
||||
onClick={(e) => handleClick(e, quotelinkReply?.cid, quotelinkReply?.subplebbitAddress)}
|
||||
>
|
||||
{quotelinkReply?.shortCid && `>>${quotelinkReply?.shortCid}`}
|
||||
{(quotelinkReply?.author?.address === account?.author?.address || quotelinkReply?.author?.address === threadSigner?.address) && ' (You)'}
|
||||
{quotelinkReply?.author?.address === account?.author?.address && ' (You)'}
|
||||
</Link>
|
||||
<br />
|
||||
{hoveredCid === quotelinkReply?.cid &&
|
||||
@@ -279,8 +276,6 @@ const MobileQuotePreview = ({ backlinkReply, quotelinkReply, isBacklinkReply, is
|
||||
);
|
||||
|
||||
const account = useAccount();
|
||||
const { getThreadSigner } = useAnonModeStore();
|
||||
const threadSigner = quotelinkReply?.postCid ? getThreadSigner(quotelinkReply?.postCid) : null;
|
||||
|
||||
const replyQuotelink = (
|
||||
<>
|
||||
@@ -291,7 +286,7 @@ const MobileQuotePreview = ({ backlinkReply, quotelinkReply, isBacklinkReply, is
|
||||
onMouseLeave={() => handleMouseLeave(quotelinkReply?.cid)}
|
||||
>
|
||||
{quotelinkReply?.shortCid && `>>${quotelinkReply?.shortCid}`}
|
||||
{(quotelinkReply?.author?.address === account?.author?.address || quotelinkReply?.author?.address === threadSigner?.address) && ' (You)'}
|
||||
{quotelinkReply?.author?.address === account?.author?.address && ' (You)'}
|
||||
</span>
|
||||
{quotelinkReply?.shortCid &&
|
||||
(() => {
|
||||
|
||||
@@ -54,15 +54,3 @@
|
||||
margin: 2px 0 10px 0;
|
||||
padding-left: 19px;
|
||||
}
|
||||
|
||||
.anonMode {
|
||||
padding: 10px 0;
|
||||
}
|
||||
|
||||
.anonMode label {
|
||||
text-transform: capitalize;
|
||||
}
|
||||
|
||||
.anonMode input[type="checkbox"] {
|
||||
margin-right: 3px;
|
||||
}
|
||||
@@ -3,27 +3,11 @@ import { useTranslation } from 'react-i18next';
|
||||
import { createAccount, deleteAccount, exportAccount, importAccount, setAccount, setActiveAccount, useAccount, useAccounts } from '@plebbit/plebbit-react-hooks';
|
||||
import stringify from 'json-stringify-pretty-compact';
|
||||
import styles from './account-settings.module.css';
|
||||
import useAnonModeStore from '../../../stores/use-anon-mode-store';
|
||||
import { Capacitor } from '@capacitor/core';
|
||||
import { useLocation, useNavigate } from 'react-router-dom';
|
||||
|
||||
const isAndroid = Capacitor.getPlatform() === 'android';
|
||||
|
||||
const AnonMode = () => {
|
||||
const { t } = useTranslation();
|
||||
const anonMode = useAnonModeStore((state) => state.anonMode);
|
||||
const setAnonMode = useAnonModeStore((state) => state.setAnonMode);
|
||||
|
||||
return (
|
||||
<div className={styles.anonMode}>
|
||||
<label>
|
||||
<input type='checkbox' checked={anonMode} onChange={(e) => setAnonMode(e.target.checked)} /> {t('anon_mode')}
|
||||
</label>
|
||||
<span className={styles.settingTip}>{t('anon_mode_description')}</span>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const AccountSettings = () => {
|
||||
const { t } = useTranslation();
|
||||
const location = useLocation();
|
||||
@@ -236,7 +220,7 @@ const AccountSettings = () => {
|
||||
<div></div>
|
||||
<textarea value={text} onChange={(e) => setText(e.target.value)} autoCorrect='off' autoComplete='off' spellCheck='false' />
|
||||
<div>
|
||||
<button onClick={saveAccount}>{t('save_changes')}</button> <button onClick={() => setText(accountJson)}>{t('reset_changes')}</button> <AnonMode />
|
||||
<button onClick={saveAccount}>{t('save_changes')}</button> <button onClick={() => setText(accountJson)}>{t('reset_changes')}</button>
|
||||
<button className={styles.deleteAccount} onClick={() => _deleteAccount(account?.name)}>
|
||||
{t('delete_account')}
|
||||
</button>
|
||||
|
||||
@@ -11,12 +11,6 @@
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.warning {
|
||||
font-size: 0.8em;
|
||||
padding: 0 10px 10px 10px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.avatar img {
|
||||
width: 64px;
|
||||
height: 64px;
|
||||
|
||||
@@ -4,7 +4,6 @@ import { setAccount, useAccount, useAuthorAvatar } from '@plebbit/plebbit-react-
|
||||
import styles from './avatar-settings.module.css';
|
||||
import { Trans, useTranslation } from 'react-i18next';
|
||||
import LoadingEllipsis from '../../loading-ellipsis';
|
||||
import useAnonMode from '../../../hooks/use-anon-mode';
|
||||
|
||||
const AvatarPreview = ({ avatar }: any) => {
|
||||
const { t } = useTranslation();
|
||||
@@ -115,11 +114,8 @@ const AvatarSettings = () => {
|
||||
alert(`saved`);
|
||||
};
|
||||
|
||||
const { anonMode } = useAnonMode();
|
||||
|
||||
return (
|
||||
<div className={styles.avatarSettings}>
|
||||
{anonMode && <span className={styles.warning}>{t('avatar_warning')}</span>}
|
||||
<AvatarPreview avatar={avatar} />
|
||||
<div className={styles.avatarSettingsForm}>
|
||||
<div className={styles.avatarSettingInput}>
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
import { useAccount } from '@plebbit/plebbit-react-hooks';
|
||||
import useAnonModeStore from '../stores/use-anon-mode-store';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
const useAnonMode = (postCid?: string) => {
|
||||
const { anonMode, getThreadSigner, setThreadSigner, setAddressSigner, getAddressSigner } = useAnonModeStore((state) => ({
|
||||
anonMode: state.anonMode,
|
||||
getThreadSigner: state.getThreadSigner,
|
||||
setThreadSigner: state.setThreadSigner,
|
||||
setAddressSigner: state.setAddressSigner,
|
||||
getAddressSigner: state.getAddressSigner,
|
||||
}));
|
||||
|
||||
const account = useAccount();
|
||||
|
||||
const getNewSigner = useCallback(async () => {
|
||||
if (anonMode) {
|
||||
if (postCid) {
|
||||
const existingSigner = getThreadSigner(postCid);
|
||||
if (existingSigner) {
|
||||
return existingSigner;
|
||||
}
|
||||
}
|
||||
try {
|
||||
const signer = await account?.plebbit.createSigner();
|
||||
if (signer) {
|
||||
if (postCid) {
|
||||
setThreadSigner(postCid, signer);
|
||||
} else {
|
||||
setAddressSigner(signer);
|
||||
}
|
||||
}
|
||||
return signer;
|
||||
} catch (error) {
|
||||
console.error('Failed to create anonymous signer:', error);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}, [anonMode, postCid, account, getThreadSigner, setThreadSigner, setAddressSigner]);
|
||||
|
||||
const getExistingSigner = useCallback(
|
||||
(address: string) => {
|
||||
const signer = getAddressSigner(address);
|
||||
return signer;
|
||||
},
|
||||
[getAddressSigner],
|
||||
);
|
||||
|
||||
return { anonMode, getNewSigner, getExistingSigner };
|
||||
};
|
||||
|
||||
export default useAnonMode;
|
||||
@@ -1,8 +1,6 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useAccount } from '@plebbit/plebbit-react-hooks';
|
||||
import useSubplebbitsStore from '@plebbit/plebbit-react-hooks/dist/stores/subplebbits';
|
||||
import useAnonModeStore from '../stores/use-anon-mode-store';
|
||||
import useAnonMode from './use-anon-mode';
|
||||
|
||||
interface AuthorPrivilegesProps {
|
||||
commentAuthorAddress: string;
|
||||
@@ -15,26 +13,16 @@ const useAuthorPrivileges = ({ commentAuthorAddress, subplebbitAddress, postCid
|
||||
const accountAuthorAddress = account?.author?.address;
|
||||
const subplebbit = useSubplebbitsStore((state) => state.subplebbits[subplebbitAddress]);
|
||||
const { roles } = subplebbit || {};
|
||||
const { getAddressSigner, getThreadSigner } = useAnonModeStore();
|
||||
const { anonMode } = useAnonMode(postCid);
|
||||
|
||||
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 = postCid && accountAuthorAddress === commentAuthorAddress;
|
||||
|
||||
if (!isAccountCommentAuthor && anonMode) {
|
||||
const addressSigner = getAddressSigner(commentAuthorAddress);
|
||||
const threadSigner = postCid ? getThreadSigner(postCid) : null;
|
||||
|
||||
isAccountCommentAuthor = (addressSigner && addressSigner.address === commentAuthorAddress) || (threadSigner && threadSigner.address === commentAuthorAddress);
|
||||
}
|
||||
const isAccountCommentAuthor = !!postCid && accountAuthorAddress === commentAuthorAddress;
|
||||
|
||||
return { isCommentAuthorMod, isAccountMod, isAccountCommentAuthor, commentAuthorRole, accountAuthorRole };
|
||||
}, [roles, commentAuthorAddress, accountAuthorAddress, anonMode, getAddressSigner, getThreadSigner, postCid]);
|
||||
}, [roles, commentAuthorAddress, accountAuthorAddress, postCid]);
|
||||
|
||||
return { isCommentAuthorMod, isAccountMod, isAccountCommentAuthor, commentAuthorRole, accountAuthorRole };
|
||||
};
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
import { useCallback } from 'react';
|
||||
import { Comment, useAccount, usePublishComment } from '@plebbit/plebbit-react-hooks';
|
||||
import useAnonMode from './use-anon-mode';
|
||||
import usePublishPostStore from '../stores/use-publish-post-store';
|
||||
|
||||
const usePublishPost = ({ subplebbitAddress }: { subplebbitAddress?: string }) => {
|
||||
const account = useAccount();
|
||||
const { anonMode } = useAnonMode();
|
||||
|
||||
const { author, signer, title, content, link, spoiler, publishCommentOptions } = usePublishPostStore((state) => ({
|
||||
const { author, title, content, link, spoiler, publishCommentOptions } = usePublishPostStore((state) => ({
|
||||
author: state.author,
|
||||
signer: state.signer,
|
||||
title: state.title || undefined,
|
||||
content: state.content || undefined,
|
||||
link: state.link || undefined,
|
||||
@@ -29,21 +26,13 @@ const usePublishPost = ({ subplebbitAddress }: { subplebbitAddress?: string }) =
|
||||
spoiler,
|
||||
};
|
||||
|
||||
if (anonMode) {
|
||||
baseOptions.author = {
|
||||
address: signer?.address,
|
||||
displayName: author?.displayName,
|
||||
};
|
||||
baseOptions.signer = signer;
|
||||
} else {
|
||||
baseOptions.author = {
|
||||
...account?.author,
|
||||
displayName: author?.displayName || account?.author?.displayName,
|
||||
};
|
||||
}
|
||||
baseOptions.author = {
|
||||
...account?.author,
|
||||
displayName: author?.displayName || account?.author?.displayName,
|
||||
};
|
||||
|
||||
return baseOptions;
|
||||
}, [anonMode, author, content, link, signer, spoiler, subplebbitAddress, title, account]);
|
||||
}, [author, content, link, spoiler, subplebbitAddress, title, account]);
|
||||
|
||||
const setPublishPostOptions = useCallback(
|
||||
(options: Partial<Comment>) => {
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
import { useCallback } from 'react';
|
||||
import { Comment, useAccount, usePublishComment } from '@plebbit/plebbit-react-hooks';
|
||||
import useAnonMode from './use-anon-mode';
|
||||
import usePublishReplyStore from '../stores/use-publish-reply-store';
|
||||
|
||||
const usePublishReply = ({ cid, subplebbitAddress, postCid }: { cid: string; subplebbitAddress: string; postCid?: string }) => {
|
||||
const parentCid = cid;
|
||||
const account = useAccount();
|
||||
const { anonMode } = useAnonMode(postCid);
|
||||
|
||||
const { author, signer, content, link, spoiler, publishCommentOptions } = usePublishReplyStore((state) => ({
|
||||
const { author, content, link, spoiler, publishCommentOptions } = usePublishReplyStore((state) => ({
|
||||
author: state.author[parentCid],
|
||||
signer: state.signer[parentCid] || undefined,
|
||||
content: state.content[parentCid] || undefined,
|
||||
link: state.link[parentCid] || undefined,
|
||||
spoiler: state.spoiler[parentCid] || false,
|
||||
@@ -30,21 +27,13 @@ const usePublishReply = ({ cid, subplebbitAddress, postCid }: { cid: string; sub
|
||||
spoiler,
|
||||
};
|
||||
|
||||
if (anonMode) {
|
||||
baseOptions.author = {
|
||||
address: signer?.address,
|
||||
displayName: author?.displayName,
|
||||
};
|
||||
baseOptions.signer = signer;
|
||||
} else {
|
||||
baseOptions.author = {
|
||||
...account?.author,
|
||||
displayName: author?.displayName || account?.author?.displayName,
|
||||
};
|
||||
}
|
||||
baseOptions.author = {
|
||||
...account?.author,
|
||||
displayName: author?.displayName || account?.author?.displayName,
|
||||
};
|
||||
|
||||
return baseOptions;
|
||||
}, [anonMode, author, content, link, parentCid, postCid, signer, spoiler, subplebbitAddress, account]);
|
||||
}, [author, content, link, parentCid, postCid, spoiler, subplebbitAddress, account]);
|
||||
|
||||
const setPublishReplyOptions = useCallback(
|
||||
(options: Partial<Comment>) => {
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
import { create } from 'zustand';
|
||||
import localForageLru from '@plebbit/plebbit-react-hooks/dist/lib/localforage-lru/index.js';
|
||||
|
||||
interface AnonModeState {
|
||||
anonMode: boolean;
|
||||
threadSigners: { [key: string]: any };
|
||||
addressSigners: { [address: string]: any };
|
||||
setAnonMode: (mode: boolean) => void;
|
||||
setThreadSigner: (postCid: string, signer: any) => void;
|
||||
getThreadSigner: (postCid: string) => any | undefined;
|
||||
setAddressSigner: (signer: any) => void;
|
||||
getAddressSigner: (address: string) => any | undefined;
|
||||
}
|
||||
|
||||
const anonModeStore = localForageLru.createInstance({
|
||||
name: 'anonModeStore',
|
||||
size: 1000,
|
||||
});
|
||||
|
||||
const useAnonModeStore = create<AnonModeState>((set, get) => ({
|
||||
anonMode: true,
|
||||
threadSigners: {},
|
||||
addressSigners: {},
|
||||
setAnonMode: (mode: boolean) => {
|
||||
set({ anonMode: mode });
|
||||
anonModeStore.setItem('anonMode', mode);
|
||||
},
|
||||
setThreadSigner: (postCid: string, signer: any) => {
|
||||
set((state) => ({
|
||||
threadSigners: { ...state.threadSigners, [postCid]: signer },
|
||||
}));
|
||||
anonModeStore.setItem(`threadSigner_${postCid}`, signer);
|
||||
},
|
||||
getThreadSigner: (postCid: string) => {
|
||||
const state = get();
|
||||
if (state.threadSigners[postCid]) {
|
||||
return state.threadSigners[postCid];
|
||||
}
|
||||
return null;
|
||||
},
|
||||
setAddressSigner: (signer: any) => {
|
||||
set((state) => ({
|
||||
addressSigners: { ...state.addressSigners, [signer.address]: signer },
|
||||
}));
|
||||
anonModeStore.setItem(`addressSigner_${signer.address}`, signer);
|
||||
},
|
||||
getAddressSigner: (address: string) => {
|
||||
const state = get();
|
||||
if (state.addressSigners[address]) {
|
||||
return state.addressSigners[address];
|
||||
}
|
||||
return null;
|
||||
},
|
||||
}));
|
||||
|
||||
const initializeAnonModeStore = async () => {
|
||||
const entries: [string, any][] = await anonModeStore.entries();
|
||||
const threadSigners: { [key: string]: any } = {};
|
||||
const addressSigners: { [key: string]: any } = {};
|
||||
let anonMode = true;
|
||||
|
||||
entries.forEach(([key, value]) => {
|
||||
if (key === 'anonMode') {
|
||||
anonMode = value;
|
||||
} else if (key.startsWith('threadSigner_')) {
|
||||
const postCid = key.replace('threadSigner_', '');
|
||||
threadSigners[postCid] = value;
|
||||
} else if (key.startsWith('addressSigner_')) {
|
||||
const address = key.replace('addressSigner_', '');
|
||||
addressSigners[address] = value;
|
||||
}
|
||||
});
|
||||
|
||||
useAnonModeStore.setState({
|
||||
anonMode,
|
||||
threadSigners,
|
||||
addressSigners,
|
||||
});
|
||||
};
|
||||
|
||||
initializeAnonModeStore();
|
||||
|
||||
export default useAnonModeStore;
|
||||
@@ -6,7 +6,6 @@ import useChallengesStore from './use-challenges-store';
|
||||
type SubmitState = {
|
||||
author?: any | undefined;
|
||||
displayName?: string | undefined;
|
||||
signer?: any | undefined;
|
||||
subplebbitAddress: string | undefined;
|
||||
title: string | undefined;
|
||||
content: string | undefined;
|
||||
@@ -22,7 +21,6 @@ const { addChallenge } = useChallengesStore.getState();
|
||||
const usePublishPostStore = create<SubmitState>((set) => ({
|
||||
author: undefined,
|
||||
displayName: undefined,
|
||||
signer: undefined,
|
||||
subplebbitAddress: undefined,
|
||||
title: undefined,
|
||||
content: undefined,
|
||||
@@ -31,7 +29,7 @@ const usePublishPostStore = create<SubmitState>((set) => ({
|
||||
publishCommentOptions: {},
|
||||
setPublishPostStore: (comment: Comment) =>
|
||||
set(() => {
|
||||
const { subplebbitAddress, author, content, link, signer, spoiler, title } = comment;
|
||||
const { subplebbitAddress, author, content, link, spoiler, title } = comment;
|
||||
|
||||
const displayName = 'displayName' in comment ? comment.displayName || undefined : author?.displayName;
|
||||
|
||||
@@ -60,14 +58,9 @@ const usePublishPostStore = create<SubmitState>((set) => ({
|
||||
publishCommentOptions.author = updatedAuthor;
|
||||
}
|
||||
|
||||
if (signer) {
|
||||
publishCommentOptions.signer = signer;
|
||||
}
|
||||
|
||||
return {
|
||||
author: updatedAuthor,
|
||||
displayName,
|
||||
signer,
|
||||
subplebbitAddress,
|
||||
title,
|
||||
content,
|
||||
@@ -80,7 +73,6 @@ const usePublishPostStore = create<SubmitState>((set) => ({
|
||||
set({
|
||||
author: undefined,
|
||||
displayName: undefined,
|
||||
signer: undefined,
|
||||
subplebbitAddress: undefined,
|
||||
title: undefined,
|
||||
content: undefined,
|
||||
|
||||
@@ -8,7 +8,6 @@ type ReplyState = {
|
||||
displayName: { [parentCid: string]: string | undefined };
|
||||
content: { [parentCid: string]: string | undefined };
|
||||
link: { [parentCid: string]: string | undefined };
|
||||
signer: { [parentCid: string]: any | undefined };
|
||||
spoiler: { [parentCid: string]: boolean | undefined };
|
||||
publishCommentOptions: { [parentCid: string]: PublishCommentOptions | undefined };
|
||||
setPublishReplyStore: (comment: Comment) => void;
|
||||
@@ -22,13 +21,12 @@ const usePublishReplyStore = create<ReplyState>((set) => ({
|
||||
displayName: {},
|
||||
content: {},
|
||||
link: {},
|
||||
signer: {},
|
||||
spoiler: {},
|
||||
publishCommentOptions: {},
|
||||
|
||||
setPublishReplyStore: (comment: Comment) =>
|
||||
set((state) => {
|
||||
const { subplebbitAddress, parentCid, author, content, link, signer, spoiler } = comment;
|
||||
const { subplebbitAddress, parentCid, author, content, link, spoiler } = comment;
|
||||
|
||||
const displayName = 'displayName' in comment ? comment.displayName || undefined : author?.displayName;
|
||||
|
||||
@@ -58,16 +56,11 @@ const usePublishReplyStore = create<ReplyState>((set) => ({
|
||||
publishCommentOptions.author = updatedAuthor;
|
||||
}
|
||||
|
||||
if (signer) {
|
||||
publishCommentOptions.signer = signer;
|
||||
}
|
||||
|
||||
return {
|
||||
author: { ...state.author, [parentCid]: updatedAuthor },
|
||||
displayName: { ...state.displayName, [parentCid]: displayName },
|
||||
content: { ...state.content, [parentCid]: content },
|
||||
link: { ...state.link, [parentCid]: link },
|
||||
signer: { ...state.signer, [parentCid]: signer },
|
||||
spoiler: { ...state.spoiler, [parentCid]: spoiler },
|
||||
publishCommentOptions: { ...state.publishCommentOptions, [parentCid]: publishCommentOptions },
|
||||
};
|
||||
@@ -79,7 +72,6 @@ const usePublishReplyStore = create<ReplyState>((set) => ({
|
||||
displayName: { ...state.displayName, [parentCid]: undefined },
|
||||
content: { ...state.content, [parentCid]: undefined },
|
||||
link: { ...state.link, [parentCid]: undefined },
|
||||
signer: { ...state.signer, [parentCid]: undefined },
|
||||
spoiler: { ...state.spoiler, [parentCid]: undefined },
|
||||
publishCommentOptions: { ...state.publishCommentOptions, [parentCid]: undefined },
|
||||
})),
|
||||
|
||||
@@ -117,8 +117,8 @@ const FAQ = () => {
|
||||
address with it.
|
||||
<br />
|
||||
<br />
|
||||
By default, Anon Mode is enabled in the settings, which automatically generates and enables a new username per thread you visit. These anon mode
|
||||
usernames stem from the currently active account file, which you can backup.
|
||||
You can also edit the display name associated with your account at any time in the settings or directly in the post form. The name you choose will be
|
||||
reused across threads until you change it again.
|
||||
</dd>
|
||||
<dt id='howimage'>How do I post an image?</dt>
|
||||
<dd>
|
||||
|
||||
Reference in New Issue
Block a user