Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions chat_diff.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--- components/chat.tsx
+++ components/chat.tsx
@@ -40,6 +40,7 @@
const [isSubmitting, setIsSubmitting] = useState(false)
const [suggestions, setSuggestions] = useState<PartialRelated | null>(null)
const chatPanelRef = useRef<ChatPanelRef>(null);
+ const lastRefreshedMessageIdRef = useRef<string | null>(null)

const handleAttachment = () => {
chatPanelRef.current?.handleAttachmentClick();
@@ -76,10 +77,15 @@
}, [id, path, messages])

useEffect(() => {
- if (aiState.messages[aiState.messages.length - 1]?.type === 'response') {
- // Refresh the page to chat history updates
+ // Find the last message of type 'response'
+ const responseMessage = [...aiState.messages]
+ .reverse()
+ .find(m => m.type === 'response')
+
+ if (responseMessage && responseMessage.id !== lastRefreshedMessageIdRef.current) {
+ // Refresh the page to update chat history in the sidebar
+ lastRefreshedMessageIdRef.current = responseMessage.id
router.refresh()
}
}, [aiState, router])
19 changes: 13 additions & 6 deletions components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export function Chat({ id }: ChatProps) {
const [isSubmitting, setIsSubmitting] = useState(false)
const [suggestions, setSuggestions] = useState<PartialRelated | null>(null)
const chatPanelRef = useRef<ChatPanelRef>(null);
const lastRefreshedMessageIdRef = useRef<string | null>(null)

const handleAttachment = () => {
chatPanelRef.current?.handleAttachmentClick();
Expand Down Expand Up @@ -76,8 +77,14 @@ export function Chat({ id }: ChatProps) {
}, [id, path, messages])

useEffect(() => {
if (aiState.messages[aiState.messages.length - 1]?.type === 'response') {
// Refresh the page to chat history updates
// Find the last message of type 'response'
const responseMessage = [...aiState.messages]
.reverse()
.find(m => m.type === 'response')

if (responseMessage && responseMessage.id !== lastRefreshedMessageIdRef.current) {
// Refresh the page to update chat history in the sidebar
lastRefreshedMessageIdRef.current = responseMessage.id
router.refresh()
}
}, [aiState, router])
Expand Down Expand Up @@ -106,7 +113,7 @@ export function Chat({ id }: ChatProps) {
// Mobile layout
if (isMobile) {
return (
<MapDataProvider> {/* Add Provider */}
<>
<HeaderSearchButton />
<div className="mobile-layout-container">
<div className="mobile-map-section">
Expand Down Expand Up @@ -160,13 +167,13 @@ export function Chat({ id }: ChatProps) {
)}
</div>
</div>
</MapDataProvider>
</>
);
}

// Desktop layout
return (
<MapDataProvider> {/* Add Provider */}
<>
<HeaderSearchButton />
<div className="flex justify-start items-start">
{/* This is the new div for scrolling */}
Expand Down Expand Up @@ -224,6 +231,6 @@ export function Chat({ id }: ChatProps) {
{activeView ? <SettingsView /> : isUsageOpen ? <UsageView /> : <MapProvider />}
</div>
</div>
</MapDataProvider>
</>
);
}
2 changes: 1 addition & 1 deletion components/graph-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { StreamableValue, useStreamableValue } from 'ai/rsc'
const COLORS = ['#0088FE', '#00C49F', '#FFBB28', '#FF8042', '#8884d8', '#82ca9d']

interface GraphSectionProps {
result: DataAnalysisResult | string | StreamableValue<DataAnalysisResult>
result: DataAnalysisResult | string | StreamableValue<DataAnalysisResult> | StreamableValue<string>
}

export function GraphSection({ result }: GraphSectionProps) {
Expand Down
2 changes: 1 addition & 1 deletion components/map/mapbox-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ export const Mapbox: React.FC<{ position?: { latitude: number; longitude: number
geolocationWatchIdRef.current = null
}
}
}, [setMap, setIsMapLoaded, captureMapCenter, handleUserInteraction, stopRotation, position?.latitude, position?.longitude, mapData.cameraState])
}, [setMap, setIsMapLoaded, captureMapCenter, handleUserInteraction, stopRotation])

// Handle map mode changes
useEffect(() => {
Expand Down