refactor: simplify toggle handlers to return 204 No Content
Remove empty toggle templates (length-toggle.html, theme-toggle.html, logo-toggle.html) that were just placeholders. The frontend uses hx-swap="none" so the response body was always ignored anyway. Now the handlers: - Set the preference cookie - Return 204 No Content immediately - Hyperscript handles the UI state toggle on the frontend This removes unnecessary template rendering overhead and cleans up dead code. Tests updated to expect 204 instead of 200.
This commit is contained in:
@@ -60,8 +60,9 @@ func TestToggleLength(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
handler.ToggleLength(w, req)
|
||||
|
||||
if w.Code != http.StatusOK {
|
||||
t.Errorf("Expected status OK, got %d", w.Code)
|
||||
// 204 No Content - frontend uses hx-swap="none" so response body is ignored
|
||||
if w.Code != http.StatusNoContent {
|
||||
t.Errorf("Expected status No Content (204), got %d", w.Code)
|
||||
}
|
||||
|
||||
// Check that response sets the toggled cookie
|
||||
@@ -131,8 +132,9 @@ func TestToggleIcons(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
handler.ToggleIcons(w, req)
|
||||
|
||||
if w.Code != http.StatusOK {
|
||||
t.Errorf("Expected status OK, got %d", w.Code)
|
||||
// 204 No Content - frontend uses hx-swap="none" so response body is ignored
|
||||
if w.Code != http.StatusNoContent {
|
||||
t.Errorf("Expected status No Content (204), got %d", w.Code)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -253,8 +255,9 @@ func TestToggleTheme(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
handler.ToggleTheme(w, req)
|
||||
|
||||
if w.Code != http.StatusOK {
|
||||
t.Errorf("Expected status OK, got %d", w.Code)
|
||||
// 204 No Content - frontend uses hx-swap="none" so response body is ignored
|
||||
if w.Code != http.StatusNoContent {
|
||||
t.Errorf("Expected status No Content (204), got %d", w.Code)
|
||||
}
|
||||
|
||||
// Verify theme cookie was set
|
||||
|
||||
Reference in New Issue
Block a user