From 38b34f5c0439b6f6c27a69a0727dac3cd8c52ee3 Mon Sep 17 00:00:00 2001 From: Ren Amamiya <123083837+reyamir@users.noreply.github.com> Date: Fri, 7 Apr 2023 14:13:40 +0700 Subject: [PATCH] added new chat modal --- src/components/chats/chatList.tsx | 4 +- src/components/chats/chatListItem.tsx | 4 +- src/components/chats/chatModal.tsx | 63 +++++++++++++++++++ src/components/chats/chatModalUser.tsx | 48 ++++++++++++++ src/components/chats/messageList.tsx | 2 + src/components/chats/messageListItem.tsx | 6 +- .../chats/{user.tsx => messageUser.tsx} | 10 +-- 7 files changed, 126 insertions(+), 11 deletions(-) create mode 100644 src/components/chats/chatModal.tsx create mode 100644 src/components/chats/chatModalUser.tsx rename src/components/chats/{user.tsx => messageUser.tsx} (76%) diff --git a/src/components/chats/chatList.tsx b/src/components/chats/chatList.tsx index 73096946..2a929c1f 100644 --- a/src/components/chats/chatList.tsx +++ b/src/components/chats/chatList.tsx @@ -1,4 +1,5 @@ import { ChatListItem } from '@components/chats/chatListItem'; +import { ChatModal } from '@components/chats/chatModal'; import { ImageWithFallback } from '@components/imageWithFallback'; import { RelayContext } from '@components/relaysProvider'; @@ -19,7 +20,7 @@ export default function ChatList() { const [list, setList] = useState(new Set()); const openSelfChat = () => { - router.replace({ + router.push({ pathname: '/chats/[pubkey]', query: { pubkey: activeAccount.pubkey }, }); @@ -70,6 +71,7 @@ export default function ChatList() { {[...list].map((item: string, index) => ( ))} + ); } diff --git a/src/components/chats/chatListItem.tsx b/src/components/chats/chatListItem.tsx index 074c4e75..f9f2c6c0 100644 --- a/src/components/chats/chatListItem.tsx +++ b/src/components/chats/chatListItem.tsx @@ -12,7 +12,7 @@ export const ChatListItem = ({ pubkey }: { pubkey: string }) => { const profile = useMetadata(pubkey); const openChat = () => { - router.replace({ + router.push({ pathname: '/chats/[pubkey]', query: { pubkey: pubkey }, }); @@ -23,7 +23,7 @@ export const ChatListItem = ({ pubkey }: { pubkey: string }) => { onClick={() => openChat()} className="inline-flex items-center gap-2 rounded-md px-2.5 py-1.5 hover:bg-zinc-900" > -
+
{ + const [plebs, setPlebs] = useState([]); + const activeAccount: any = useAtomValue(activeAccountAtom); + + const fetchPlebsByAccount = useCallback(async (id) => { + const { getPlebs } = await import('@utils/bindings'); + return await getPlebs({ account_id: id }); + }, []); + + useEffect(() => { + fetchPlebsByAccount(activeAccount.id) + .then((res) => setPlebs(res)) + .catch(console.error); + }, [activeAccount.id, fetchPlebsByAccount]); + + return ( + + +
+
+ +
+
+
Add a new chat
+
+
+
+ + + +
+
+
+
+ + + +
New chat
+
+
+
+ {plebs.map((pleb) => ( + + ))} +
+
+
+
+
+
+ ); +}; diff --git a/src/components/chats/chatModalUser.tsx b/src/components/chats/chatModalUser.tsx new file mode 100644 index 00000000..d673dfd1 --- /dev/null +++ b/src/components/chats/chatModalUser.tsx @@ -0,0 +1,48 @@ +import { ImageWithFallback } from '@components/imageWithFallback'; + +import { DEFAULT_AVATAR } from '@stores/constants'; + +import { truncate } from '@utils/truncate'; + +import { useRouter } from 'next/router'; + +export const ChatModalUser = ({ data }: { data: any }) => { + const router = useRouter(); + const profile = JSON.parse(data.metadata); + + const openNewChat = () => { + router.push({ + pathname: '/chats/[pubkey]', + query: { pubkey: data.pubkey }, + }); + }; + + return ( +
+
+
+ +
+
+ + {profile?.display_name || profile?.name} + + {truncate(data.pubkey, 16, ' .... ')} +
+
+
+ +
+
+ ); +}; diff --git a/src/components/chats/messageList.tsx b/src/components/chats/messageList.tsx index fda01645..aaea7aac 100644 --- a/src/components/chats/messageList.tsx +++ b/src/components/chats/messageList.tsx @@ -37,6 +37,8 @@ export const MessageList = ({ data }: { data: any }) => { initialTopMostItemIndex={data.length - 1} alignToBottom={true} followOutput={true} + overscan={50} + increaseViewportBy={{ top: 200, bottom: 200 }} className="scrollbar-hide h-full w-full overflow-y-auto" />
diff --git a/src/components/chats/messageListItem.tsx b/src/components/chats/messageListItem.tsx index 6c3b04b7..4947fb1f 100644 --- a/src/components/chats/messageListItem.tsx +++ b/src/components/chats/messageListItem.tsx @@ -1,4 +1,4 @@ -import { MessageUser } from '@components/chats/user'; +import { MessageUser } from '@components/chats/messageUser'; import { nip04 } from 'nostr-tools'; import { memo, useCallback, useEffect, useMemo, useState } from 'react'; @@ -33,10 +33,10 @@ const MessageListItem = ({ }, [decryptContent]); return ( -
+
-
+
{content} diff --git a/src/components/chats/user.tsx b/src/components/chats/messageUser.tsx similarity index 76% rename from src/components/chats/user.tsx rename to src/components/chats/messageUser.tsx index 9ac89062..8ff71336 100644 --- a/src/components/chats/user.tsx +++ b/src/components/chats/messageUser.tsx @@ -14,8 +14,8 @@ export const MessageUser = ({ pubkey, time }: { pubkey: string; time: number }) const profile = useMetadata(pubkey); return ( -
-
+
+
- + {profile?.display_name || profile?.name || truncate(pubkey, 16, ' .... ')} - · - {dayjs().to(dayjs.unix(time))} + · + {dayjs().to(dayjs.unix(time))}