mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
Merge branch 'master' of github.com:plebbit/plebchan
This commit is contained in:
@@ -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;
|
||||
@@ -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',
|
||||
|
||||
@@ -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;
|
||||
@@ -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