-
Notifications
You must be signed in to change notification settings - Fork 1
Fix chat scroll and charts message persistance #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -147,6 +147,8 @@ export default function FinanceAnalysis() { | |||||||||||||||||||
|
|
||||||||||||||||||||
| const [selectedCharts, setSelectedCharts] = React.useState<BarChartDef[]>([]); | ||||||||||||||||||||
| const [isChartsExpanded, setIsChartsExpanded] = React.useState(false); | ||||||||||||||||||||
| // Map message IDs to their associated charts | ||||||||||||||||||||
| const [messageCharts, setMessageCharts] = React.useState<Map<string | number, BarChartDef[]>>(new Map()); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Predefined suggestions related to financial data | ||||||||||||||||||||
| const financialSuggestions: ChatSuggestion[] = [ | ||||||||||||||||||||
|
|
@@ -178,36 +180,48 @@ export default function FinanceAnalysis() { | |||||||||||||||||||
| suggestions: financialSuggestions, | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Watch for changes in the latest response to update charts | ||||||||||||||||||||
| // Associate charts with the latest bot message when response arrives | ||||||||||||||||||||
| React.useEffect(() => { | ||||||||||||||||||||
| if ( | ||||||||||||||||||||
| chatBot.latestResponse?.json?.charts && | ||||||||||||||||||||
| Array.isArray(chatBot.latestResponse.json.charts) | ||||||||||||||||||||
| Array.isArray(chatBot.latestResponse.json.charts) && | ||||||||||||||||||||
| chatBot.latestResponse.messageId | ||||||||||||||||||||
| ) { | ||||||||||||||||||||
| const validCharts: BarChartDef[] = chatBot.latestResponse.json.charts | ||||||||||||||||||||
| .filter(isBarChartDef) | ||||||||||||||||||||
| .slice(0, 3); | ||||||||||||||||||||
| setSelectedCharts(validCharts); | ||||||||||||||||||||
| } else { | ||||||||||||||||||||
| setSelectedCharts([]); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (validCharts.length > 0) { | ||||||||||||||||||||
| setMessageCharts(prev => { | ||||||||||||||||||||
| const newMap = new Map(prev); | ||||||||||||||||||||
| newMap.set(chatBot.latestResponse!.messageId!, validCharts); | ||||||||||||||||||||
|
Comment on lines
+195
to
+197
|
||||||||||||||||||||
| setMessageCharts(prev => { | |
| const newMap = new Map(prev); | |
| newMap.set(chatBot.latestResponse!.messageId!, validCharts); | |
| const messageId = chatBot.latestResponse.messageId; | |
| setMessageCharts(prev => { | |
| const newMap = new Map(prev); | |
| if (messageId) { | |
| newMap.set(messageId, validCharts); | |
| } |
Copilot
AI
Nov 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The chart retrieval logic is duplicated - it's already retrieved as chartsForThisMessage on line 208. Consider reusing that variable instead of calling messageCharts.get(props.item.id) again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
Date.now() + 2for message ID generation can lead to collisions if multiple messages are created in rapid succession. Consider using a more robust ID generation strategy like incrementing a counter or a UUID library.