Skip to content

Commit 154aa33

Browse files
Implement search functionality for chat history in independent panel
Co-authored-by: PeterDaveHello <3691490+PeterDaveHello@users.noreply.github.com>
1 parent b12f461 commit 154aa33

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

src/_locales/en/main.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@
9797
"Delete Conversation": "Delete Conversation",
9898
"Clear conversations": "Clear conversations",
9999
"Settings": "Settings",
100+
"Search": "Search",
101+
"Search conversations...": "Search conversations...",
100102
"Feature Pages": "Feature Pages",
101103
"Keyboard Shortcuts": "Keyboard Shortcuts",
102104
"Open Conversation Page": "Open Conversation Page",

src/_locales/zh-hans/main.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@
9797
"Delete Conversation": "删除对话",
9898
"Clear conversations": "清空记录",
9999
"Settings": "设置",
100+
"Search": "搜索",
101+
"Search conversations...": "搜索聊天记录...",
100102
"Feature Pages": "功能页",
101103
"Keyboard Shortcuts": "快捷键设置",
102104
"Open Conversation Page": "打开独立对话页",

src/pages/IndependentPanel/App.jsx

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function App() {
2525
const [sessionId, setSessionId] = useState(null)
2626
const [currentSession, setCurrentSession] = useState(null)
2727
const [renderContent, setRenderContent] = useState(false)
28+
const [searchQuery, setSearchQuery] = useState('')
2829
const currentPort = useRef(null)
2930

3031
const setSessionIdSafe = async (sessionId) => {
@@ -103,6 +104,29 @@ function App() {
103104
await setSessionIdSafe(sessions[0].sessionId)
104105
}
105106

107+
// Filter sessions based on search query
108+
const filteredSessions = sessions.filter((session) => {
109+
if (!searchQuery.trim()) return true
110+
111+
const query = searchQuery.toLowerCase()
112+
113+
// Search in session name
114+
if (session.sessionName && session.sessionName.toLowerCase().includes(query)) {
115+
return true
116+
}
117+
118+
// Search in conversation records
119+
if (session.conversationRecords && Array.isArray(session.conversationRecords)) {
120+
return session.conversationRecords.some((record) => {
121+
const questionMatch = record.question && record.question.toLowerCase().includes(query)
122+
const answerMatch = record.answer && record.answer.toLowerCase().includes(query)
123+
return questionMatch || answerMatch
124+
})
125+
}
126+
127+
return false
128+
})
129+
106130
return (
107131
<div className="IndependentPanel">
108132
<div className="chat-container">
@@ -119,8 +143,17 @@ function App() {
119143
</button>
120144
</div>
121145
<hr />
146+
<div className="search-container">
147+
<input
148+
type="text"
149+
placeholder={t('Search conversations...')}
150+
value={searchQuery}
151+
onChange={(e) => setSearchQuery(e.target.value)}
152+
className="search-input"
153+
/>
154+
</div>
122155
<div className="chat-list">
123-
{sessions.map(
156+
{filteredSessions.map(
124157
(
125158
session,
126159
index, // TODO editable session name

src/pages/IndependentPanel/styles.scss

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,33 @@
8585
gap: 15px;
8686
}
8787

88+
.search-container {
89+
padding: 0;
90+
background-color: var(--theme-color);
91+
}
92+
93+
.search-input {
94+
width: 100%;
95+
min-height: 40px;
96+
padding: 8px 12px;
97+
border: 1px solid var(--theme-border-color);
98+
border-radius: 5px;
99+
background-color: var(--theme-color);
100+
color: var(--font-color);
101+
font-size: 14px;
102+
font-family: 'Cairo', sans-serif;
103+
}
104+
105+
.search-input::placeholder {
106+
color: var(--font-color);
107+
opacity: 0.6;
108+
}
109+
110+
.search-input:focus {
111+
outline: none;
112+
border-color: var(--font-active-color);
113+
}
114+
88115
.chat-list {
89116
display: flex;
90117
flex-direction: column;

0 commit comments

Comments
 (0)