migrated activeAccount state to rehook

This commit is contained in:
Ren Amamiya
2023-04-11 09:02:39 +07:00
parent 0bfcb10253
commit 4e1dcdc2ce
20 changed files with 72 additions and 85 deletions

View File

@@ -29,20 +29,19 @@ export const ActiveAccount = memo(function ActiveAccount({ user }: { user: any }
const insertFollowsToStorage = useCallback(
async (tags) => {
const { createPleb } = await import('@utils/bindings');
const activeAccount = JSON.parse(localStorage.getItem('activeAccount'));
for (const tag of tags) {
const metadata: any = await fetchMetadata(tag[1], pool, relays);
createPleb({
pleb_id: tag[1] + '-lume' + activeAccount.id.toString(),
pleb_id: tag[1] + '-lume' + user.id.toString(),
pubkey: tag[1],
kind: 0,
metadata: metadata.content,
account_id: activeAccount.id,
account_id: user.id,
}).catch(console.error);
}
},
[pool, relays]
[pool, relays, user.id]
);
useEffect(() => {

View File

@@ -6,15 +6,15 @@ import { APP_VERSION } from '@stores/constants';
import LumeSymbol from '@assets/icons/Lume';
import { PlusIcon } from '@radix-ui/react-icons';
import useLocalStorage from '@rehooks/local-storage';
import Link from 'next/link';
import { useCallback, useEffect, useState } from 'react';
export default function MultiAccounts() {
const [users, setUsers] = useState([]);
const [activeAccount]: any = useLocalStorage('activeAccount');
const renderAccount = useCallback((user: { pubkey: string }) => {
const activeAccount = JSON.parse(localStorage.getItem('activeAccount'));
if (user.pubkey === activeAccount.pubkey) {
return <ActiveAccount key={user.pubkey} user={user} />;
} else {