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:
@@ -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