fixed some performance issues

This commit is contained in:
Ren Amamiya
2023-04-21 15:13:33 +07:00
parent f8dff5f81e
commit 9fdf2eb81c
12 changed files with 71 additions and 62 deletions

View File

@@ -4,20 +4,9 @@ import { DEFAULT_AVATAR, DEFAULT_CHANNEL_BANNER } from '@stores/constants';
import { useChannelMetadata } from '@utils/hooks/useChannelMetadata';
import { useRouter } from 'next/navigation';
import { useCallback } from 'react';
export const BrowseChannelItem = ({ data }: { data: any }) => {
const router = useRouter();
const channel = useChannelMetadata(data.event_id, data.metadata);
const openChannel = useCallback(
(id: string) => {
router.push(`/nostr/channels/${id}`);
},
[router]
);
return (
<div className="h-64 w-full rounded-md bg-zinc-900">
<div className="relative h-24">

View File

@@ -23,7 +23,7 @@ export default function EventCollector() {
const now = useRef(new Date());
const subscribe = useCallback(async () => {
pool.subscribe(
const unsubscribe = pool.subscribe(
[
{
kinds: [1, 6],
@@ -101,7 +101,11 @@ export default function EventCollector() {
}
}
);
}, [activeAccount.follows, activeAccount.pubkey, activeAccount.id, pool, relays, setHasNewerNote]);
return () => {
unsubscribe();
};
}, [activeAccount.pubkey, activeAccount.id, follows, pool, relays, setHasNewerNote]);
useEffect(() => {
subscribe();

View File

@@ -15,7 +15,7 @@ import { getEventHash, signEvent } from 'nostr-tools';
import { useCallback, useContext } from 'react';
export const FormChannel = ({ eventId }: { eventId: string | string[] }) => {
const [pool, relays]: any = useContext(RelayContext);
const [pool]: any = useContext(RelayContext);
const [activeAccount]: any = useLocalStorage('account', {});
const [value, setValue] = useAtom(channelContentAtom);
@@ -61,8 +61,8 @@ export const FormChannel = ({ eventId }: { eventId: string | string[] }) => {
activeAccount.privkey,
eventId,
resetChannelReply,
resetValue,
pool,
relays,
]);
const handleEnterPress = (e) => {

View File

@@ -13,7 +13,7 @@ import { getEventHash, nip04, signEvent } from 'nostr-tools';
import { useCallback, useContext } from 'react';
export default function FormChat({ receiverPubkey }: { receiverPubkey: string }) {
const [pool, relays]: any = useContext(RelayContext);
const [pool]: any = useContext(RelayContext);
const [activeAccount]: any = useLocalStorage('account', {});
const [value, setValue] = useAtom(chatContentAtom);
@@ -44,7 +44,7 @@ export default function FormChat({ receiverPubkey }: { receiverPubkey: string })
resetValue();
})
.catch(console.error);
}, [encryptMessage, activeAccount.privkey, activeAccount.pubkey, receiverPubkey, pool]);
}, [encryptMessage, activeAccount.privkey, activeAccount.pubkey, receiverPubkey, resetValue, pool]);
const handleEnterPress = (e) => {
if (e.key === 'Enter' && !e.shiftKey) {