From 763af0da14c8ed04d230887b81e10c996ae8429e Mon Sep 17 00:00:00 2001 From: Ren Amamiya <123083837+reyamir@users.noreply.github.com> Date: Tue, 30 May 2023 09:56:16 +0700 Subject: [PATCH] minor updates --- src/app/channel/components/messageList.tsx | 1 - src/app/channel/components/messages/form.tsx | 41 +++++++++---------- .../channel/components/messages/userReply.tsx | 10 ++--- src/app/channel/pages/index.page.tsx | 6 ++- src/app/chat/components/messages/form.tsx | 11 +++++ src/app/chat/pages/index.page.tsx | 7 +++- src/stores/channels.tsx | 7 +++- src/stores/chats.tsx | 3 ++ src/stores/constants.tsx | 8 ++-- 9 files changed, 58 insertions(+), 36 deletions(-) diff --git a/src/app/channel/components/messageList.tsx b/src/app/channel/components/messageList.tsx index 71e8971b..eb76bf23 100644 --- a/src/app/channel/components/messageList.tsx +++ b/src/app/channel/components/messageList.tsx @@ -9,7 +9,6 @@ export function ChannelMessageList() { const virtuosoRef = useRef(null); const messages = useChannelMessages((state: any) => state.messages); - const sorted = messages; const itemContent: any = useCallback( (index: string | number) => { diff --git a/src/app/channel/components/messages/form.tsx b/src/app/channel/components/messages/form.tsx index 8a3d500b..fa7108c3 100644 --- a/src/app/channel/components/messages/form.tsx +++ b/src/app/channel/components/messages/form.tsx @@ -1,6 +1,5 @@ import UserReply from "@app/channel/components/messages/userReply"; import CancelIcon from "@icons/cancel"; -import { ImagePicker } from "@shared/form/imagePicker"; import { RelayContext } from "@shared/relayProvider"; import { useActiveAccount } from "@stores/accounts"; import { useChannelMessages } from "@stores/channels"; @@ -11,7 +10,7 @@ import { useContext, useState } from "react"; export default function ChannelMessageForm({ channelID, -}: { channelID: string | string[] }) { +}: { channelID: string }) { const pool: any = useContext(RelayContext); const account = useActiveAccount((state: any) => state.account); @@ -22,7 +21,7 @@ export default function ChannelMessageForm({ ]); const submitEvent = () => { - let tags: any[][]; + let tags: string[][]; if (replyTo.id !== null) { tags = [ @@ -34,23 +33,21 @@ export default function ChannelMessageForm({ tags = [["e", channelID, "", "root"]]; } - if (account) { - const event: any = { - content: value, - created_at: dateToUnix(), - kind: 42, - pubkey: account.pubkey, - tags: tags, - }; + const event: any = { + content: value, + created_at: dateToUnix(), + kind: 42, + pubkey: account.pubkey, + tags: tags, + }; - event.id = getEventHash(event); - event.sig = getSignature(event, account.privkey); + event.id = getEventHash(event); + event.sig = getSignature(event, account.privkey); - // publish note - pool.publish(event, WRITEONLY_RELAYS); - } else { - console.log("error"); - } + // publish note + pool.publish(event, WRITEONLY_RELAYS); + // reset state + setValue(""); }; const handleEnterPress = (e) => { @@ -68,15 +65,15 @@ export default function ChannelMessageForm({
{replyTo.id && ( -
+
-
-
{replyTo.content}
+
+
{replyTo.content}
+
+
); } diff --git a/src/app/chat/pages/index.page.tsx b/src/app/chat/pages/index.page.tsx index f5ef3cf7..0f96aea5 100644 --- a/src/app/chat/pages/index.page.tsx +++ b/src/app/chat/pages/index.page.tsx @@ -18,9 +18,10 @@ export function Page() { const searchParams: any = pageContext.urlParsed.search; const pubkey = searchParams.pubkey; - const [fetchMessages, addMessage] = useChatMessages((state: any) => [ + const [fetchMessages, addMessage, clear] = useChatMessages((state: any) => [ state.fetch, state.add, + state.clear, ]); useSWRSubscription(account ? ["chat", pubkey] : null, ([, key]) => { @@ -52,6 +53,10 @@ export function Page() { useEffect(() => { fetchMessages(account.pubkey, pubkey); + + return () => { + clear(); + }; }, [pubkey]); return ( diff --git a/src/stores/channels.tsx b/src/stores/channels.tsx index 60e37715..05e5bd8d 100644 --- a/src/stores/channels.tsx +++ b/src/stores/channels.tsx @@ -13,7 +13,6 @@ export const useChannels = create((set) => ({ export const useChannelMessages = create( immer((set) => ({ messages: [], - members: new Set(), replyTo: { id: null, pubkey: null, content: null }, add: (message: any) => { set((state: any) => ({ messages: [...state.messages, message] })); @@ -36,5 +35,11 @@ export const useChannelMessages = create( state.messages[target]["mute"] = true; }); }, + clear: () => { + set(() => ({ + messages: [], + replyTo: { id: null, pubkey: null, content: null }, + })); + }, })), ); diff --git a/src/stores/chats.tsx b/src/stores/chats.tsx index d29993b2..89b58b8e 100644 --- a/src/stores/chats.tsx +++ b/src/stores/chats.tsx @@ -18,4 +18,7 @@ export const useChatMessages = create((set) => ({ add: (message: any) => { set((state: any) => ({ messages: [...state.messages, message] })); }, + clear: () => { + set(() => ({ messages: [] })); + }, })); diff --git a/src/stores/constants.tsx b/src/stores/constants.tsx index 040f629c..d3d96bde 100644 --- a/src/stores/constants.tsx +++ b/src/stores/constants.tsx @@ -5,18 +5,16 @@ export const DEFAULT_AVATAR = "https://void.cat/d/KmypFh2fBdYCEvyJrPiN89.webp"; export const DEFAULT_CHANNEL_BANNER = "https://bafybeiacwit7hjmdefqggxqtgh6ht5dhth7ndptwn2msl5kpkodudsr7py.ipfs.w3s.link/banner-1.jpg"; -// metadata service -export const METADATA_SERVICE = "https://us.rbr.bio"; - // read-only relay list export const READONLY_RELAYS = [ "wss://welcome.nostr.wine", "wss://relay.nostr.band", + "wss://relay.damus.io", ]; // write-only relay list export const WRITEONLY_RELAYS = [ - "wss://nostr.mutinywallet.com", + "wss://relay.damus.io", "wss://relay.nostr.band", ]; @@ -27,5 +25,5 @@ export const METADATA_RELAY = ["wss://relay.nostr.band"]; export const FULL_RELAYS = [ "wss://welcome.nostr.wine", "wss://relay.nostr.band", - "wss://nostr.mutinywallet.com", + "wss://relay.damus.io", ];