mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix anon mode replymodal logic
This commit is contained in:
@@ -32,9 +32,11 @@ import handleQuoteClick from '../../utils/handleQuoteClick';
|
|||||||
import handleQuoteHover from '../../utils/handleQuoteHover';
|
import handleQuoteHover from '../../utils/handleQuoteHover';
|
||||||
import handleStyleChange from '../../utils/handleStyleChange';
|
import handleStyleChange from '../../utils/handleStyleChange';
|
||||||
import removeHighlight from '../../utils/removeHighlight';
|
import removeHighlight from '../../utils/removeHighlight';
|
||||||
|
import useAnonModeRef from '../../hooks/useAnonModeRef';
|
||||||
import useError from '../../hooks/useError';
|
import useError from '../../hooks/useError';
|
||||||
import useFeedStateString from '../../hooks/useFeedStateString';
|
import useFeedStateString from '../../hooks/useFeedStateString';
|
||||||
import useSuccess from '../../hooks/useSuccess';
|
import useSuccess from '../../hooks/useSuccess';
|
||||||
|
import useAnonModeStore from '../../hooks/stores/useAnonModeStore';
|
||||||
import useGeneralStore from '../../hooks/stores/useGeneralStore';
|
import useGeneralStore from '../../hooks/stores/useGeneralStore';
|
||||||
import packageJson from '../../../package.json'
|
import packageJson from '../../../package.json'
|
||||||
const {version} = packageJson
|
const {version} = packageJson
|
||||||
@@ -62,6 +64,7 @@ const All = () => {
|
|||||||
setSelectedTitle,
|
setSelectedTitle,
|
||||||
} = useGeneralStore(state => state);
|
} = useGeneralStore(state => state);
|
||||||
|
|
||||||
|
const { anonymousMode } = useAnonModeStore();
|
||||||
|
|
||||||
const account = useAccount();
|
const account = useAccount();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -76,6 +79,7 @@ const All = () => {
|
|||||||
const backlinkRefsMobile = useRef({});
|
const backlinkRefsMobile = useRef({});
|
||||||
const quoteRefsMobile = useRef({});
|
const quoteRefsMobile = useRef({});
|
||||||
const postOnHoverRef = useRef(null);
|
const postOnHoverRef = useRef(null);
|
||||||
|
const selectedThreadCidRef = useRef(null);
|
||||||
|
|
||||||
const [isReplyOpen, setIsReplyOpen] = useState(false);
|
const [isReplyOpen, setIsReplyOpen] = useState(false);
|
||||||
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
|
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
|
||||||
@@ -92,6 +96,13 @@ const All = () => {
|
|||||||
const [postOnHoverHeight, setPostOnHoverHeight] = useState(0);
|
const [postOnHoverHeight, setPostOnHoverHeight] = useState(0);
|
||||||
const [deletePost, setDeletePost] = useState(false);
|
const [deletePost, setDeletePost] = useState(false);
|
||||||
const [moderatorPermissions, setModeratorPermissions] = useState({});
|
const [moderatorPermissions, setModeratorPermissions] = useState({});
|
||||||
|
const [executeAnonMode, setExecuteAnonMode] = useState(false);
|
||||||
|
|
||||||
|
const setSelectedThreadCid = (cid) => {
|
||||||
|
selectedThreadCidRef.current = cid;
|
||||||
|
}
|
||||||
|
|
||||||
|
useAnonModeRef(selectedThreadCidRef, anonymousMode && executeAnonMode);
|
||||||
|
|
||||||
const addresses = defaultSubplebbits.map(subplebbit => subplebbit.address);
|
const addresses = defaultSubplebbits.map(subplebbit => subplebbit.address);
|
||||||
const { feed, hasMore, loadMore } = useFeed({subplebbitAddresses: addresses, sortType: 'active'});
|
const { feed, hasMore, loadMore } = useFeed({subplebbitAddresses: addresses, sortType: 'active'});
|
||||||
@@ -303,6 +314,14 @@ const All = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (anonymousMode) {
|
||||||
|
setExecuteAnonMode(true);
|
||||||
|
}
|
||||||
|
}, [anonymousMode, selectedThreadCidRef]);
|
||||||
|
|
||||||
|
|
||||||
const [publishCommentEditOptions, setPublishCommentEditOptions] = useState({
|
const [publishCommentEditOptions, setPublishCommentEditOptions] = useState({
|
||||||
commentCid: commentCid,
|
commentCid: commentCid,
|
||||||
content: editedComment || undefined,
|
content: editedComment || undefined,
|
||||||
@@ -668,6 +687,7 @@ const All = () => {
|
|||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
if (e.button === 2) return;
|
if (e.button === 2) return;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
setSelectedThreadCid(thread.cid);
|
||||||
setIsReplyOpen(true);
|
setIsReplyOpen(true);
|
||||||
setSelectedShortCid(thread.shortCid);
|
setSelectedShortCid(thread.shortCid);
|
||||||
setSelectedParentCid(thread.cid);
|
setSelectedParentCid(thread.cid);
|
||||||
@@ -947,6 +967,7 @@ const All = () => {
|
|||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
if (e.button === 2) return;
|
if (e.button === 2) return;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
setSelectedThreadCid(thread.cid);
|
||||||
setIsReplyOpen(true);
|
setIsReplyOpen(true);
|
||||||
setSelectedShortCid(reply.shortCid);
|
setSelectedShortCid(reply.shortCid);
|
||||||
setSelectedParentCid(reply.cid);
|
setSelectedParentCid(reply.cid);
|
||||||
@@ -1380,6 +1401,7 @@ const All = () => {
|
|||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
if (e.button === 2) return;
|
if (e.button === 2) return;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
setSelectedThreadCid(thread.cid);
|
||||||
setIsReplyOpen(true);
|
setIsReplyOpen(true);
|
||||||
setSelectedShortCid(thread.shortCid);
|
setSelectedShortCid(thread.shortCid);
|
||||||
setSelectedParentCid(thread.cid);
|
setSelectedParentCid(thread.cid);
|
||||||
@@ -1552,6 +1574,7 @@ const All = () => {
|
|||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
if (e.button === 2) return;
|
if (e.button === 2) return;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
setSelectedThreadCid(thread.cid);
|
||||||
setIsReplyOpen(true);
|
setIsReplyOpen(true);
|
||||||
setSelectedShortCid(reply.shortCid);
|
setSelectedShortCid(reply.shortCid);
|
||||||
setSelectedParentCid(reply.cid);
|
setSelectedParentCid(reply.cid);
|
||||||
|
|||||||
@@ -32,10 +32,12 @@ import handleQuoteClick from '../../utils/handleQuoteClick';
|
|||||||
import handleQuoteHover from '../../utils/handleQuoteHover';
|
import handleQuoteHover from '../../utils/handleQuoteHover';
|
||||||
import handleStyleChange from '../../utils/handleStyleChange';
|
import handleStyleChange from '../../utils/handleStyleChange';
|
||||||
import removeHighlight from '../../utils/removeHighlight';
|
import removeHighlight from '../../utils/removeHighlight';
|
||||||
|
import useAnonModeRef from '../../hooks/useAnonModeRef';
|
||||||
import useClickForm from '../../hooks/useClickForm';
|
import useClickForm from '../../hooks/useClickForm';
|
||||||
import useError from '../../hooks/useError';
|
import useError from '../../hooks/useError';
|
||||||
import useStateString from '../../hooks/useStateString';
|
import useStateString from '../../hooks/useStateString';
|
||||||
import useSuccess from '../../hooks/useSuccess';
|
import useSuccess from '../../hooks/useSuccess';
|
||||||
|
import useAnonModeStore from '../../hooks/stores/useAnonModeStore';
|
||||||
import useGeneralStore from '../../hooks/stores/useGeneralStore';
|
import useGeneralStore from '../../hooks/stores/useGeneralStore';
|
||||||
import packageJson from '../../../package.json'
|
import packageJson from '../../../package.json'
|
||||||
const {version} = packageJson
|
const {version} = packageJson
|
||||||
@@ -65,7 +67,8 @@ const Board = () => {
|
|||||||
showPostForm,
|
showPostForm,
|
||||||
showPostFormLink,
|
showPostFormLink,
|
||||||
} = useGeneralStore(state => state);
|
} = useGeneralStore(state => state);
|
||||||
|
|
||||||
|
const { anonymousMode } = useAnonModeStore();
|
||||||
|
|
||||||
const account = useAccount();
|
const account = useAccount();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -86,6 +89,7 @@ const Board = () => {
|
|||||||
const backlinkRefsMobile = useRef({});
|
const backlinkRefsMobile = useRef({});
|
||||||
const quoteRefsMobile = useRef({});
|
const quoteRefsMobile = useRef({});
|
||||||
const postOnHoverRef = useRef(null);
|
const postOnHoverRef = useRef(null);
|
||||||
|
const selectedThreadCidRef = useRef(null);
|
||||||
|
|
||||||
const { feed, hasMore, loadMore } = useFeed({subplebbitAddresses: [`${selectedAddress}`], sortType: 'active'});
|
const { feed, hasMore, loadMore } = useFeed({subplebbitAddresses: [`${selectedAddress}`], sortType: 'active'});
|
||||||
const subplebbit = useSubplebbit({subplebbitAddress: selectedAddress});
|
const subplebbit = useSubplebbit({subplebbitAddress: selectedAddress});
|
||||||
@@ -109,6 +113,13 @@ const Board = () => {
|
|||||||
const [outOfViewCid, setOutOfViewCid] = useState(null);
|
const [outOfViewCid, setOutOfViewCid] = useState(null);
|
||||||
const [outOfViewPosition, setOutOfViewPosition] = useState({top: 0, left: 0});
|
const [outOfViewPosition, setOutOfViewPosition] = useState({top: 0, left: 0});
|
||||||
const [postOnHoverHeight, setPostOnHoverHeight] = useState(0);
|
const [postOnHoverHeight, setPostOnHoverHeight] = useState(0);
|
||||||
|
const [executeAnonMode, setExecuteAnonMode] = useState(false);
|
||||||
|
|
||||||
|
const setSelectedThreadCid = (cid) => {
|
||||||
|
selectedThreadCidRef.current = cid;
|
||||||
|
}
|
||||||
|
|
||||||
|
useAnonModeRef(selectedThreadCidRef, anonymousMode && executeAnonMode);
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -351,9 +362,17 @@ const Board = () => {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
setTriggerPublishComment(true);
|
setTriggerPublishComment(true);
|
||||||
|
setExecuteAnonMode(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (anonymousMode) {
|
||||||
|
setExecuteAnonMode(true);
|
||||||
|
}
|
||||||
|
}, [anonymousMode, selectedThreadCidRef]);
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (publishCommentOptions && triggerPublishComment) {
|
if (publishCommentOptions && triggerPublishComment) {
|
||||||
(async () => {
|
(async () => {
|
||||||
@@ -1115,6 +1134,7 @@ const Board = () => {
|
|||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
if (e.button === 2) return;
|
if (e.button === 2) return;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
setSelectedThreadCid(thread.cid);
|
||||||
setIsReplyOpen(true);
|
setIsReplyOpen(true);
|
||||||
setSelectedShortCid(thread.shortCid);
|
setSelectedShortCid(thread.shortCid);
|
||||||
setSelectedParentCid(thread.cid);
|
setSelectedParentCid(thread.cid);
|
||||||
@@ -1392,6 +1412,7 @@ const Board = () => {
|
|||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
if (e.button === 2) return;
|
if (e.button === 2) return;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
setSelectedThreadCid(thread.cid);
|
||||||
setIsReplyOpen(true);
|
setIsReplyOpen(true);
|
||||||
setSelectedShortCid(reply.shortCid);
|
setSelectedShortCid(reply.shortCid);
|
||||||
setSelectedParentCid(reply.cid);
|
setSelectedParentCid(reply.cid);
|
||||||
@@ -1796,6 +1817,7 @@ const Board = () => {
|
|||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
if (e.button === 2) return;
|
if (e.button === 2) return;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
setSelectedThreadCid(thread.cid);
|
||||||
setIsReplyOpen(true);
|
setIsReplyOpen(true);
|
||||||
setSelectedShortCid(thread.shortCid);
|
setSelectedShortCid(thread.shortCid);
|
||||||
setSelectedParentCid(thread.cid);
|
setSelectedParentCid(thread.cid);
|
||||||
@@ -1946,6 +1968,7 @@ const Board = () => {
|
|||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
if (e.button === 2) return;
|
if (e.button === 2) return;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
setSelectedThreadCid(thread.cid);
|
||||||
setIsReplyOpen(true);
|
setIsReplyOpen(true);
|
||||||
setSelectedShortCid(reply.shortCid);
|
setSelectedShortCid(reply.shortCid);
|
||||||
setSelectedParentCid(reply.cid);
|
setSelectedParentCid(reply.cid);
|
||||||
|
|||||||
@@ -33,9 +33,11 @@ import handleQuoteClick from '../../utils/handleQuoteClick';
|
|||||||
import handleQuoteHover from '../../utils/handleQuoteHover';
|
import handleQuoteHover from '../../utils/handleQuoteHover';
|
||||||
import handleStyleChange from '../../utils/handleStyleChange';
|
import handleStyleChange from '../../utils/handleStyleChange';
|
||||||
import removeHighlight from '../../utils/removeHighlight';
|
import removeHighlight from '../../utils/removeHighlight';
|
||||||
|
import useAnonModeRef from '../../hooks/useAnonModeRef';
|
||||||
import useError from '../../hooks/useError';
|
import useError from '../../hooks/useError';
|
||||||
import useFeedStateString from '../../hooks/useFeedStateString';
|
import useFeedStateString from '../../hooks/useFeedStateString';
|
||||||
import useSuccess from '../../hooks/useSuccess';
|
import useSuccess from '../../hooks/useSuccess';
|
||||||
|
import useAnonModeStore from '../../hooks/stores/useAnonModeStore';
|
||||||
import packageJson from '../../../package.json'
|
import packageJson from '../../../package.json'
|
||||||
const {version} = packageJson
|
const {version} = packageJson
|
||||||
|
|
||||||
@@ -62,6 +64,8 @@ const Subscriptions = () => {
|
|||||||
setSelectedTitle,
|
setSelectedTitle,
|
||||||
} = useGeneralStore(state => state);
|
} = useGeneralStore(state => state);
|
||||||
|
|
||||||
|
const { anonymousMode } = useAnonModeStore();
|
||||||
|
|
||||||
const account = useAccount();
|
const account = useAccount();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [, setNewErrorMessage] = useError();
|
const [, setNewErrorMessage] = useError();
|
||||||
@@ -75,6 +79,7 @@ const Subscriptions = () => {
|
|||||||
const backlinkRefsMobile = useRef({});
|
const backlinkRefsMobile = useRef({});
|
||||||
const quoteRefsMobile = useRef({});
|
const quoteRefsMobile = useRef({});
|
||||||
const postOnHoverRef = useRef(null);
|
const postOnHoverRef = useRef(null);
|
||||||
|
const selectedThreadCidRef = useRef(null);
|
||||||
|
|
||||||
const [isReplyOpen, setIsReplyOpen] = useState(false);
|
const [isReplyOpen, setIsReplyOpen] = useState(false);
|
||||||
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
|
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
|
||||||
@@ -91,6 +96,13 @@ const Subscriptions = () => {
|
|||||||
const [postOnHoverHeight, setPostOnHoverHeight] = useState(0);
|
const [postOnHoverHeight, setPostOnHoverHeight] = useState(0);
|
||||||
const [deletePost, setDeletePost] = useState(false);
|
const [deletePost, setDeletePost] = useState(false);
|
||||||
const [moderatorPermissions, setModeratorPermissions] = useState({});
|
const [moderatorPermissions, setModeratorPermissions] = useState({});
|
||||||
|
const [executeAnonMode, setExecuteAnonMode] = useState(false);
|
||||||
|
|
||||||
|
const setSelectedThreadCid = (cid) => {
|
||||||
|
selectedThreadCidRef.current = cid;
|
||||||
|
}
|
||||||
|
|
||||||
|
useAnonModeRef(selectedThreadCidRef, anonymousMode && executeAnonMode);
|
||||||
|
|
||||||
const { feed, hasMore, loadMore } = useFeed({subplebbitAddresses: account?.subscriptions, sortType: 'active'});
|
const { feed, hasMore, loadMore } = useFeed({subplebbitAddresses: account?.subscriptions, sortType: 'active'});
|
||||||
const [selectedFeed, setSelectedFeed] = useState(feed.sort((a, b) => b.timestamp - a.timestamp));
|
const [selectedFeed, setSelectedFeed] = useState(feed.sort((a, b) => b.timestamp - a.timestamp));
|
||||||
@@ -316,6 +328,13 @@ const Subscriptions = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (anonymousMode) {
|
||||||
|
setExecuteAnonMode(true);
|
||||||
|
}
|
||||||
|
}, [anonymousMode, selectedThreadCidRef]);
|
||||||
|
|
||||||
|
|
||||||
const { publishCommentEdit } = usePublishCommentEdit(publishCommentEditOptions);
|
const { publishCommentEdit } = usePublishCommentEdit(publishCommentEditOptions);
|
||||||
|
|
||||||
|
|
||||||
@@ -678,6 +697,7 @@ const Subscriptions = () => {
|
|||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
if (e.button === 2) return;
|
if (e.button === 2) return;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
setSelectedThreadCid(thread.cid);
|
||||||
setIsReplyOpen(true);
|
setIsReplyOpen(true);
|
||||||
setSelectedShortCid(thread.shortCid);
|
setSelectedShortCid(thread.shortCid);
|
||||||
setSelectedParentCid(thread.cid);
|
setSelectedParentCid(thread.cid);
|
||||||
@@ -957,6 +977,7 @@ const Subscriptions = () => {
|
|||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
if (e.button === 2) return;
|
if (e.button === 2) return;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
setSelectedThreadCid(thread.cid);
|
||||||
setIsReplyOpen(true);
|
setIsReplyOpen(true);
|
||||||
setSelectedShortCid(reply.shortCid);
|
setSelectedShortCid(reply.shortCid);
|
||||||
setSelectedParentCid(reply.cid);
|
setSelectedParentCid(reply.cid);
|
||||||
@@ -1390,6 +1411,7 @@ const Subscriptions = () => {
|
|||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
if (e.button === 2) return;
|
if (e.button === 2) return;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
setSelectedThreadCid(thread.cid);
|
||||||
setIsReplyOpen(true);
|
setIsReplyOpen(true);
|
||||||
setSelectedShortCid(thread.shortCid);
|
setSelectedShortCid(thread.shortCid);
|
||||||
setSelectedParentCid(thread.cid);
|
setSelectedParentCid(thread.cid);
|
||||||
@@ -1562,6 +1584,7 @@ const Subscriptions = () => {
|
|||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
if (e.button === 2) return;
|
if (e.button === 2) return;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
setSelectedThreadCid(thread.cid);
|
||||||
setIsReplyOpen(true);
|
setIsReplyOpen(true);
|
||||||
setSelectedShortCid(reply.shortCid);
|
setSelectedShortCid(reply.shortCid);
|
||||||
setSelectedParentCid(reply.cid);
|
setSelectedParentCid(reply.cid);
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import { useEffect } from "react";
|
||||||
|
import { createAccount, setActiveAccount, useAccounts } from "@plebbit/plebbit-react-hooks";
|
||||||
|
import useAnonModeStore from "./stores/useAnonModeStore";
|
||||||
|
|
||||||
|
const useAnonModeRef = (threadCidRef, execute) => {
|
||||||
|
const {accounts} = useAccounts();
|
||||||
|
const { anonymousMode } = useAnonModeStore();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleAnonMode = async () => {
|
||||||
|
let storedAccounts = JSON.parse(localStorage.getItem('storedAccounts')) || {};
|
||||||
|
|
||||||
|
if (!anonymousMode) return;
|
||||||
|
|
||||||
|
if (!storedAccounts[threadCidRef.current] && execute) {
|
||||||
|
await createAccount();
|
||||||
|
const lastAccount = accounts[accounts.length - 1];
|
||||||
|
await setActiveAccount(lastAccount.name);
|
||||||
|
storedAccounts[threadCidRef.current] = lastAccount.name;
|
||||||
|
|
||||||
|
localStorage.setItem('storedAccounts', JSON.stringify(storedAccounts));
|
||||||
|
} else {
|
||||||
|
await setActiveAccount(storedAccounts[threadCidRef.current]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleAnonMode();
|
||||||
|
}, [threadCidRef, execute, accounts, anonymousMode]);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
export default useAnonModeRef;
|
||||||
Reference in New Issue
Block a user