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:
plebeius
2025-11-25 13:13:38 +01:00
parent f6cf6ec4eb
commit f037a669c0
51 changed files with 26 additions and 521 deletions
+3 -30
View File
@@ -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 -84
View File
@@ -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 -53
View File
@@ -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}>