feat: add server-side theme cookie with dropdown selector (no JS)
- Add theme POST handler that sets HttpOnly cookie - Update preferences page to use <select> dropdown instead of JS buttons - Theme cookie set on POST /preferences with theme parameter - Theme read from cookie on all page renders - No JavaScript required for theme selection Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
056d2d1175
commit
fe0c7e8dc8
4 changed files with 47 additions and 13 deletions
|
|
@ -55,6 +55,8 @@ type PageData struct {
|
|||
PageNumbers []PageNumber
|
||||
ShowHeader bool
|
||||
IsImageSearch bool
|
||||
// Theme is the user's selected theme (light/dark) from cookie
|
||||
Theme string
|
||||
// New fields for three-column layout
|
||||
Categories []string
|
||||
CategoryIcons map[string]string
|
||||
|
|
@ -280,9 +282,9 @@ func FromResponse(resp contracts.SearchResponse, query string, pageno int, activ
|
|||
}
|
||||
|
||||
// RenderIndex renders the homepage (search box only).
|
||||
func RenderIndex(w http.ResponseWriter, sourceURL string) error {
|
||||
func RenderIndex(w http.ResponseWriter, sourceURL, theme string) error {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
return tmplIndex.ExecuteTemplate(w, "base", PageData{ShowHeader: true, SourceURL: sourceURL})
|
||||
return tmplIndex.ExecuteTemplate(w, "base", PageData{ShowHeader: true, SourceURL: sourceURL, Theme: theme})
|
||||
}
|
||||
|
||||
// RenderSearch renders the full search results page (with base layout).
|
||||
|
|
@ -326,8 +328,8 @@ func RenderSearchAuto(w http.ResponseWriter, r *http.Request, data PageData) err
|
|||
}
|
||||
|
||||
// RenderPreferences renders the full preferences page.
|
||||
func RenderPreferences(w http.ResponseWriter, sourceURL string) error {
|
||||
func RenderPreferences(w http.ResponseWriter, sourceURL, theme string) error {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
return tmplPreferences.ExecuteTemplate(w, "base", PageData{ShowHeader: true, SourceURL: sourceURL})
|
||||
return tmplPreferences.ExecuteTemplate(w, "base", PageData{ShowHeader: true, SourceURL: sourceURL, Theme: theme})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue