From 3e31e7d4dccf2442b7cda8cbd7d7c0fd860d8478 Mon Sep 17 00:00:00 2001 From: Ren Amamiya <123083837+reyamir@users.noreply.github.com> Date: Mon, 24 Apr 2023 15:29:40 +0700 Subject: [PATCH] minor fixes --- .../channels/messages/hideMessageButton.tsx | 2 +- src/components/channels/messages/index.tsx | 2 +- src/components/channels/messages/item.tsx | 6 ++---- src/components/chats/messageList.tsx | 4 ++-- src/components/chats/messageListItem.tsx | 14 ++++++++++---- src/components/eventCollector.tsx | 2 +- src/components/form/chat.tsx | 2 +- src/components/multiAccounts/index.tsx | 17 ++++++++++------- src/components/note/parent.tsx | 2 +- src/components/note/quote.tsx | 2 +- src/utils/hooks/usePageContext.tsx | 1 + src/utils/hooks/useProfileMetadata.tsx | 6 +++--- 12 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/components/channels/messages/hideMessageButton.tsx b/src/components/channels/messages/hideMessageButton.tsx index 3af35fc1..d6513c00 100644 --- a/src/components/channels/messages/hideMessageButton.tsx +++ b/src/components/channels/messages/hideMessageButton.tsx @@ -28,7 +28,7 @@ export const HideMessageButton = ({ id }: { id: string }) => { // publish note pool.publish(event, MESSAGE_RELAYS); - }, [id, pool, MESSAGE_RELAYS]); + }, [activeAccount.pubkey, activeAccount.privkey, id, pool]); return ( diff --git a/src/components/channels/messages/index.tsx b/src/components/channels/messages/index.tsx index 962c314c..a7e84a97 100644 --- a/src/components/channels/messages/index.tsx +++ b/src/components/channels/messages/index.tsx @@ -1,4 +1,4 @@ -import ChannelMessageItem from '@components/channels/messages/item'; +import { ChannelMessageItem } from '@components/channels/messages/item'; import { sortedChannelMessagesAtom } from '@stores/channel'; diff --git a/src/components/channels/messages/item.tsx b/src/components/channels/messages/item.tsx index a2fb5769..a5e0b1a5 100644 --- a/src/components/channels/messages/item.tsx +++ b/src/components/channels/messages/item.tsx @@ -7,7 +7,7 @@ import { messageParser } from '@utils/parser'; import { memo } from 'react'; -const ChannelMessageItem = ({ data }: { data: any }) => { +export const ChannelMessageItem = memo(function ChannelMessageItem({ data }: { data: any }) { const content = messageParser(data.content); return ( @@ -31,6 +31,4 @@ const ChannelMessageItem = ({ data }: { data: any }) => { ); -}; - -export default memo(ChannelMessageItem); +}); diff --git a/src/components/chats/messageList.tsx b/src/components/chats/messageList.tsx index e9813de0..dae03147 100644 --- a/src/components/chats/messageList.tsx +++ b/src/components/chats/messageList.tsx @@ -1,5 +1,5 @@ import { AccountContext } from '@components/accountProvider'; -import MessageListItem from '@components/chats/messageListItem'; +import { MessageListItem } from '@components/chats/messageListItem'; import { sortedChatMessagesAtom } from '@stores/chat'; @@ -20,7 +20,7 @@ export default function MessageList() { ); }, - [data] + [activeAccount.privkey, activeAccount.pubkey, data] ); const computeItemKey = useCallback( diff --git a/src/components/chats/messageListItem.tsx b/src/components/chats/messageListItem.tsx index f91918cd..8b314153 100644 --- a/src/components/chats/messageListItem.tsx +++ b/src/components/chats/messageListItem.tsx @@ -4,7 +4,15 @@ import { useDecryptMessage } from '@utils/hooks/useDecryptMessage'; import { memo } from 'react'; -const MessageListItem = ({ data, userPubkey, userPrivkey }: { data: any; userPubkey: string; userPrivkey: string }) => { +export const MessageListItem = memo(function MessageListItem({ + data, + userPubkey, + userPrivkey, +}: { + data: any; + userPubkey: string; + userPrivkey: string; +}) { const content = useDecryptMessage(userPubkey, userPrivkey, data.pubkey, data.tags, data.content); return ( @@ -21,6 +29,4 @@ const MessageListItem = ({ data, userPubkey, userPrivkey }: { data: any; userPub ); -}; - -export default memo(MessageListItem); +}); diff --git a/src/components/eventCollector.tsx b/src/components/eventCollector.tsx index ebb831a5..edd7d06a 100644 --- a/src/components/eventCollector.tsx +++ b/src/components/eventCollector.tsx @@ -104,7 +104,7 @@ export default function EventCollector() { return () => { unsubscribe(); }; - }, [follows, pool, setHasNewerNote]); + }, [activeAccount.id, activeAccount.pubkey, follows, pool, setHasNewerNote]); useEffect(() => { let ignore = false; diff --git a/src/components/form/chat.tsx b/src/components/form/chat.tsx index 230312da..9aeb4fdf 100644 --- a/src/components/form/chat.tsx +++ b/src/components/form/chat.tsx @@ -44,7 +44,7 @@ export default function FormChat({ receiverPubkey }: { receiverPubkey: string }) resetValue(); }) .catch(console.error); - }, [encryptMessage, receiverPubkey, resetValue, pool]); + }, [activeAccount.privkey, activeAccount.pubkey, receiverPubkey, pool, resetValue, encryptMessage]); const handleEnterPress = (e) => { if (e.key === 'Enter' && !e.shiftKey) { diff --git a/src/components/multiAccounts/index.tsx b/src/components/multiAccounts/index.tsx index 08e39fd8..fcc932a6 100644 --- a/src/components/multiAccounts/index.tsx +++ b/src/components/multiAccounts/index.tsx @@ -19,13 +19,16 @@ if (typeof window !== 'undefined') { export default function MultiAccounts() { const activeAccount: any = useContext(AccountContext); - const renderAccount = useCallback((account: { pubkey: string }) => { - if (account.pubkey === activeAccount.pubkey) { - return ; - } else { - return ; - } - }, []); + const renderAccount = useCallback( + (account: { pubkey: string }) => { + if (account.pubkey === activeAccount.pubkey) { + return ; + } else { + return ; + } + }, + [activeAccount.pubkey] + ); return (
diff --git a/src/components/note/parent.tsx b/src/components/note/parent.tsx index 695a38e1..55079d96 100644 --- a/src/components/note/parent.tsx +++ b/src/components/note/parent.tsx @@ -54,7 +54,7 @@ export const NoteParent = memo(function NoteParent({ id }: { id: string }) { return () => { unsubscribe(); }; - }, [id, pool]); + }, [activeAccount.id, id, pool]); const checkNoteIsSaved = useCallback(async () => { getNoteByID(id) diff --git a/src/components/note/quote.tsx b/src/components/note/quote.tsx index c7601c83..4f4bde67 100644 --- a/src/components/note/quote.tsx +++ b/src/components/note/quote.tsx @@ -52,7 +52,7 @@ export const NoteQuote = memo(function NoteQuote({ id }: { id: string }) { return () => { unsubscribe(); }; - }, [id, pool]); + }, [activeAccount.id, id, pool]); const checkNoteIsSaved = useCallback(async () => { getNoteByID(id) diff --git a/src/utils/hooks/usePageContext.tsx b/src/utils/hooks/usePageContext.tsx index a1303f6b..6adc4f3d 100644 --- a/src/utils/hooks/usePageContext.tsx +++ b/src/utils/hooks/usePageContext.tsx @@ -16,6 +16,7 @@ export function PageContextProvider({ return {children}; } +// eslint-disable-next-line react-refresh/only-export-components export function usePageContext() { const pageContext = useContext(Context); return pageContext; diff --git a/src/utils/hooks/useProfileMetadata.tsx b/src/utils/hooks/useProfileMetadata.tsx index 6adedb93..4ca80f84 100644 --- a/src/utils/hooks/useProfileMetadata.tsx +++ b/src/utils/hooks/useProfileMetadata.tsx @@ -35,9 +35,9 @@ export const useProfileMetadata = (pubkey: string) => { fetchProfileMetadata(pubkey).then((res: any) => { if (res) { // update state - setProfile(res); + setProfile(JSON.parse(res.content)); // insert to db - insertPlebToDB(pubkey, JSON.stringify(res)); + insertPlebToDB(pubkey, res.content); } }); } @@ -48,7 +48,7 @@ export const useProfileMetadata = (pubkey: string) => { return () => { ignore = true; }; - }, [insertPlebToDB, pubkey]); + }, [getProfileFromDB, insertPlebToDB, pubkey]); return profile; };