From 79e948ac05efb6a13e6c0dd9a658f9a12b880152 Mon Sep 17 00:00:00 2001 From: Ren Amamiya <123083837+reyamir@users.noreply.github.com> Date: Sat, 27 May 2023 12:14:30 +0700 Subject: [PATCH] wip: refactor chats to use zustand --- .../20230418080146_create_chats.sql | 1 + src/app/chat/components/item.tsx | 12 +- src/app/chat/components/list.tsx | 6 +- src/app/chat/components/messageList.tsx | 23 ++-- src/app/chat/components/messages/form.tsx | 119 ++++++++---------- src/app/chat/components/messages/item.tsx | 19 ++- src/app/chat/components/messages/user.tsx | 10 +- src/app/chat/components/self.tsx | 52 -------- src/app/chat/components/sidebar.tsx | 30 +++++ src/app/chat/hooks/useDecryptMessage.tsx | 41 +++--- src/app/chat/layout.tsx | 1 - src/app/chat/pages/index.page.tsx | 81 +++++++----- src/app/prefetch/pages/index.page.tsx | 37 ++++-- src/app/space/components/following.tsx | 4 +- src/renderer/_default.page.server.tsx | 2 +- src/shared/appHeader.tsx | 14 +-- src/shared/eventCollector.tsx | 30 ++--- src/shared/form/imagePicker.tsx | 4 - src/shared/navigation.tsx | 2 +- src/stores/chat.tsx | 14 --- src/utils/storage.tsx | 5 +- 21 files changed, 229 insertions(+), 278 deletions(-) delete mode 100644 src/app/chat/components/self.tsx create mode 100644 src/app/chat/components/sidebar.tsx delete mode 100644 src/stores/chat.tsx diff --git a/src-tauri/migrations/20230418080146_create_chats.sql b/src-tauri/migrations/20230418080146_create_chats.sql index 551a1d4c..1dcd8cd0 100644 --- a/src-tauri/migrations/20230418080146_create_chats.sql +++ b/src-tauri/migrations/20230418080146_create_chats.sql @@ -7,5 +7,6 @@ CREATE TABLE receiver_pubkey INTEGER NOT NULL, sender_pubkey TEXT NOT NULL, content TEXT NOT NULL, + tags JSON, created_at INTEGER NOT NULL ); \ No newline at end of file diff --git a/src/app/chat/components/item.tsx b/src/app/chat/components/item.tsx index c5583706..cabf8c52 100644 --- a/src/app/chat/components/item.tsx +++ b/src/app/chat/components/item.tsx @@ -1,19 +1,18 @@ import { Image } from "@shared/image"; - +import { useActiveAccount } from "@stores/accounts"; import { DEFAULT_AVATAR } from "@stores/constants"; - import { usePageContext } from "@utils/hooks/usePageContext"; import { useProfile } from "@utils/hooks/useProfile"; import { shortenKey } from "@utils/shortenKey"; - import { twMerge } from "tailwind-merge"; -export default function ChatsListItem({ pubkey }: { pubkey: string }) { +export function ChatsListItem({ pubkey }: { pubkey: string }) { const pageContext = usePageContext(); const searchParams: any = pageContext.urlParsed.search; const pagePubkey = searchParams.pubkey; + const account = useActiveAccount((state: any) => state.account); const { user, isError, isLoading } = useProfile(pubkey); return ( @@ -43,10 +42,13 @@ export default function ChatsListItem({ pubkey }: { pubkey: string }) { className="h-5 w-5 rounded bg-white object-cover" /> -
+ {user?.nip05 || user?.username || shortenKey(pubkey)} +
+