This commit is contained in:
lubiana 2025-07-24 11:35:37 +02:00
parent ba1f43fd8e
commit 0f9fbc9375
Signed by: lubiana
SSH key fingerprint: SHA256:vW1EA0fRR3Fw+dD/sM0K+x3Il2gSry6YRYHqOeQwrfk
15 changed files with 381 additions and 297 deletions

28
main.go
View file

@ -84,6 +84,25 @@ func setupDatabase() error {
return nil
}
func loadChecklistName(uuid string) (string, error) {
rows, err := db.Query(
`SELECT name FROM checklists WHERE uuid = ?`,
uuid)
if err != nil {
return "", err
}
defer rows.Close()
if rows.Next() {
var name string
err = rows.Scan(&name)
if err != nil {
return "", err
}
return name, nil
}
return "", fmt.Errorf("not found")
}
func loadChecklistItems(uuid string) ([]ChecklistItem, error) {
rows, err := db.Query(
`SELECT id, content, checked, parent_id FROM items WHERE checklist_uuid = ?`,
@ -427,13 +446,20 @@ func handleSSE(w http.ResponseWriter, r *http.Request) {
// Send full state on connect
items, err := loadChecklistItems(uuid)
if err == nil {
name, err2 := loadChecklistName(uuid)
if err == nil && err2 == nil {
msg, _ := json.Marshal(map[string]interface{}{
"type": "full_state",
"items": items,
})
fmt.Fprintf(w, "data: %s\n\n", msg)
flusher.Flush()
msg, _ = json.Marshal(map[string]interface{}{
"type": "checklist_name",
"name": name,
})
fmt.Fprintf(w, "data: %s\n\n", msg)
flusher.Flush()
}
// Forward events