From 2024031a7a9e7b4f61e38676c5285a588f952f7b Mon Sep 17 00:00:00 2001 From: mhughes9 Date: Wed, 26 Feb 2025 18:46:51 +0000 Subject: [PATCH] Simplify pronouns in user settings (#6835) The main change here is to use `datalist` for pronouns This supports (see also docs[1]): * Displaying the value already set by the user (if any), otherwise * Presenting a list of common options to the user, and * Allowing them to freely enter any value This setup requires no additional JS and resolves[2]. This is different from the previous flow which used, if JS was available: * A menu for a default 'recognised' set of pronouns, and if the user wanted another value: * An extra text div if the user wanted to enter custom pronouns Without JS enabled both the menu and the custom text div would always be displayed. This change means there's no longer a distinction between 'custom' and 'recognised' pronouns (this difference looks to have only been made in code, and not in any data models). Link: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/datalist [1] Link: https://codeberg.org/forgejo/forgejo/issues/6774 [2] Co-authored-by: Matthew Hughes Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6835 Reviewed-by: Gusted Reviewed-by: Otto Co-authored-by: mhughes9 Co-committed-by: mhughes9 --- options/locale/locale_en-US.ini | 2 -- routers/web/user/setting/profile.go | 8 ++--- templates/user/settings/profile.tmpl | 38 ++++----------------- tests/e2e/user-settings.test.e2e.ts | 16 ++++++--- web_src/js/features/user-settings.js | 50 ---------------------------- web_src/js/index.js | 2 -- 6 files changed, 21 insertions(+), 95 deletions(-) delete mode 100644 web_src/js/features/user-settings.js diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 22c726a793..dfae2b7b6f 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -761,8 +761,6 @@ full_name = Full name website = Website location = Location pronouns = Pronouns -pronouns_custom = Custom -pronouns_custom_label = Custom pronouns pronouns_unspecified = Unspecified update_theme = Change theme update_profile = Update profile diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index 33b2919d69..7d6a678c60 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -12,7 +12,6 @@ import ( "net/http" "os" "path/filepath" - "slices" "strings" "time" @@ -42,8 +41,7 @@ const ( tplSettingsRepositories base.TplName = "user/settings/repos" ) -// must be kept in sync with `web_src/js/features/user-settings.js` -var recognisedPronouns = []string{"", "he/him", "she/her", "they/them", "it/its", "any pronouns"} +var commonPronouns = []string{"he/him", "she/her", "they/them", "it/its", "any pronouns"} // Profile render user's profile page func Profile(ctx *context.Context) { @@ -51,8 +49,8 @@ func Profile(ctx *context.Context) { ctx.Data["PageIsSettingsProfile"] = true ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice() ctx.Data["DisableGravatar"] = setting.Config().Picture.DisableGravatar.Value(ctx) - ctx.Data["PronounsAreCustom"] = !slices.Contains(recognisedPronouns, ctx.Doer.Pronouns) ctx.Data["CooldownPeriod"] = setting.Service.UsernameCooldownPeriod + ctx.Data["CommonPronouns"] = commonPronouns ctx.HTML(http.StatusOK, tplSettingsProfile) } @@ -63,8 +61,8 @@ func ProfilePost(ctx *context.Context) { ctx.Data["PageIsSettingsProfile"] = true ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice() ctx.Data["DisableGravatar"] = setting.Config().Picture.DisableGravatar.Value(ctx) - ctx.Data["PronounsAreCustom"] = !slices.Contains(recognisedPronouns, ctx.Doer.Pronouns) ctx.Data["CooldownPeriod"] = setting.Service.UsernameCooldownPeriod + ctx.Data["CommonPronouns"] = commonPronouns if ctx.HasError() { ctx.HTML(http.StatusOK, tplSettingsProfile) diff --git a/templates/user/settings/profile.tmpl b/templates/user/settings/profile.tmpl index 503a977158..3bc8800a76 100644 --- a/templates/user/settings/profile.tmpl +++ b/templates/user/settings/profile.tmpl @@ -30,38 +30,14 @@ -