-
-
Notifications
You must be signed in to change notification settings - Fork 11.3k
/
Copy pathindex.tsx
42 lines (35 loc) · 1.17 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use client';
import { SearchBar } from '@lobehub/ui';
import { useUnmount } from 'ahooks';
import { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useChatStore } from '@/store/chat';
import { useServerConfigStore } from '@/store/serverConfig';
const TopicSearchBar = memo<{ onClear?: () => void }>(({ onClear }) => {
const { t } = useTranslation('topic');
const [keywords, setKeywords] = useState('');
const mobile = useServerConfigStore((s) => s.isMobile);
const [activeSessionId, useSearchTopics] = useChatStore((s) => [s.activeId, s.useSearchTopics]);
useSearchTopics(keywords, activeSessionId);
useUnmount(() => {
useChatStore.setState({ isSearchingTopic: false });
});
return (
<SearchBar
autoFocus
onBlur={() => {
if (keywords === '') onClear?.();
}}
onChange={(e) => {
const value = e.target.value;
setKeywords(value);
useChatStore.setState({ isSearchingTopic: !!value });
}}
placeholder={t('searchPlaceholder')}
spotlight={!mobile}
type={mobile ? 'block' : 'ghost'}
value={keywords}
/>
);
});
export default TopicSearchBar;