From 90270572f1366b2a9e8b1127a911ef8dc805020d Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Tue, 26 Dec 2023 15:44:34 -0800 Subject: [PATCH] Look & Feel settings for profile pages --- pkg/controller/account/settings.go | 58 +++++ pkg/templates/templates.go | 1 + web/static/css/bulma-prefers-dark.css | 2 +- web/templates/account/friends.html | 3 + web/templates/account/profile.html | 3 +- web/templates/account/settings.html | 292 +++++++++++++++++++++++++- web/templates/account/user_notes.html | 3 + web/templates/partials/themes.html | 83 ++++++++ web/templates/photo/gallery.html | 5 + 9 files changed, 444 insertions(+), 6 deletions(-) create mode 100644 web/templates/partials/themes.html diff --git a/pkg/controller/account/settings.go b/pkg/controller/account/settings.go index 7e8500e..575d9e2 100644 --- a/pkg/controller/account/settings.go +++ b/pkg/controller/account/settings.go @@ -4,6 +4,7 @@ import ( "fmt" "net/http" nm "net/mail" + "regexp" "strconv" "strings" "time" @@ -35,6 +36,7 @@ func (t ChangeEmailToken) Delete() error { // User settings page. (/settings). func Settings() http.HandlerFunc { tmpl := templates.Must("account/settings.html") + var reHexColor = regexp.MustCompile(`^#[a-fA-F0-9]{6}$`) return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { vars := map[string]interface{}{ "Enum": config.ProfileEnums, @@ -119,6 +121,62 @@ func Settings() http.HandlerFunc { } session.Flash(w, r, "Profile settings updated!") + case "look": + hashtag = "#look" + + // Resetting all styles? + if r.PostFormValue("reset") == "true" { + // Blank out all profile fields. + for _, field := range []string{ + "hero-color-start", + "hero-color-end", + "hero-text-dark", + "card-title-bg", + "card-title-fg", + "card-link-color", + "card-lightness", + } { + user.SetProfileField(field, "") + } + + if err := user.Save(); err != nil { + session.FlashError(w, r, "Failed to save user to database: %s", err) + } + + session.Flash(w, r, "Profile look & feel reset to defaults!") + break + } + + // Set color preferences. + for _, field := range []string{ + "hero-color-start", + "hero-color-end", + "card-title-bg", + "card-title-fg", + "card-link-color", + } { + // Ensure valid. + value := r.PostFormValue(field) + if !reHexColor.Match([]byte(value)) { + value = "" + } + user.SetProfileField(field, value) + } + + // Set other fields. + for _, field := range []string{ + "hero-text-dark", + "card-lightness", + } { + value := r.PostFormValue(field) + user.SetProfileField(field, value) + } + + if err := user.Save(); err != nil { + session.FlashError(w, r, "Failed to save user to database: %s", err) + } + + session.Flash(w, r, "Profile look & feel updated!") case "preferences": hashtag = "#prefs" var ( diff --git a/pkg/templates/templates.go b/pkg/templates/templates.go index 2bbd676..654ee6c 100644 --- a/pkg/templates/templates.go +++ b/pkg/templates/templates.go @@ -134,6 +134,7 @@ var baseTemplates = []string{ config.TemplatePath + "/partials/user_avatar.html", config.TemplatePath + "/partials/like_modal.html", config.TemplatePath + "/partials/right_click.html", + config.TemplatePath + "/partials/themes.html", } // templates returns a template chain with the base templates preceding yours. diff --git a/web/static/css/bulma-prefers-dark.css b/web/static/css/bulma-prefers-dark.css index bd36ab0..6f685ad 100644 --- a/web/static/css/bulma-prefers-dark.css +++ b/web/static/css/bulma-prefers-dark.css @@ -4400,7 +4400,7 @@ .table td, .table th { - border: 1px solid #363636; + border-color: #363636; } .table td.is-white, diff --git a/web/templates/account/friends.html b/web/templates/account/friends.html index d1614e3..42fa83e 100644 --- a/web/templates/account/friends.html +++ b/web/templates/account/friends.html @@ -1,5 +1,8 @@ {{define "title"}}Friends of {{.User.Username}}{{end}} {{define "content"}} +
{{$Root := .}}