mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix race condition
This commit is contained in:
@@ -1,13 +1,17 @@
|
|||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { createAccount, setActiveAccount, useAccounts } from "@plebbit/plebbit-react-hooks";
|
import { createAccount, setActiveAccount, useAccounts } from "@plebbit/plebbit-react-hooks";
|
||||||
|
import useAnonModeStore from "./stores/useAnonModeStore";
|
||||||
|
|
||||||
const useAnonMode = (threadCid, execute) => {
|
const useAnonMode = (threadCid, execute) => {
|
||||||
const {accounts} = useAccounts();
|
const {accounts} = useAccounts();
|
||||||
|
const { anonymousMode } = useAnonModeStore();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleAnonMode = async () => {
|
const handleAnonMode = async () => {
|
||||||
let storedAccounts = JSON.parse(localStorage.getItem('storedAccounts')) || {};
|
let storedAccounts = JSON.parse(localStorage.getItem('storedAccounts')) || {};
|
||||||
|
|
||||||
|
if (!anonymousMode) return;
|
||||||
|
|
||||||
if (!storedAccounts[threadCid] && execute) {
|
if (!storedAccounts[threadCid] && execute) {
|
||||||
await createAccount();
|
await createAccount();
|
||||||
const lastAccount = accounts[accounts.length - 1];
|
const lastAccount = accounts[accounts.length - 1];
|
||||||
@@ -21,7 +25,7 @@ const useAnonMode = (threadCid, execute) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleAnonMode();
|
handleAnonMode();
|
||||||
}, [threadCid, execute, accounts]);
|
}, [threadCid, execute, accounts, anonymousMode]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user