Display only current project statistics in statusline. (#3)

This commit is contained in:
2025-12-18 22:36:37 +00:00
parent 2f303454af
commit ed8b5e92e1
8 changed files with 184 additions and 48 deletions
+12 -3
View File
@@ -1,4 +1,4 @@
import { ref, onMounted, onUnmounted, watch } from 'vue'
import { ref, onMounted, onUnmounted, watch, type Ref } from 'vue'
import type { Stats } from '@/types'
import { fetchStats } from '@/utils/api'
import { useSSE } from './useSSE'
@@ -6,7 +6,7 @@ import { useSSE } from './useSSE'
// Fallback poll interval when SSE is disconnected
const FALLBACK_POLL_INTERVAL = 10000 // 10 seconds
export function useStats() {
export function useStats(projectRef?: Ref<string | null>) {
const stats = ref<Stats | null>(null)
const loading = ref(false)
const error = ref<string | null>(null)
@@ -21,7 +21,8 @@ export function useStats() {
error.value = null
try {
stats.value = await fetchStats()
const project = projectRef?.value ?? null
stats.value = await fetchStats(project)
} catch (err) {
error.value = err instanceof Error ? err.message : 'Failed to fetch stats'
console.error('[Stats] Error:', err)
@@ -54,6 +55,14 @@ export function useStats() {
}
})
// Watch for project filter changes
if (projectRef) {
watch(projectRef, () => {
console.log('[Stats] Project filter changed, refreshing stats')
refresh()
})
}
// Switch between SSE-driven and fallback polling based on connection status
watch(isConnected, (connected) => {
if (connected) {