make search result item easier to click

This commit is contained in:
heweikang 2024-08-15 17:21:39 +08:00
parent 00990dc195
commit 98093a1f31

View File

@ -25,21 +25,6 @@ export function SearchChatPage() {
const [searchResults, setSearchResults] = useState<Item[]>([]); const [searchResults, setSearchResults] = useState<Item[]>([]);
// const setDefaultItems = () => {
// setSearchResults(
// sessions.slice(1, 7).map((session, index) => {
// return {
// id: index,
// name: session.topic,
// content: session.messages[0].content as string, //.map((m) => m.content).join("\n")
// };
// }),
// );
// };
// useEffect(() => {
// setDefaultItems();
// }, []);
const previousValueRef = useRef<string>(""); const previousValueRef = useRef<string>("");
const searchInputRef = useRef<HTMLInputElement>(null); const searchInputRef = useRef<HTMLInputElement>(null);
const doSearch = (text: string) => { const doSearch = (text: string) => {
@ -53,7 +38,7 @@ export function SearchChatPage() {
const content = message.content as string; const content = message.content as string;
const lowerCaseContent = content.toLowerCase(); const lowerCaseContent = content.toLowerCase();
// 全文搜索 // full text search
let pos = lowerCaseContent.indexOf(lowerCaseText); let pos = lowerCaseContent.indexOf(lowerCaseText);
while (pos !== -1) { while (pos !== -1) {
const start = Math.max(0, pos - 35); const start = Math.max(0, pos - 35);
@ -70,12 +55,12 @@ export function SearchChatPage() {
results.push({ results.push({
id: index, id: index,
name: session.topic, name: session.topic,
content: fullTextContents.join("... "), // 使用...连接不同消息中的内容 content: fullTextContents.join("... "), // concat content with...
}); });
} }
}); });
// 按内容长度排序 // sort by length of matching content
results.sort((a, b) => b.content.length - a.content.length); results.sort((a, b) => b.content.length - a.content.length);
return results; return results;
@ -148,7 +133,15 @@ export function SearchChatPage() {
<div> <div>
{searchResults.map((item) => ( {searchResults.map((item) => (
<div className={styles["mask-item"]} key={item.id}> <div
className={styles["mask-item"]}
key={item.id}
onClick={() => {
navigate(Path.Chat);
selectSession(item.id);
}}
style={{ cursor: "pointer" }}
>
{/** 搜索匹配的文本 */} {/** 搜索匹配的文本 */}
<div className={styles["mask-header"]}> <div className={styles["mask-header"]}>
<div className={styles["mask-title"]}> <div className={styles["mask-title"]}>
@ -161,10 +154,6 @@ export function SearchChatPage() {
<IconButton <IconButton
icon={<EyeIcon />} icon={<EyeIcon />}
text={Locale.SearchChat.Item.View} text={Locale.SearchChat.Item.View}
onClick={() => {
navigate(Path.Chat);
selectSession(item.id);
}}
/> />
</div> </div>
</div> </div>