feat: move search bar from chat-list to sidebar

This commit is contained in:
Andision 2023-12-01 04:50:21 +00:00
parent 59e7532e77
commit 0544ad0ccf
2 changed files with 18 additions and 18 deletions

View File

@ -98,7 +98,7 @@ export function ChatItem(props: {
); );
} }
export function ChatList(props: { narrow?: boolean }) { export function ChatList(props: { narrow?: boolean; search: string }) {
const [sessions, selectedIndex, selectSession, moveSession] = useChatStore( const [sessions, selectedIndex, selectSession, moveSession] = useChatStore(
(state) => [ (state) => [
state.sessions, state.sessions,
@ -127,10 +127,8 @@ export function ChatList(props: { narrow?: boolean }) {
moveSession(source.index, destination.index); moveSession(source.index, destination.index);
}; };
const [chatListSearch, setChatListSearch] = useState("");
function haveSearchKeyword(item: ChatSession): boolean { function haveSearchKeyword(item: ChatSession): boolean {
if (chatListSearch.length === 0) { if (props.search.length === 0) {
return true; return true;
} }
@ -138,7 +136,7 @@ export function ChatList(props: { narrow?: boolean }) {
item.messages.forEach((message) => { item.messages.forEach((message) => {
// console.log(chatListSearch, message.content, message.content.includes(chatListSearch)) // console.log(chatListSearch, message.content, message.content.includes(chatListSearch))
if (message.content.includes(chatListSearch)) { if (message.content.includes(props.search)) {
foundKeyword = true; foundKeyword = true;
return; return;
} }
@ -156,16 +154,6 @@ export function ChatList(props: { narrow?: boolean }) {
ref={provided.innerRef} ref={provided.innerRef}
{...provided.droppableProps} {...provided.droppableProps}
> >
<div className={styles["chat-list-search"]}>
<SearchInput
value={chatListSearch}
onChange={(e) => {
setChatListSearch(e.currentTarget.value);
}}
placeholder={Locale.Home.Search}
></SearchInput>
</div>
{sessions.map( {sessions.map(
(item, i) => (item, i) =>
haveSearchKeyword(item) && ( haveSearchKeyword(item) && (

View File

@ -1,4 +1,4 @@
import { useEffect, useRef, useMemo } from "react"; import { useEffect, useRef, useMemo, useState } from "react";
import styles from "./home.module.scss"; import styles from "./home.module.scss";
@ -29,7 +29,7 @@ import {
import { Link, useNavigate } from "react-router-dom"; import { Link, useNavigate } from "react-router-dom";
import { isIOS, useMobileScreen } from "../utils"; import { isIOS, useMobileScreen } from "../utils";
import dynamic from "next/dynamic"; import dynamic from "next/dynamic";
import { showConfirm, showToast } from "./ui-lib"; import { SearchInput, showConfirm, showToast } from "./ui-lib";
const ChatList = dynamic(async () => (await import("./chat-list")).ChatList, { const ChatList = dynamic(async () => (await import("./chat-list")).ChatList, {
loading: () => null, loading: () => null,
@ -141,6 +141,8 @@ export function SideBar(props: { className?: string }) {
[isMobileScreen], [isMobileScreen],
); );
const [chatListSearch, setChatListSearch] = useState("");
useHotKey(); useHotKey();
return ( return (
@ -188,6 +190,16 @@ export function SideBar(props: { className?: string }) {
/> />
</div> </div>
<div className={styles["chat-list-search"]}>
<SearchInput
value={chatListSearch}
onChange={(e) => {
setChatListSearch(e.currentTarget.value);
}}
placeholder={Locale.Home.Search}
></SearchInput>
</div>
<div <div
className={styles["sidebar-body"]} className={styles["sidebar-body"]}
onClick={(e) => { onClick={(e) => {
@ -196,7 +208,7 @@ export function SideBar(props: { className?: string }) {
} }
}} }}
> >
<ChatList narrow={shouldNarrow} /> <ChatList narrow={shouldNarrow} search={chatListSearch} />
</div> </div>
<div className={styles["sidebar-tail"]}> <div className={styles["sidebar-tail"]}>