Skip to content

Commit fd448a9

Browse files
Address code review feedback: improve key props, delete handling, and search robustness
Co-authored-by: PeterDaveHello <[email protected]>
1 parent 534c936 commit fd448a9

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

src/pages/IndependentPanel/App.jsx

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,21 +106,27 @@ function App() {
106106

107107
// Filter sessions based on search query (memoized for performance)
108108
const filteredSessions = useMemo(() => {
109-
const query = searchQuery.trim().toLowerCase()
109+
const query = String(searchQuery || '')
110+
.trim()
111+
.toLowerCase()
110112
if (!query) return sessions
111113

114+
const toSafeString = (value) =>
115+
typeof value === 'string' ? value : value == null ? '' : String(value)
116+
112117
return sessions.filter((session) => {
113118
// Search in session name
114-
if (session.sessionName && session.sessionName.toLowerCase().includes(query)) {
119+
const sessionName = toSafeString(session.sessionName).toLowerCase()
120+
if (sessionName.includes(query)) {
115121
return true
116122
}
117123

118124
// Search in conversation records
119-
if (session.conversationRecords) {
125+
if (Array.isArray(session.conversationRecords)) {
120126
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
127+
const question = toSafeString(record?.question).toLowerCase()
128+
const answer = toSafeString(record?.answer).toLowerCase()
129+
return question.includes(query) || answer.includes(query)
124130
})
125131
}
126132

@@ -156,9 +162,9 @@ function App() {
156162
/>
157163
</div>
158164
<div className="chat-list">
159-
{filteredSessions.map((session) => (
165+
{filteredSessions.map((session, index) => (
160166
<button
161-
key={session.sessionId}
167+
key={session.sessionId || `session-${index}`}
162168
className={`normal-button ${sessionId === session.sessionId ? 'active' : ''}`}
163169
style={{
164170
display: 'flex',
@@ -174,12 +180,17 @@ function App() {
174180
<DeleteButton
175181
size={14}
176182
text={t('Delete Conversation')}
177-
onConfirm={() =>
178-
deleteSession(session.sessionId).then((sessions) => {
179-
setSessions(sessions)
180-
setSessionIdSafe(sessions[0].sessionId)
181-
})
182-
}
183+
onConfirm={async () => {
184+
const updatedSessions = await deleteSession(session.sessionId)
185+
setSessions(updatedSessions)
186+
if (updatedSessions && updatedSessions.length > 0) {
187+
await setSessionIdSafe(updatedSessions[0].sessionId)
188+
} else {
189+
// No sessions left after deletion
190+
setSessionId(null)
191+
setCurrentSession(null)
192+
}
193+
}}
183194
/>
184195
</span>
185196
</button>

0 commit comments

Comments
 (0)