From f95ae87385f431d9e70d0afb6aa0ad514eb55c30 Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Mon, 27 May 2024 16:41:13 +0000 Subject: [PATCH] theme dropdown --- public/style.css | 2 +- public/utils.js | 2 +- routes.go | 19 +++++++++++-------- templates/settings.html | 24 ++++++++---------------- 4 files changed, 21 insertions(+), 26 deletions(-) diff --git a/public/style.css b/public/style.css index 5b106a2..0be05bb 100644 --- a/public/style.css +++ b/public/style.css @@ -974,7 +974,7 @@ form.create input[type=file], form.create select { } .preferences label{ display: inline-block; - width: 150px; + width: 170px; margin-right: 5px; text-align: right; diff --git a/public/utils.js b/public/utils.js index dc82a3d..c82db03 100644 --- a/public/utils.js +++ b/public/utils.js @@ -387,7 +387,7 @@ function saveSettings(e) { var targ = e.currentTarget || e.srcElement || e; var data = new FormData(targ) e.preventDefault() - request(targ.target, data, function(res) { + request(targ.dataset.target, data, function(res) { ["endlessScrolling", "autoLoad", "markRead"].map(function(x) { localStorage.setItem(x, data.get(x)=="on") }) diff --git a/routes.go b/routes.go index 678768d..fb7a2f6 100644 --- a/routes.go +++ b/routes.go @@ -778,15 +778,18 @@ func Settings(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { deleteCookie(w, state.Host, name) setCookie(w, "", name, r.FormValue(name)) } - state.Dark = new(bool) - dark := r.FormValue("darkmode") - undark := r.FormValue("undarkmode") - if dark == "0" && undark != "0" { - } else if dark == "0" && undark == "0" { - setCookie(w, "", "Dark", "0") - } else { + dark := true + switch r.FormValue("Dark") { + case "1": setCookie(w, "", "Dark", "1") - *state.Dark = true + state.Dark = &dark + case "0": + setCookie(w, "", "Dark", "0") + dark = false + state.Dark = &dark + default: + deleteCookie(w, "", "Dark") + state.Dark = nil } if r.FormValue("shownsfw") != "" { setCookie(w, "", "ShowNSFW", "1") diff --git a/templates/settings.html b/templates/settings.html index 1d759cb..9d807df 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -60,7 +60,7 @@
{{.Error}}
{{ end }} {{ end }} -
+
-
- - - -
-
- - {{ if not .Dark }} - - {{ end }} - +
+ +