- R:
-
{thread.replyCount}
-
{
- threadMenuRefs.current[thread.cid] = el;
- postMenuRef.current = el;
- }}
- className='post-menu-button'
- id='post-menu-button-catalog'
- rotated={openMenuCid === thread.cid}
- onClick={(event) => {
- event.stopPropagation();
- const rect = threadMenuRefs.current[thread.cid].getBoundingClientRect();
- setMenuPosition({top: rect.top + window.scrollY, left: rect.left});
- setOpenMenuCid(prevCid => (prevCid === thread.cid ? null : thread.cid));
- }}
- >
- ▶
-
+
+ {subplebbit.rules ? (
+ setIsHoveringOnThread('rules')}
+ onMouseLeave={() => setIsHoveringOnThread('')}>
+
+
+ R:
0
+
+
+
+
+
{
+ threadMenuRefs.current["rules"] = el;
+ postMenuRef.current = el;
+ }}
+ className='post-menu-button'
+ id='post-menu-button-catalog'
+ rotated={openMenuCid === "rules"}
+ onClick={(event) => {
+ event.stopPropagation();
+ const rect = threadMenuRefs.current["rules"].getBoundingClientRect();
+ setMenuPosition({top: rect.top + window.scrollY, left: rect.left});
+ setOpenMenuCid(prevCid => (prevCid === "rules" ? null : "rules"));
+ }}
+ >
+ ▶
+
{createPortal(
{
style={{position: "absolute",
top: menuPosition.top + 7,
left: menuPosition.left}}>
-
- handleOptionClick(thread.cid)}>Hide thread
- {thread.author.shortAddress === account?.author.shortAddress ? (
+ handleOptionClick("rules")}>Hide thread
+ {/* {isModerator ? (
<>
- handleAuthorEditClick(thread)}>Edit post
- handleAuthorDeleteClick(thread)}>Delete post
+ change rules
>
- ) : null}
- {isModerator ? (
- <>
- {thread.author.shortAddress === account?.author.shortAddress ? (
- null
- ) : (
- {
- setModeratingCommentCid(thread.cid)
- setIsModerationOpen(true);
- handleOptionClick(thread.cid);
- setDeletePost(true);
- }}>
- Delete post
-
- )}
- {
- setModeratingCommentCid(thread.cid)
- setIsModerationOpen(true);
- handleOptionClick(thread.cid);
- }}>
- Mod tools
-
- >
- ) : null}
- {(commentMediaInfo && (
- commentMediaInfo.type === 'image' ||
- (commentMediaInfo.type === 'webpage' &&
- commentMediaInfo.thumbnail))) ? (
- {setIsImageSearchOpen(true)}}
- onMouseLeave={() => {setIsImageSearchOpen(false)}}>
- Image search »
-
- handleOptionClick(thread.cid)}>
- Google
-
- handleOptionClick(thread.cid)}>
- Yandex
-
- handleOptionClick(thread.cid)}>
- SauceNAO
-
-
-
- ) : null
- }
+ ) : null} */}
, document.body
)}
-
setSelectedThread(thread.cid)}>
-
- {thread.title ? `${thread.title}` : null}
- {thread.content ? `: ${thread.content}` : null}
-
-
+
{}}
+ onClick={() => setSelectedThread("rules")}>
+
+ Rules
+ {": " + subplebbit.rules.map((rule, index) => `${index + 1}. ${rule}`).join(' ')}
+
+
- )})}
-
+ ) : null}
+ {subplebbit.description ? (
+
setIsHoveringOnThread('description')}
+ onMouseLeave={() => setIsHoveringOnThread('')}>
+
{}}>
+ {subplebbit.suggested?.avatarUrl ? (
+
+ ) : null}
+
+ {subplebbit.suggested?.avatarUrl ? (
+
+
+
+
+ ) : null}
+
+
+ R:
0
+ {subplebbit.suggested?.avatarUrl ? null : (
+
+
+
+
+ )}
+
{
+ threadMenuRefs.current["description"] = el;
+ postMenuRef.current = el;
+ }}
+ className='post-menu-button'
+ id='post-menu-button-catalog'
+ rotated={openMenuCid === "description"}
+ onClick={(event) => {
+ event.stopPropagation();
+ const rect = threadMenuRefs.current["description"].getBoundingClientRect();
+ setMenuPosition({top: rect.top + window.scrollY, left: rect.left});
+ setOpenMenuCid(prevCid => (prevCid === "description" ? null : "description"));
+ }}
+ >
+ ▶
+
+
+ {createPortal(
+ {postMenuCatalogRef.current = el}}
+ onClick={(event) => event.stopPropagation()}
+ style={{position: "absolute",
+ top: menuPosition.top + 7,
+ left: menuPosition.left}}>
+
+
+ handleOptionClick("description")}>Hide thread
+ {/* {isModerator ? (
+ <>
+ change description
+ >
+ ) : null} */}
+ {subplebbit.suggested?.avatarUrl ? (
+ {setIsImageSearchOpen(true)}}
+ onMouseLeave={() => {setIsImageSearchOpen(false)}}>
+ Image search »
+
+ handleOptionClick("description")}>
+ Google
+
+ handleOptionClick("description")}>
+ Yandex
+
+ handleOptionClick("description")}>
+ SauceNAO
+
+
+
+ ) : null}
+
+
+ , document.body
+ )}
+
+
{}}
+ onClick={() => setSelectedThread("description")}>
+
+ Welcome to {subplebbit.title || subplebbit.address}
+ {": " + subplebbit.description}
+
+
+
+ ) : null}
+ {feed.map((thread, index) => {
+ const commentMediaInfo = getCommentMediaInfo(thread);
+ const fallbackImgUrl = "assets/filedeleted-res.gif";
+ return (
+
{setIsHoveringOnThread(thread.cid)}}
+ onMouseLeave={() => {setIsHoveringOnThread('')}}>
+ {commentMediaInfo?.url ? (
+
setSelectedThread(thread.cid)}>
+ {commentMediaInfo?.type === "webpage" ? (
+ thread.thumbnailUrl ? (
+
{
+ e.target.src = fallbackImgUrl
+ e.target.onerror = null;
+ }} />
+ ) : null
+ ) : null}
+ {commentMediaInfo?.type === "image" ? (
+
{
+ e.target.src = fallbackImgUrl
+ e.target.onerror = null;}} />
+ ) : null}
+ {commentMediaInfo?.type === "video" ? (
+
e.target.src = fallbackImgUrl} />
+ ) : null}
+ {commentMediaInfo?.type === "audio" ? (
+ e.target.src = fallbackImgUrl} />
+ ) : null}
+
+ ) : null}
+ {(commentMediaInfo && (
+ commentMediaInfo.type === 'image' ||
+ commentMediaInfo.type === 'video' ||
+ (commentMediaInfo.type === 'webpage' &&
+ commentMediaInfo.thumbnail))) ? (
+
+ {thread.pinned ? (
+
+ ) : null}
+ {thread.locked ? (
+
+ ) : null}
+
+ ) : null}
+
+
+ R:
+
{thread.replyCount}
+ {(commentMediaInfo && (
+ commentMediaInfo.type === 'image' ||
+ commentMediaInfo.type === 'video' ||
+ (commentMediaInfo.type === 'webpage' &&
+ commentMediaInfo.thumbnail))) ? null : (
+
+ {thread.pinned ? (
+
+ ) : null}
+ {thread.locked ? (
+
+ ) : null}
+
+ )}
+
{
+ threadMenuRefs.current[thread.cid] = el;
+ postMenuRef.current = el;
+ }}
+ className='post-menu-button'
+ id='post-menu-button-catalog'
+ rotated={openMenuCid === thread.cid}
+ onClick={(event) => {
+ event.stopPropagation();
+ const rect = threadMenuRefs.current[thread.cid].getBoundingClientRect();
+ setMenuPosition({top: rect.top + window.scrollY, left: rect.left});
+ setOpenMenuCid(prevCid => (prevCid === thread.cid ? null : thread.cid));
+ }}
+ >
+ ▶
+
+
+ {createPortal(
+ {postMenuCatalogRef.current = el}}
+ onClick={(event) => event.stopPropagation()}
+ style={{position: "absolute",
+ top: menuPosition.top + 7,
+ left: menuPosition.left}}>
+
+
+ handleOptionClick(thread.cid)}>Hide thread
+ {thread.author.shortAddress === account?.author.shortAddress ? (
+ <>
+ handleAuthorEditClick(thread)}>Edit post
+ handleAuthorDeleteClick(thread)}>Delete post
+ >
+ ) : null}
+ {isModerator ? (
+ <>
+ {thread.author.shortAddress === account?.author.shortAddress ? (
+ null
+ ) : (
+ {
+ setModeratingCommentCid(thread.cid)
+ setIsModerationOpen(true);
+ handleOptionClick(thread.cid);
+ setDeletePost(true);
+ }}>
+ Delete post
+
+ )}
+ {
+ setModeratingCommentCid(thread.cid)
+ setIsModerationOpen(true);
+ handleOptionClick(thread.cid);
+ }}>
+ Mod tools
+
+ >
+ ) : null}
+ {(commentMediaInfo && (
+ commentMediaInfo.type === 'image' ||
+ (commentMediaInfo.type === 'webpage' &&
+ commentMediaInfo.thumbnail))) ? (
+ {setIsImageSearchOpen(true)}}
+ onMouseLeave={() => {setIsImageSearchOpen(false)}}>
+ Image search »
+
+ handleOptionClick(thread.cid)}>
+ Google
+
+ handleOptionClick(thread.cid)}>
+ Yandex
+
+ handleOptionClick(thread.cid)}>
+ SauceNAO
+
+
+
+ ) : null
+ }
+
+
+ , document.body
+ )}
+
+ setSelectedThread(thread.cid)}>
+
+ {thread.title ? `${thread.title}` : null}
+ {thread.content ? `: ${thread.content}` : null}
+
+
+
+ )})}
+
) : (
)
)}
diff --git a/src/components/views/Home.jsx b/src/components/views/Home.jsx
index ea97bb7d..ebd24ad3 100644
--- a/src/components/views/Home.jsx
+++ b/src/components/views/Home.jsx
@@ -1,11 +1,11 @@
import React, { Fragment, useEffect, useRef } from 'react';
import { Helmet } from 'react-helmet-async';
import { useAccount } from '@plebbit/plebbit-react-hooks';
-import useGeneralStore from '../../hooks/stores/useGeneralStore';
import { Link, useNavigate } from 'react-router-dom';
import { Container, Header, Logo, Page, Search, About, AboutTitle, AboutContent, Boards, BoardsTitle, BoardsContent, Footer } from '../styled/views/Home.styled';
import BoardAvatar from '../BoardAvatar';
import OfflineIndicator from '../OfflineIndicator';
+import useGeneralStore from '../../hooks/stores/useGeneralStore';
import packageJson from '../../../package.json'
import { Tooltip } from 'react-tooltip';
const {version} = packageJson
@@ -14,7 +14,7 @@ const commitRef = process?.env?.REACT_APP_COMMIT_REF ? ` ${process.env.REACT_APP
const Home = () => {
- const {
+ const {
bodyStyle, setBodyStyle,
defaultSubplebbits,
setSelectedAddress,
diff --git a/src/components/views/Subscriptions.jsx b/src/components/views/Subscriptions.jsx
index 67d8d88a..0559edcc 100755
--- a/src/components/views/Subscriptions.jsx
+++ b/src/components/views/Subscriptions.jsx
@@ -33,9 +33,11 @@ import handleQuoteClick from '../../utils/handleQuoteClick';
import handleQuoteHover from '../../utils/handleQuoteHover';
import handleStyleChange from '../../utils/handleStyleChange';
import removeHighlight from '../../utils/removeHighlight';
+import useAnonModeRef from '../../hooks/useAnonModeRef';
import useError from '../../hooks/useError';
import useFeedStateString from '../../hooks/useFeedStateString';
import useSuccess from '../../hooks/useSuccess';
+import useAnonModeStore from '../../hooks/stores/useAnonModeStore';
import packageJson from '../../../package.json'
const {version} = packageJson
@@ -62,6 +64,8 @@ const Subscriptions = () => {
setSelectedTitle,
} = useGeneralStore(state => state);
+ const { anonymousMode } = useAnonModeStore();
+
const account = useAccount();
const navigate = useNavigate();
const [, setNewErrorMessage] = useError();
@@ -75,6 +79,7 @@ const Subscriptions = () => {
const backlinkRefsMobile = useRef({});
const quoteRefsMobile = useRef({});
const postOnHoverRef = useRef(null);
+ const selectedThreadCidRef = useRef(null);
const [isReplyOpen, setIsReplyOpen] = useState(false);
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
@@ -91,6 +96,13 @@ const Subscriptions = () => {
const [postOnHoverHeight, setPostOnHoverHeight] = useState(0);
const [deletePost, setDeletePost] = useState(false);
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 [selectedFeed, setSelectedFeed] = useState(feed.sort((a, b) => b.timestamp - a.timestamp));
@@ -316,11 +328,18 @@ const Subscriptions = () => {
});
+ useEffect(() => {
+ if (anonymousMode) {
+ setExecuteAnonMode(true);
+ }
+ }, [anonymousMode, selectedThreadCidRef]);
+
+
const { publishCommentEdit } = usePublishCommentEdit(publishCommentEditOptions);
- const handleAuthorDeleteClick = (comment) => {
- handleOptionClick(comment.cid);
+ const handleAuthorDeleteClick = (cid) => {
+ handleOptionClick(cid);
confirmAlert({
customUI: ({ onClose }) => {
@@ -334,7 +353,7 @@ const Subscriptions = () => {
onClick={() => {
setIsAuthorDelete(true);
setIsAuthorEdit(false);
- setCommentCid(comment.cid);
+ setCommentCid(cid);
setPublishCommentEditOptions(prevOptions => ({
...prevOptions,
deleted: true,
@@ -678,7 +697,8 @@ const Subscriptions = () => {
onClick={(e) => {
if (e.button === 2) return;
e.preventDefault();
- setIsReplyOpen(true);
+ setSelectedThreadCid(thread.cid);
+ setIsReplyOpen(true);
setSelectedShortCid(thread.shortCid);
setSelectedParentCid(thread.cid);
setSelectedAddress(thread.subplebbitAddress);
@@ -736,7 +756,7 @@ const Subscriptions = () => {
{thread.author.shortAddress === account?.author.shortAddress ? (
<>
{handleAuthorEditClick(thread); setSelectedAddress(thread.subplebbitAddress);}}>Edit post
-
{handleAuthorDeleteClick(thread); setSelectedAddress(thread.subplebbitAddress);}}>Delete post
+
{handleAuthorDeleteClick(thread.cid); setSelectedAddress(thread.subplebbitAddress);}}>Delete post
>
) : null}
{isModerator ? (
@@ -957,7 +977,8 @@ const Subscriptions = () => {
onClick={(e) => {
if (e.button === 2) return;
e.preventDefault();
- setIsReplyOpen(true);
+ setSelectedThreadCid(thread.cid);
+ setIsReplyOpen(true);
setSelectedShortCid(reply.shortCid);
setSelectedParentCid(reply.cid);
setSelectedAddress(thread.subplebbitAddress);
@@ -1015,7 +1036,7 @@ const Subscriptions = () => {
{reply.author.shortAddress === account?.author.shortAddress ? (
<>
{handleAuthorEditClick(reply); setSelectedAddress(thread.subplebbitAddress);}}>Edit post
-
{handleAuthorDeleteClick(reply); setSelectedAddress(thread.subplebbitAddress);}}>Delete post
+
{handleAuthorDeleteClick(reply.cid); setSelectedAddress(thread.subplebbitAddress);}}>Delete post
>
) : null}
{isModerator ? (
@@ -1390,7 +1411,8 @@ const Subscriptions = () => {
onClick={(e) => {
if (e.button === 2) return;
e.preventDefault();
- setIsReplyOpen(true);
+ setSelectedThreadCid(thread.cid);
+ setIsReplyOpen(true);
setSelectedShortCid(thread.shortCid);
setSelectedParentCid(thread.cid);
setSelectedAddress(thread.subplebbitAddress);
@@ -1562,7 +1584,8 @@ const Subscriptions = () => {
onClick={(e) => {
if (e.button === 2) return;
e.preventDefault();
- setIsReplyOpen(true);
+ setSelectedThreadCid(thread.cid);
+ setIsReplyOpen(true);
setSelectedShortCid(reply.shortCid);
setSelectedParentCid(reply.cid);
setSelectedAddress(thread.subplebbitAddress);
diff --git a/src/components/views/Thread.jsx b/src/components/views/Thread.jsx
index 464cf057..a95de4c8 100755
--- a/src/components/views/Thread.jsx
+++ b/src/components/views/Thread.jsx
@@ -7,7 +7,6 @@ import { Tooltip } from 'react-tooltip';
import { useAccount, useAccountComments, useComment, usePublishComment, usePublishCommentEdit, useSubplebbit } from '@plebbit/plebbit-react-hooks';
import { flattenCommentsPages } from '@plebbit/plebbit-react-hooks/dist/lib/utils'
import { debounce } from 'lodash';
-import useGeneralStore from '../../hooks/stores/useGeneralStore';
import { Container, NavBar, Header, Break, PostForm, PostFormTable, PostMenu } from '../styled/views/Board.styled';
import { ReplyFormLink, TopBar, BottomBar, BoardForm, Footer, AuthorDeleteAlert } from '../styled/views/Thread.styled';
import { PostMenuCatalog } from '../styled/views/Catalog.styled';
@@ -32,11 +31,14 @@ import handleQuoteClick from '../../utils/handleQuoteClick';
import handleQuoteHover from '../../utils/handleQuoteHover';
import handleStyleChange from '../../utils/handleStyleChange';
import removeHighlight from '../../utils/removeHighlight';
+import useAnonMode from '../../hooks/useAnonMode';
import useClickForm from '../../hooks/useClickForm';
import useError from '../../hooks/useError';
import useStateString from '../../hooks/useStateString';
-import packageJson from '../../../package.json'
import useSuccess from '../../hooks/useSuccess';
+import useAnonModeStore from '../../hooks/stores/useAnonModeStore';
+import useGeneralStore from '../../hooks/stores/useGeneralStore';
+import packageJson from '../../../package.json'
const {version} = packageJson
@@ -65,6 +67,8 @@ const Thread = () => {
showPostFormLink,
} = useGeneralStore(state => state);
+ const { anonymousMode } = useAnonModeStore();
+
const account = useAccount();
const navigate = useNavigate();
const handleClickForm = useClickForm();
@@ -82,6 +86,8 @@ const Thread = () => {
const backlinkRefs = useRef({});
const quoteRefs = useRef({});
const postOnHoverRef = useRef(null);
+ const backlinkRefsMobile = useRef({});
+ const quoteRefsMobile = useRef({});
const [triggerPublishComment, setTriggerPublishComment] = useState(false);
const [triggerPublishCommentEdit, setTriggerPublishCommentEdit] = useState(false);
@@ -99,9 +105,9 @@ const Thread = () => {
const [outOfViewCid, setOutOfViewCid] = useState(null);
const [outOfViewPosition, setOutOfViewPosition] = useState({top: 0, left: 0});
const [postOnHoverHeight, setPostOnHoverHeight] = useState(0);
- const backlinkRefsMobile = useRef({});
- const quoteRefsMobile = useRef({});
-
+ const [executeAnonMode, setExecuteAnonMode] = useState(false);
+
+ useAnonMode(selectedThread, anonymousMode && executeAnonMode);
const comment = useComment({commentCid: selectedThread});
const { subplebbitAddress, threadCid } = useParams();
@@ -323,7 +329,15 @@ const Thread = () => {
}));
setTriggerPublishComment(true);
+ setExecuteAnonMode(false);
};
+
+
+ useEffect(() => {
+ if (anonymousMode) {
+ setExecuteAnonMode(true);
+ }
+ }, [anonymousMode, selectedThread]);
useEffect(() => {
@@ -387,8 +401,8 @@ const Thread = () => {
const { publishCommentEdit } = usePublishCommentEdit(publishCommentEditOptions);
- const handleAuthorDeleteClick = (comment) => {
- handleOptionClick(comment.cid);
+ const handleAuthorDeleteClick = (cid) => {
+ handleOptionClick(cid);
confirmAlert({
customUI: ({ onClose }) => {
@@ -402,7 +416,7 @@ const Thread = () => {
onClick={() => {
setIsAuthorDelete(true);
setIsAuthorEdit(false);
- setCommentCid(comment.cid);
+ setCommentCid(cid);
setPublishCommentEditOptions(prevOptions => ({
...prevOptions,
deleted: true,
@@ -518,7 +532,7 @@ const Thread = () => {
[
All
- /
+ /
Subscriptions
] [
{defaultSubplebbits.map((subplebbit, index) => (
@@ -865,7 +879,7 @@ const Thread = () => {
{comment.author?.shortAddress === account?.author.shortAddress ? (
<>
handleAuthorEditClick(comment)}>Edit post
- handleAuthorDeleteClick(comment)}>Delete post
+ handleAuthorDeleteClick(comment.cid)}>Delete post
>
) : null}
{isModerator ? (
@@ -1088,7 +1102,7 @@ const Thread = () => {
{reply.author.shortAddress === account?.author.shortAddress ? (
<>
handleAuthorEditClick(reply)}>Edit post
- handleAuthorDeleteClick(reply)}>Delete post
+ handleAuthorDeleteClick(reply.cid)}>Delete post
>
) : null}
{isModerator ? (
diff --git a/src/hooks/stores/useAnonModeStore.js b/src/hooks/stores/useAnonModeStore.js
new file mode 100644
index 00000000..bf70c388
--- /dev/null
+++ b/src/hooks/stores/useAnonModeStore.js
@@ -0,0 +1,15 @@
+import { create } from 'zustand';
+import { persist } from 'zustand/middleware';
+
+const useAnonModeStore = create(persist(
+ (set) => ({
+ anonymousMode: true,
+ setAnonymousMode: (mode) => set({ anonymousMode: mode }),
+ }),
+ {
+ name: "anonmode_store",
+ getStorage: () => localStorage,
+ }
+));
+
+export default useAnonModeStore;
\ No newline at end of file
diff --git a/src/hooks/stores/useGeneralStore.js b/src/hooks/stores/useGeneralStore.js
index 9c5489f0..100f092d 100644
--- a/src/hooks/stores/useGeneralStore.js
+++ b/src/hooks/stores/useGeneralStore.js
@@ -1,9 +1,6 @@
import { create } from 'zustand';
const useGeneralStore = create((set) => ({
- anonymousMode: true,
- setAnonymousMode: (mode) => set({ anonymousMode: mode }),
-
bodyStyle: JSON.parse(localStorage.getItem('bodyStyle')) || {
background: '#ffe url(assets/fade.png) top repeat-x',
color: 'maroon',
diff --git a/src/hooks/useAnonMode.js b/src/hooks/useAnonMode.js
new file mode 100644
index 00000000..309775f2
--- /dev/null
+++ b/src/hooks/useAnonMode.js
@@ -0,0 +1,32 @@
+import { useEffect } from "react";
+import { createAccount, setActiveAccount, useAccounts } from "@plebbit/plebbit-react-hooks";
+import useAnonModeStore from "./stores/useAnonModeStore";
+
+const useAnonMode = (threadCid, execute) => {
+ const {accounts} = useAccounts();
+ const { anonymousMode } = useAnonModeStore();
+
+ useEffect(() => {
+ const handleAnonMode = async () => {
+ let storedAccounts = JSON.parse(localStorage.getItem('storedAccounts')) || {};
+
+ if (!anonymousMode) return;
+
+ if (!storedAccounts[threadCid] && execute) {
+ await createAccount();
+ const lastAccount = accounts[accounts.length - 1];
+ await setActiveAccount(lastAccount.name);
+ storedAccounts[threadCid] = lastAccount.name;
+
+ localStorage.setItem('storedAccounts', JSON.stringify(storedAccounts));
+ } else {
+ await setActiveAccount(storedAccounts[threadCid]);
+ }
+ }
+
+ handleAnonMode();
+ }, [threadCid, execute, accounts, anonymousMode]);
+
+ return;
+}
+export default useAnonMode;
\ No newline at end of file
diff --git a/src/hooks/useAnonModeRef.js b/src/hooks/useAnonModeRef.js
new file mode 100644
index 00000000..ed6b12a2
--- /dev/null
+++ b/src/hooks/useAnonModeRef.js
@@ -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;
\ No newline at end of file
diff --git a/yarn.lock b/yarn.lock
index 40c8bb04..f301b99c 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -7,6 +7,7 @@
resolved "https://registry.yarnpkg.com/7zip-bin/-/7zip-bin-5.1.1.tgz#9274ec7460652f9c632c59addf24efb1684ef876"
integrity sha512-sAP4LldeWNz0lNzmTird3uWfFDWWTeg6V/MsmyyLR9X1idwKBWIgt/ZvinqQldJm3LecKEs1emkbquO6PCiLVQ==
+
"@adraffy/ens-normalize@1.8.3", "@adraffy/ens-normalize@1.9.0", "@adraffy/ens-normalize@1.9.2":
version "1.8.3"
resolved "https://registry.yarnpkg.com/@adraffy/ens-normalize/-/ens-normalize-1.8.3.tgz#6084dd00eac37a99bcf91a3a3249cc737cbcb005"
@@ -2591,11 +2592,12 @@
resolved "https://registry.yarnpkg.com/@noble/ed25519/-/ed25519-1.7.3.tgz#57e1677bf6885354b466c38e2b620c62f45a7123"
integrity sha512-iR8GBkDt0Q3GyaVcIu7mSsVIqnFbkbRzGLWlvhwunacoLwt4J3swfKhfaM6rN6WY+TBGoYT1GtT1mIh2/jGbRQ==
+
"@noble/hashes@1.1.2":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.1.2.tgz#e9e035b9b166ca0af657a7848eb2718f0f22f183"
integrity sha512-KYRCASVTv6aeUi1tsF8/vpyR7zpfs3FUzy2Jqm+MU+LmUKhQ0y2FpfwqkCcxSg2ua4GALJd8k2R76WxwZGbQpA==
-
+
"@noble/hashes@1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.0.tgz#085fd70f6d7d9d109671090ccae1d3bec62554a1"
@@ -2606,6 +2608,7 @@
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.1.tgz#8831ef002114670c603c458ab8b11328406953a9"
integrity sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA==
+
"@noble/secp256k1@1.7.1", "@noble/secp256k1@^1.3.0":
version "1.7.1"
resolved "https://registry.yarnpkg.com/@noble/secp256k1/-/secp256k1-1.7.1.tgz#b251c70f824ce3ca7f8dc3df08d58f005cc0507c"
@@ -2648,7 +2651,53 @@
mkdirp "^1.0.4"
rimraf "^3.0.2"
+
"@plebbit/plebbit-js@https://github.com/plebbit/plebbit-js.git#574d1730da725a6266da6d69f2fa01f027dadb96":
+ version "0.0.3"
+ resolved "https://github.com/plebbit/plebbit-js.git#220c709566d8b680e7dc13722f4e81c8d0f13b3b"
+ dependencies:
+ "@adraffy/ens-normalize" "1.9.2"
+ "@keyv/sqlite" "3.6.2"
+ "@plebbit/plebbit-logger" "github:plebbit/plebbit-logger"
+ "@types/node-fetch" "2.6.2"
+ "@types/proper-lockfile" "4.1.2"
+ "@types/uuid" "8.3.4"
+ assert "2.0.0"
+ async-wait-until "2.0.12"
+ buffer "6.0.3"
+ captcha-canvas "3.2.1"
+ err-code "3.0.1"
+ file-type "16.5.4"
+ form-data "4.0.0"
+ hpagent "1.2.0"
+ ipfs-http-client "56.0.3"
+ ipfs-only-hash "4.0.0"
+ is-ipfs "6.0.2"
+ jose "4.11.0"
+ js-sha256 "0.9.0"
+ keyv "4.5.2"
+ knex "2.4.2"
+ libp2p-crypto "0.21.2"
+ limiter "2.1.0"
+ localforage "1.10.0"
+ lodash-es "4.17.21"
+ lru-cache "7.18.3"
+ open-graph-scraper "5.2.3"
+ p-limit "3.1.0"
+ peer-id "0.16.0"
+ proper-lockfile "github:plebbit/node-proper-lockfile"
+ retry "0.13.1"
+ safe-stable-stringify "2.4.1"
+ sha1-uint8array "0.10.3"
+ skia-canvas "1.0.0"
+ sqlite3 "5.1.6"
+ tiny-typed-emitter "2.1.0"
+ tinycache "1.1.2"
+ ts-custom-error "3.3.1"
+ uuid "9.0.0"
+ viem "1.0.7"
+
+"@plebbit/plebbit-js@https://github.com/plebbit/plebbit-js.git#27df54b8c591c9245deb91e131d15de2bc8bf4d3":
version "0.0.3"
resolved "https://github.com/plebbit/plebbit-js.git#574d1730da725a6266da6d69f2fa01f027dadb96"
dependencies:
@@ -2722,6 +2771,22 @@
uuid "8.3.2"
zustand "4.0.0"
+"@plebbit/plebbit-react-hooks@https://github.com/plebbit/plebbit-react-hooks.git#338324289dffa20ecde429fa5f428a2894851512":
+ version "0.0.1"
+ resolved "https://github.com/plebbit/plebbit-react-hooks.git#338324289dffa20ecde429fa5f428a2894851512"
+ dependencies:
+ "@adraffy/ens-normalize" "1.9.2"
+ "@plebbit/plebbit-js" "https://github.com/plebbit/plebbit-js.git#220c709566d8b680e7dc13722f4e81c8d0f13b3b"
+ "@plebbit/plebbit-logger" "https://github.com/plebbit/plebbit-logger.git"
+ assert "2.0.0"
+ ethers "5.6.9"
+ localforage "1.10.0"
+ lodash.isequal "4.5.0"
+ memoizee "0.4.15"
+ quick-lru "5.1.1"
+ uuid "8.3.2"
+ zustand "4.0.0"
+
"@pmmmwh/react-refresh-webpack-plugin@^0.5.3":
version "0.5.10"
resolved "https://registry.yarnpkg.com/@pmmmwh/react-refresh-webpack-plugin/-/react-refresh-webpack-plugin-0.5.10.tgz#2eba163b8e7dbabb4ce3609ab5e32ab63dda3ef8"
@@ -2859,6 +2924,28 @@
"@noble/hashes" "~1.3.0"
"@scure/base" "~1.1.0"
+"@scure/base@~1.1.0":
+ version "1.1.1"
+ resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.1.1.tgz#ebb651ee52ff84f420097055f4bf46cfba403938"
+ integrity sha512-ZxOhsSyxYwLJj3pLZCefNitxsj093tb2vq90mp2txoYeBqbcjDjqFhyM8eUjq/uFm6zJ+mUuqxlS2FkuSY1MTA==
+
+"@scure/bip32@1.3.0":
+ version "1.3.0"
+ resolved "https://registry.yarnpkg.com/@scure/bip32/-/bip32-1.3.0.tgz#6c8d980ef3f290987736acd0ee2e0f0d50068d87"
+ integrity sha512-bcKpo1oj54hGholplGLpqPHRbIsnbixFtc06nwuNM5/dwSXOq/AAYoIBRsBmnZJSdfeNW5rnff7NTAz3ZCqR9Q==
+ dependencies:
+ "@noble/curves" "~1.0.0"
+ "@noble/hashes" "~1.3.0"
+ "@scure/base" "~1.1.0"
+
+"@scure/bip39@1.2.0":
+ version "1.2.0"
+ resolved "https://registry.yarnpkg.com/@scure/bip39/-/bip39-1.2.0.tgz#a207e2ef96de354de7d0002292ba1503538fc77b"
+ integrity sha512-SX/uKq52cuxm4YFXWFaVByaSHJh2w3BnokVSeUJVCv6K7WulT9u2BuNRBhuFl8vAuYnzx9bEu9WgpcNYTrYieg==
+ dependencies:
+ "@noble/hashes" "~1.3.0"
+ "@scure/base" "~1.1.0"
+
"@sideway/address@^4.1.3":
version "4.1.4"
resolved "https://registry.yarnpkg.com/@sideway/address/-/address-4.1.4.tgz#03dccebc6ea47fdc226f7d3d1ad512955d4783f0"
@@ -3716,6 +3803,7 @@
dependencies:
"@webassemblyjs/floating-point-hex-parser" "1.11.6"
"@webassemblyjs/helper-api-error" "1.11.6"
+
"@xtuc/long" "4.2.2"
"@webassemblyjs/helper-wasm-bytecode@1.11.6":