feat: add connection status indicator with SSE heartbeat
All checks were successful
CI / Deploy / test (pull_request) Successful in 14s
CI / Deploy / lint (pull_request) Successful in 25s
CI / Deploy / deploy (pull_request) Has been skipped

- Add ConnectionIndicator component showing green/red dot
- Send lastPing signal every 15 seconds via SSE
- Indicator turns red if no ping received in 20 seconds
- Gives users confidence the live connection is active
This commit is contained in:
Ryan Hamamura
2026-03-03 09:53:20 -10:00
parent ffbff8cca5
commit 90a3d9e5a5
6 changed files with 81 additions and 4 deletions

28
sse/signals.go Normal file
View File

@@ -0,0 +1,28 @@
// Package sse provides helpers for SSE signal handling.
package sse
import (
"encoding/json"
"time"
"github.com/starfederation/datastar-go/datastar"
)
// Signals holds client-side state managed via SSE.
type Signals struct {
LastPing int64 `json:"lastPing,omitempty"`
}
// SendPing sends a heartbeat signal with the current timestamp.
func SendPing(sse *datastar.ServerSentEventGenerator) error {
return PatchSignals(sse, Signals{LastPing: time.Now().UnixMilli()})
}
// PatchSignals sends a signals patch to the client.
func PatchSignals(sse *datastar.ServerSentEventGenerator, s Signals) error {
data, err := json.Marshal(s)
if err != nil {
return err
}
return sse.PatchSignals(data)
}