Skip to content

Commit

Permalink
Merge pull request #55 from youngle316/dev
Browse files Browse the repository at this point in the history
feat: search chat title
  • Loading branch information
youngle316 authored Mar 31, 2023
2 parents 1be5d9d + cb4372a commit 903c52c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
38 changes: 31 additions & 7 deletions src/components/sideBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ import { db } from '../../service/firebase/firebase';
import ChatRow from './ChatRow';
import Setting from '../setting';
import { useI18n } from '@/hook/useI18n';
import BasicInput from '../Input';
import { useState } from 'react';

function SideBar() {
const [searchValue, setSearchValue] = useState<string>('');

const { data: session } = useSession();

const { t } = useI18n();
Expand Down Expand Up @@ -37,14 +41,34 @@ function SideBar() {
</div>
) : (
<>
<div className="mb-3">
<BasicInput
setData={setSearchValue}
placeholder={t('searchTitle')}
/>
</div>

{chats?.docs?.map((doc) => {
return (
<ChatRow
key={doc?.id}
id={doc?.id}
chatContentData={chatContentData}
/>
);
const { title } = doc.data();
if (searchValue) {
if (title && title.includes(searchValue)) {
return (
<ChatRow
key={doc?.id}
id={doc?.id}
chatContentData={chatContentData}
/>
);
}
} else {
return (
<ChatRow
key={doc?.id}
id={doc?.id}
chatContentData={chatContentData}
/>
);
}
})}
</>
)}
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@
"promptContent": "Enter your prompt here",
"addPrompt": "Add Prompt",
"cancelAddPrompt": "Cancel",
"noCustomPrompt": "You don't have custom prompts, add one first"
"noCustomPrompt": "You don't have custom prompts, add one first",
"searchTitle": "Enter title"
}
3 changes: 2 additions & 1 deletion src/i18n/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@
"promptContent": "输入你的 Prompt",
"addPrompt": "添加 Prompt",
"cancelAddPrompt": "取消",
"noCustomPrompt": "你没有自定义的 Prompts,先添加一个吧~"
"noCustomPrompt": "你没有自定义的 Prompts,先添加一个吧~",
"searchTitle": "输入要查找的标题"
}

0 comments on commit 903c52c

Please sign in to comment.