feat: real-time sidebar stats via session-changed events
Sidebar now refreshes stats when sessions are created or completed, not just on page navigation. Uses window event bus pattern (same as folder-changed events in codebase). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -31,6 +31,7 @@ export const sessionsApi = {
|
|||||||
|
|
||||||
async create(data: SessionCreate): Promise<Session> {
|
async create(data: SessionCreate): Promise<Session> {
|
||||||
const response = await apiClient.post<Session>('/sessions', data)
|
const response = await apiClient.post<Session>('/sessions', data)
|
||||||
|
window.dispatchEvent(new Event('session-changed'))
|
||||||
return response.data
|
return response.data
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -41,6 +42,7 @@ export const sessionsApi = {
|
|||||||
|
|
||||||
async complete(id: string, data: SessionComplete): Promise<Session> {
|
async complete(id: string, data: SessionComplete): Promise<Session> {
|
||||||
const response = await apiClient.post<Session>(`/sessions/${id}/complete`, data)
|
const response = await apiClient.post<Session>(`/sessions/${id}/complete`, data)
|
||||||
|
window.dispatchEvent(new Event('session-changed'))
|
||||||
return response.data
|
return response.data
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useState } from 'react'
|
import { useCallback, useEffect, useState } from 'react'
|
||||||
import { useLocation } from 'react-router-dom'
|
import { useLocation } from 'react-router-dom'
|
||||||
import {
|
import {
|
||||||
LayoutGrid, Network, Wrench, Clock, FileOutput, BarChart3,
|
LayoutGrid, Network, Wrench, Clock, FileOutput, BarChart3,
|
||||||
@@ -37,10 +37,20 @@ export function Sidebar() {
|
|||||||
|
|
||||||
const [stats, setStats] = useState<SidebarStatsResponse | null>(null)
|
const [stats, setStats] = useState<SidebarStatsResponse | null>(null)
|
||||||
|
|
||||||
|
const refreshStats = useCallback(() => {
|
||||||
|
sidebarApi.getStats().then(setStats).catch(() => {})
|
||||||
|
}, [])
|
||||||
|
|
||||||
// Fetch sidebar stats — refreshes on navigation
|
// Fetch sidebar stats — refreshes on navigation
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
sidebarApi.getStats().then(setStats).catch(() => {})
|
refreshStats()
|
||||||
}, [location.pathname])
|
}, [location.pathname, refreshStats])
|
||||||
|
|
||||||
|
// Refresh when sessions are created or completed
|
||||||
|
useEffect(() => {
|
||||||
|
window.addEventListener('session-changed', refreshStats)
|
||||||
|
return () => window.removeEventListener('session-changed', refreshStats)
|
||||||
|
}, [refreshStats])
|
||||||
|
|
||||||
const handleSidebarWheel = (e: React.WheelEvent<HTMLElement>) => {
|
const handleSidebarWheel = (e: React.WheelEvent<HTMLElement>) => {
|
||||||
const sidebar = e.currentTarget
|
const sidebar = e.currentTarget
|
||||||
|
|||||||
Reference in New Issue
Block a user