diff --git a/web/src/components/ChatList.tsx b/web/src/components/ChatList.tsx index acc85e7..d99dbd0 100644 --- a/web/src/components/ChatList.tsx +++ b/web/src/components/ChatList.tsx @@ -23,10 +23,12 @@ export function ChatList() { const [messageResults, setMessageResults] = useState([]); const [archivedChats, setArchivedChats] = useState([]); const [searchLoading, setSearchLoading] = useState(false); - const [tab, setTab] = useState<"all" | "contacts" | "people" | "groups" | "channels" | "archived">("all"); + const [tab, setTab] = useState<"all" | "people" | "groups" | "channels" | "archived">("all"); const [archivedLoading, setArchivedLoading] = useState(false); const [contactsLoading, setContactsLoading] = useState(false); const [contacts, setContacts] = useState([]); + const [contactsOpen, setContactsOpen] = useState(false); + const [contactsSearch, setContactsSearch] = useState(""); const [contactEmail, setContactEmail] = useState(""); const [contactEmailError, setContactEmailError] = useState(null); const [ctxChatId, setCtxChatId] = useState(null); @@ -79,7 +81,7 @@ export function ChatList() { }, [tab, chats.length]); useEffect(() => { - if (tab !== "contacts") { + if (!contactsOpen) { return; } let cancelled = false; @@ -103,7 +105,7 @@ export function ChatList() { return () => { cancelled = true; }; - }, [tab]); + }, [contactsOpen]); useEffect(() => { const term = search.trim(); @@ -273,7 +275,7 @@ export function ChatList() { - +

Contacts

+ + setContactsSearch(e.target.value)} + /> +

Add contact (Email)

@@ -472,48 +502,69 @@ export function ChatList() {
{contactEmailError ?

{contactEmailError}

: null}
- ) : null} - {tab === "contacts" && !contactsLoading && contacts.length === 0 ? ( -

No contacts yet

- ) : null} - {tab === "contacts" - ? contacts.map((user) => ( -
- - -
- )) - : null} - - {tab !== "contacts" && pinnedVisibleChats.length > 0 ? ( -

Pinned

- ) : null} - {tab !== "contacts" ? pinnedVisibleChats.map(renderChatRow) : null} - {tab !== "contacts" && regularVisibleChats.length > 0 ? ( -

Chats

- ) : null} - {tab !== "contacts" ? regularVisibleChats.map(renderChatRow) : null} - +
+ {contactsLoading ? ( +

Loading contacts...

+ ) : null} + {!contactsLoading && + contacts.filter((user) => { + const term = contactsSearch.trim().toLowerCase(); + if (!term) { + return true; + } + return ( + (user.name || "").toLowerCase().includes(term) || + (user.username || "").toLowerCase().includes(term) || + (user.email || "").toLowerCase().includes(term) + ); + }).length === 0 ? ( +

No contacts yet

+ ) : null} + {!contactsLoading + ? contacts + .filter((user) => { + const term = contactsSearch.trim().toLowerCase(); + if (!term) { + return true; + } + return ( + (user.name || "").toLowerCase().includes(term) || + (user.username || "").toLowerCase().includes(term) || + (user.email || "").toLowerCase().includes(term) + ); + }) + .map((user) => ( +
+ + +
+ )) + : null} +
+ + ) : null} {ctxChatId && ctxPos