make settings global

This commit is contained in:
Ryan Stafford 2023-07-07 12:27:44 -04:00
parent 7760d7c226
commit 2a9a54f595

View file

@ -514,7 +514,8 @@ func Settings(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
switch r.Method {
case "POST":
for _, name := range []string{"DefaultSortType", "DefaultListingType"} {
setCookie(w, state.Host, name, r.FormValue(name))
deleteCookie(w, state.Host, name)
setCookie(w, "", name, r.FormValue(name))
}
if r.FormValue("darkmode") != "" {
setCookie(w, "", "Dark", "1")
@ -525,10 +526,11 @@ func Settings(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
state.Dark = false
}
if r.FormValue("shownsfw") != "" {
setCookie(w, state.Host, "ShowNSFW", "1")
setCookie(w, "", "ShowNSFW", "1")
state.ShowNSFW = true
} else {
deleteCookie(w, state.Host, "ShowNSFW")
deleteCookie(w, "", "ShowNSFW")
state.ShowNSFW = false
}
state.Listing = r.FormValue("DefaultListingType")
@ -1024,7 +1026,7 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
}
case "shownsfw":
if r.FormValue("submit") == "continue" {
setCookie(w, state.Host, "ShowNSFW", "1")
setCookie(w, "", "ShowNSFW", "1")
} else {
r.URL.Path = "/" + state.Host
}