fix: enabled toggle — list-row click + edit-form save

Two bugs in the channel-enabled affordance:

1. List-row toggle was a static span with no handler; the row's
   row-link overlay swallowed every click and routed to /edit. Add
   POST /settings/notifications/{id}/toggle backed by a new store
   method SetNotificationChannelEnabled, and turn the row toggle
   into an htmx-driven button that swaps in the new state. Use
   event.stopPropagation() on the toggle so it beats the row link.

2. Edit-form toggle visually flipped but the underlying checkbox
   reverted: the visual span lives inside the <label>, so clicking
   it fired the inline JS handler AND the label's native
   checkbox-toggle, cancelling out. Bind to the checkbox 'change'
   event instead and let the label do the toggling — the JS just
   mirrors check.checked into the .on class.
This commit is contained in:
2026-05-04 22:21:45 +01:00
parent 373d74cdaf
commit d830635a2e
4 changed files with 85 additions and 5 deletions
+16
View File
@@ -77,6 +77,22 @@ func (s *Store) UpdateNotificationChannel(ctx context.Context, ch NotificationCh
return nil
}
// SetNotificationChannelEnabled flips the enabled flag without
// touching kind/name/config — used by the inline list-row toggle.
func (s *Store) SetNotificationChannelEnabled(ctx context.Context, id string, enabled bool, when time.Time) error {
v := 0
if enabled {
v = 1
}
_, err := s.db.ExecContext(ctx,
`UPDATE notification_channels SET enabled = ?, updated_at = ? WHERE id = ?`,
v, when.UTC().Format(time.RFC3339Nano), id)
if err != nil {
return fmt.Errorf("store: set channel enabled: %w", err)
}
return nil
}
// DeleteNotificationChannel removes a channel row; cascades to notification_log.
func (s *Store) DeleteNotificationChannel(ctx context.Context, id string) error {
_, err := s.db.ExecContext(ctx,