mirror of
https://github.com/dergigi/boris.git
synced 2025-12-26 19:14:52 +01:00
- Add relayStatusService to track relay connections with 20-minute history - Add useRelayStatus hook for polling relay status updates - Create RelaySettings component to display active and recent relays - Update Settings and ThreePaneLayout to integrate relay status display - Shows relay connection status with visual indicators and timestamps
38 lines
899 B
TypeScript
38 lines
899 B
TypeScript
import { useState, useEffect } from 'react'
|
|
import { RelayPool } from 'applesauce-relay'
|
|
import { RelayStatus, updateAndGetRelayStatuses } from '../services/relayStatusService'
|
|
|
|
interface UseRelayStatusParams {
|
|
relayPool: RelayPool | null
|
|
pollingInterval?: number // in milliseconds
|
|
}
|
|
|
|
export function useRelayStatus({
|
|
relayPool,
|
|
pollingInterval = 5000
|
|
}: UseRelayStatusParams) {
|
|
const [relayStatuses, setRelayStatuses] = useState<RelayStatus[]>([])
|
|
|
|
useEffect(() => {
|
|
if (!relayPool) return
|
|
|
|
const updateStatuses = () => {
|
|
const statuses = updateAndGetRelayStatuses(relayPool)
|
|
setRelayStatuses(statuses)
|
|
}
|
|
|
|
// Initial update
|
|
updateStatuses()
|
|
|
|
// Poll for updates
|
|
const interval = setInterval(updateStatuses, pollingInterval)
|
|
|
|
return () => {
|
|
clearInterval(interval)
|
|
}
|
|
}, [relayPool, pollingInterval])
|
|
|
|
return relayStatuses
|
|
}
|
|
|