wip
This commit is contained in:
parent
ba1f43fd8e
commit
0f9fbc9375
15 changed files with 381 additions and 297 deletions
28
main.go
28
main.go
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue