minor fixes

This commit is contained in:
Ren Amamiya
2023-04-24 15:29:40 +07:00
parent cdbf70591e
commit 3e31e7d4dc
12 changed files with 34 additions and 26 deletions

View File

@@ -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 (
<AlertDialog.Root>

View File

@@ -1,4 +1,4 @@
import ChannelMessageItem from '@components/channels/messages/item';
import { ChannelMessageItem } from '@components/channels/messages/item';
import { sortedChannelMessagesAtom } from '@stores/channel';

View File

@@ -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 }) => {
</div>
</div>
);
};
export default memo(ChannelMessageItem);
});

View File

@@ -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() {
<MessageListItem data={data[index]} userPubkey={activeAccount.pubkey} userPrivkey={activeAccount.privkey} />
);
},
[data]
[activeAccount.privkey, activeAccount.pubkey, data]
);
const computeItemKey = useCallback(

View File

@@ -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
</div>
</div>
);
};
export default memo(MessageListItem);
});

View File

@@ -104,7 +104,7 @@ export default function EventCollector() {
return () => {
unsubscribe();
};
}, [follows, pool, setHasNewerNote]);
}, [activeAccount.id, activeAccount.pubkey, follows, pool, setHasNewerNote]);
useEffect(() => {
let ignore = false;

View File

@@ -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) {

View File

@@ -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 <ActiveAccount key={account.pubkey} user={account} />;
} else {
return <InactiveAccount key={account.pubkey} user={account} />;
}
}, []);
const renderAccount = useCallback(
(account: { pubkey: string }) => {
if (account.pubkey === activeAccount.pubkey) {
return <ActiveAccount key={account.pubkey} user={account} />;
} else {
return <InactiveAccount key={account.pubkey} user={account} />;
}
},
[activeAccount.pubkey]
);
return (
<div className="flex h-full flex-col items-center justify-between px-2 pb-4 pt-3">

View File

@@ -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)

View File

@@ -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)

View File

@@ -16,6 +16,7 @@ export function PageContextProvider({
return <Context.Provider value={pageContext}>{children}</Context.Provider>;
}
// eslint-disable-next-line react-refresh/only-export-components
export function usePageContext() {
const pageContext = useContext(Context);
return pageContext;

View File

@@ -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;
};