A platform for community discussion. Free, open, simple.
Revert "FEATURE: theme default option in user interface" (#34125)
Krzysztof Kotlarek8aa45fbbfa63
diff --git a/app/assets/javascripts/discourse/app/controllers/preferences/interface.js b/app/assets/javascripts/discourse/app/controllers/preferences/interface.jsindex 7baed1ac6f8..91365e41a52 100644--- a/app/assets/javascripts/discourse/app/controllers/preferences/interface.js+++ b/app/assets/javascripts/discourse/app/controllers/preferences/interface.js@@ -1,6 +1,7 @@import { tracked } from "@glimmer/tracking";import Controller, { inject as controller } from "@ember/controller";import { action, computed } from "@ember/object";+import { not, reads } from "@ember/object/computed";import { service } from "@ember/service";import { reload } from "discourse/helpers/page-reloader";import { popupAjaxError } from "discourse/lib/ajax-error";@@ -51,6 +52,12 @@ export default class InterfaceController extends Controller {@propertyEqual("model.id", "currentUser.id") isViewingOwnProfile;subpageTitle = i18n("user.preferences_nav.interface");+ @reads("userSelectableColorSchemes.length") showColorSchemeSelector;++ @not("currentSchemeCanBeSelected") showColorSchemeNoneItem;++ selectedColorSchemeNoneLabel = i18n("user.color_schemes.default_description");+init() {super.init(...arguments);this.set("selectedDarkColorSchemeId", this.session.userDarkSchemeId);@@ -243,14 +250,13 @@ export default class InterfaceController extends Controller {});}- @discourseComputed("userSelectableColorSchemes")- showColorSchemeSelector(lightSchemes) {- return lightSchemes && lightSchemes.length > 1;- }-@discourseComputed("userSelectableDarkColorSchemes")showDarkColorSchemeSelector(darkSchemes) {- return darkSchemes && darkSchemes.length > 1;+ // when a default dark scheme is set+ // dropdown has two items (disable / use site default)+ // but we show a checkbox in that case+ const minToShow = this.defaultDarkSchemeId > 0 ? 2 : 1;+ return darkSchemes && darkSchemes.length > minToShow;}get interfaceColorModes() {diff --git a/app/assets/javascripts/discourse/app/initializers/discourse-bootstrap.js b/app/assets/javascripts/discourse/app/initializers/discourse-bootstrap.jsindex 71eb3cf706e..e1823278491 100644--- a/app/assets/javascripts/discourse/app/initializers/discourse-bootstrap.js+++ b/app/assets/javascripts/discourse/app/initializers/discourse-bootstrap.js@@ -77,8 +77,9 @@ export default {session.highlightJsPath = setupData.highlightJsPath;session.svgSpritePath = setupData.svgSpritePath;- session.userColorSchemeId = parseInt(setupData.userColorSchemeId, 10);- session.userDarkSchemeId = parseInt(setupData.userDarkSchemeId, 10);+ session.userColorSchemeId =+ parseInt(setupData.userColorSchemeId, 10) || null;+ session.userDarkSchemeId = parseInt(setupData.userDarkSchemeId, 10) || -1;let iconList = setupData.svgIconList;if (isDevelopment() && iconList) {diff --git a/app/assets/javascripts/discourse/app/lib/color-scheme-picker.js b/app/assets/javascripts/discourse/app/lib/color-scheme-picker.jsindex aa297accd49..94b428e6376 100644--- a/app/assets/javascripts/discourse/app/lib/color-scheme-picker.js+++ b/app/assets/javascripts/discourse/app/lib/color-scheme-picker.js@@ -29,15 +29,36 @@ export function listColorSchemes(site, options = {}) {});const defaultLightColorScheme = site.get("default_light_color_scheme");- const defaultDarkColorScheme = site.get("default_dark_color_scheme");-- results.unshift({- id: -1,- name: `${i18n("user.color_schemes.default_description")}`,- colors: options.darkOnly- ? defaultDarkColorScheme?.colors || []- : defaultLightColorScheme?.colors || [],- });+ if (defaultLightColorScheme && !options.darkOnly) {+ const existing = schemes.findBy("id", defaultLightColorScheme.id);+ if (!existing) {+ results.unshift({+ id: defaultLightColorScheme.id,+ name: `${i18n("user.color_schemes.default_description")}`,+ theme_id: defaultLightColorScheme.theme_id,+ colors: defaultLightColorScheme.colors,+ });+ }+ }+ if (options.darkOnly) {+ const defaultDarkColorScheme = site.get("default_dark_color_scheme");+ if (defaultDarkColorScheme) {+ const existing = schemes.findBy("id", defaultDarkColorScheme.id);+ if (!existing) {+ results.unshift({+ id: defaultDarkColorScheme.id,+ name: `${i18n("user.color_schemes.default_description")}`,+ theme_id: defaultDarkColorScheme.theme_id,+ colors: defaultDarkColorScheme.colors,+ });+ }+ } else {+ results.unshift({+ id: -1,+ name: `${i18n("user.color_schemes.default_description")}`,+ });+ }+ }return results.length === 0 ? null : results;}diff --git a/app/assets/javascripts/discourse/app/templates/preferences/interface.gjs b/app/assets/javascripts/discourse/app/templates/preferences/interface.gjsindex af1c7e125ff..3af8954e780 100644--- a/app/assets/javascripts/discourse/app/templates/preferences/interface.gjs+++ b/app/assets/javascripts/discourse/app/templates/preferences/interface.gjs@@ -62,6 +62,10 @@ export default RouteTemplate(@content={{@controller.userSelectableColorSchemes}}@value={{@controller.selectedColorSchemeId}}@onChange={{@controller.loadColorScheme}}+ @options={{hash+ }}/></div></div>diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-preferences-interface-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-preferences-interface-test.jsindex f12079ac8b1..e6be44b4f92 100644--- a/app/assets/javascripts/discourse/tests/acceptance/user-preferences-interface-test.js+++ b/app/assets/javascripts/discourse/tests/acceptance/user-preferences-interface-test.js@@ -65,6 +65,27 @@ acceptance("User Preferences - Interface", function (needs) {removeCookie("text_size");});+ test("shows light color scheme default option when theme's color scheme is not user selectable", async function (assert) {+ let site = Site.current();+ site.set("user_themes", [+ { theme_id: 1, name: "Cool Theme", color_scheme_id: null },+ ]);++ site.set("user_color_schemes", [{ id: 2, name: "Cool Breeze" }]);++ await visit("/u/eviltrout/preferences/interface");+ assert.dom(".light-color-scheme").exists("has regular dropdown");++ assert.strictEqual(+ selectKit(".light-color-scheme .select-kit").header().value(),+ null+ );+ assert.strictEqual(+ selectKit(".light-color-scheme .select-kit").header().label(),+ i18n("user.color_schemes.default_description")+ );+ });+skip("shows no default option for light scheme when theme's color scheme is user selectable", async function (assert) {let meta = document.createElement("meta");meta.name = "discourse_theme_id";@@ -181,15 +202,12 @@ acceptance();});- test("always display 'Theme default'", async function (assert) {+ test("display 'Theme default' when default color scheme is not marked as selectable", async function (assert) {let meta = document.createElement("meta");meta.name = "discourse_theme_id";meta.content = "1";document.getElementsByTagName("head")[0].appendChild(meta);- let session = Session.current();- session.userColorSchemeId = -1;-let site = Site.current();site.set("user_themes", [{ theme_id: 1, name: "A Theme", color_scheme_id: 2, default: true },@@ -201,14 +219,14 @@ acceptance(assert.dom(".light-color-scheme").exists("has regular dropdown");const dropdownObject = selectKit(".light-color-scheme .select-kit");- assert.strictEqual(dropdownObject.header().value(), "-1");+ assert.strictEqual(dropdownObject.header().value(), null);assert.strictEqual(dropdownObject.header().label(),i18n("user.color_schemes.default_description"));await dropdownObject.expand();- assert.strictEqual(dropdownObject.rows().length, 2);+ assert.strictEqual(dropdownObject.rows().length, 1);document.querySelector("meta[name='discourse_theme_id']").remove();});@@ -284,8 +302,8 @@ acceptance(// dark schemeawait selectKit(".dark-color-scheme .combobox").expand();assert.true(- selectKit(".dark-color-scheme .combobox").rowByValue(3).exists(),- "user selectable dark scheme is included"+ selectKit(".dark-color-scheme .combobox").rowByValue(1).exists(),+ "default dark scheme is included");await click("button.undo-preview");diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rbindex 67f72dbcfb8..942717000e3 100644--- a/app/helpers/application_helper.rb+++ b/app/helpers/application_helper.rb@@ -566,16 +566,14 @@ module ApplicationHelper@stylesheet_manager = Stylesheet::Manager.new(theme_id: theme_id)end- def user_scheme_id- return @user_scheme_id if defined?(@user_scheme_id)- scheme_id = cookies[:color_scheme_id] || current_user&.user_option&.color_scheme_id- @user_scheme_id = scheme_id if scheme_id && ColorScheme.find_by_id(scheme_id)- end-def scheme_idreturn @scheme_id if defined?(@scheme_id)- return user_scheme_id if user_scheme_id+ custom_user_scheme_id = cookies[:color_scheme_id] || current_user&.user_option&.color_scheme_id+ if custom_user_scheme_id && ColorScheme.find_by_id(custom_user_scheme_id)+ return custom_user_scheme_id+ end+return if theme_id.blank?if SiteSetting.use_overhauled_theme_color_palette@@ -584,17 +582,11 @@ module ApplicationHelper@scheme_id ||= Theme.where(id: theme_id).pick(:color_scheme_id)end- def user_dark_scheme_id- return @user_dark_scheme_id if defined?(@user_dark_scheme_id)- scheme_id = cookies[:dark_scheme_id] || current_user&.user_option&.dark_scheme_id- @user_dark_scheme_id = scheme_id if scheme_id && ColorScheme.find_by_id(scheme_id)- end-def dark_scheme_idif SiteSetting.use_overhauled_theme_color_palettescheme_idelse- user_dark_scheme_id ||+ cookies[:dark_scheme_id] || current_user&.user_option&.dark_scheme_id ||(theme_id ? Theme.find_by_id(theme_id) : Theme.find_default)&.dark_color_scheme_id || -1endend@@ -840,8 +832,8 @@ module ApplicationHelpersvg_sprite_path: SvgSprite.path(theme_id),enable_js_error_reporting: GlobalSetting.enable_js_error_reporting,color_scheme_is_dark: dark_color_scheme?,- user_color_scheme_id: user_scheme_id || -1,- user_dark_scheme_id: user_dark_scheme_id || -1,+ user_color_scheme_id: scheme_id,+ user_dark_scheme_id: dark_scheme_id,}if Rails.env.development?diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rbindex a7f412e7a3c..bc6b649ef70 100644--- a/spec/helpers/application_helper_spec.rb+++ b/spec/helpers/application_helper_spec.rb@@ -868,7 +868,7 @@ RSpec.describe ApplicationHelper docontext "with dark scheme with user option and/or cookies" dobefore do- user.user_option.interface_color_mode = UserOption::LIGHT_MODE+ user.user_option.dark_scheme_id = -1user.user_option.save!helper.request.env[Auth::DefaultCurrentUserProvider::CURRENT_USER_KEY] = user@new_cs = Fabricate(:color_scheme, name: "Custom Color Scheme")@@ -884,10 +884,7 @@ RSpec.describe ApplicationHelper doendit "returns user-selected dark color scheme stylesheet" do- user.user_option.update!(- dark_scheme_id: @new_cs.id,- interface_color_mode: UserOption::AUTO_MODE,- )+ user.user_option.update!(dark_scheme_id: @new_cs.id)color_stylesheets = helper.discourse_color_scheme_stylesheetsexpect(color_stylesheets).to include("(prefers-color-scheme: dark)")@@ -895,7 +892,6 @@ RSpec.describe ApplicationHelper doendit "respects cookie value over user option for dark color scheme" do- user.user_option.update!(interface_color_mode: UserOption::AUTO_MODE)helper.request.cookies["dark_scheme_id"] = @new_cs.idcolor_stylesheets = helper.discourse_color_scheme_stylesheetsdiff --git a/spec/system/interface_color_selector_spec.rb b/spec/system/interface_color_selector_spec.rbindex c53bf922c91..647195e770e 100644--- a/spec/system/interface_color_selector_spec.rb+++ b/spec/system/interface_color_selector_spec.rb@@ -62,7 +62,7 @@ describe "Interface color selector", type: :system doendit "is not available if the user uses the same scheme for dark mode as the light mode" do- user.user_option.update!(color_scheme_id: light_scheme.id, dark_scheme_id: light_scheme.id)+ user.user_option.update!(color_scheme_id: light_scheme.id, dark_scheme_id: -1)sign_in(user)visit("/")diff --git a/spec/system/page_objects/pages/user_preferences_interface.rb b/spec/system/page_objects/pages/user_preferences_interface.rbindex 4ffb44a49fd..3b98a7a75d3 100644--- a/spec/system/page_objects/pages/user_preferences_interface.rb+++ b/spec/system/page_objects/pages/user_preferences_interface.rb@@ -24,28 +24,6 @@ module PageObjectspage.find('.dark-mode input[type="checkbox"]')end- def light_scheme_dropdown- PageObjects::Components::SelectKit.new(".light-color-scheme .select-kit")- end-- def dark_scheme_dropdown- PageObjects::Components::SelectKit.new(".dark-color-scheme .select-kit")- end-- def has_light_scheme_css?(color_scheme)- expect(page).to have_css(- "link.light-scheme[data-scheme-id=\"#{color_scheme.id}\"]",- visible: false,- )- end-- def has_dark_scheme_css?(color_scheme)- expect(page).to have_css(- "link.dark-scheme[data-scheme-id=\"#{color_scheme.id}\"]",- visible: false,- )- end-def color_mode_dropdownPageObjects::Components::SelectKit.new(".interface-color-mode .select-kit")enddiff --git a/spec/system/user_page/user_preferences_interface_spec.rb b/spec/system/user_page/user_preferences_interface_spec.rbindex ab6d5815e26..7cd9eeb8c10 100644--- a/spec/system/user_page/user_preferences_interface_spec.rb+++ b/spec/system/user_page/user_preferences_interface_spec.rb@@ -67,7 +67,6 @@ describe "User preferences | Interface", type: :system dobefore dodark = ColorScheme.find_by(base_scheme_id: "Dark")ColorScheme.where.not(id: dark.id).destroy_all- dark.update!(user_selectable: false)user.user_option.update!(dark_scheme_id: dark.id, theme_ids: [SiteSetting.default_theme_id])end@@ -97,74 +96,6 @@ describe "User preferences | Interface", type: :system dobefore { SiteSetting.interface_color_selector = "sidebar_footer" }context "when changing own preferences" do- fab!(:color_scheme_light_1) { Fabricate(:color_scheme, base_scheme_id: "Light") }- fab!(:color_scheme_dark_1) { Fabricate(:color_scheme, base_scheme_id: "Dark") }- fab!(:color_scheme_light_2) { Fabricate(:color_scheme, base_scheme_id: "Light") }- fab!(:color_scheme_dark_2) { Fabricate(:color_scheme, base_scheme_id: "Dark") }- fab!(:color_scheme_light_3) do- Fabricate(:color_scheme, base_scheme_id: "Light", user_selectable: true)- end- fab!(:color_scheme_dark_3) do- Fabricate(:color_scheme, base_scheme_id: "Dark", user_selectable: true)- end-- it "has and can change default color scheme for light and dark" do- Theme.find_default.update!(- color_scheme: color_scheme_light_1,- dark_color_scheme: color_scheme_dark_1,- )- user_preferences_interface_page.visit(user)-- expect(user_preferences_interface_page.light_scheme_dropdown).to have_selected_name(- I18n.t("js.user.color_schemes.default_description"),- )- expect(user_preferences_interface_page.light_scheme_dropdown).to have_selected_value(-1)- expect(user_preferences_interface_page.dark_scheme_dropdown).to have_selected_name(- I18n.t("js.user.color_schemes.default_description"),- )- expect(user_preferences_interface_page.dark_scheme_dropdown).to have_selected_value(-1)- expect(user_preferences_interface_page).to have_light_scheme_css(color_scheme_light_1)- expect(user_preferences_interface_page).to have_dark_scheme_css(color_scheme_dark_1)-- Theme.find_default.update!(- color_scheme: color_scheme_light_2,- dark_color_scheme: color_scheme_dark_2,- )- user_preferences_interface_page.visit(user)-- expect(user_preferences_interface_page.light_scheme_dropdown).to have_selected_name(- I18n.t("js.user.color_schemes.default_description"),- )- expect(user_preferences_interface_page.light_scheme_dropdown).to have_selected_value(-1)- expect(user_preferences_interface_page.dark_scheme_dropdown).to have_selected_name(- I18n.t("js.user.color_schemes.default_description"),- )- expect(user_preferences_interface_page.dark_scheme_dropdown).to have_selected_value(-1)- expect(user_preferences_interface_page).to have_light_scheme_css(color_scheme_light_2)- expect(user_preferences_interface_page).to have_dark_scheme_css(color_scheme_dark_2)-- user_preferences_interface_page.light_scheme_dropdown.expand- user_preferences_interface_page.light_scheme_dropdown.select_row_by_value(- color_scheme_light_3.id,- )- user_preferences_interface_page.dark_scheme_dropdown.expand- user_preferences_interface_page.dark_scheme_dropdown.select_row_by_value(- color_scheme_dark_3.id,- )- user_preferences_interface_page.save_changes-- user_preferences_interface_page.visit(user)-- expect(user_preferences_interface_page.light_scheme_dropdown).to have_selected_name(- color_scheme_light_3.name,- )- expect(user_preferences_interface_page.dark_scheme_dropdown).to have_selected_name(- color_scheme_dark_3.name,- )- expect(user_preferences_interface_page).to have_light_scheme_css(color_scheme_light_3)- expect(user_preferences_interface_page).to have_dark_scheme_css(color_scheme_dark_3)- end-it "can change the color mode for the current device only" douser_preferences_interface_page.visit(user)diff --git a/themes/horizon/spec/system/user_color_palette_selector_spec.rb b/themes/horizon/spec/system/user_color_palette_selector_spec.rbindex c0237867349..f65aa0d29d2 100644--- a/themes/horizon/spec/system/user_color_palette_selector_spec.rb+++ b/themes/horizon/spec/system/user_color_palette_selector_spec.rb@@ -19,14 +19,7 @@ describe "Horizon theme | User color palette selector", type: :system dolet(:marigold_palette) { theme.color_schemes.find_by(name: "Marigold") }let(:marigold_palette_dark) { theme.color_schemes.find_by(name: "Marigold Dark") }- before do- SiteSetting.interface_color_selector = "sidebar_footer"- SiteSetting.default_theme_id = theme.id- theme.update!(- color_scheme_id: marigold_palette.id,- dark_color_scheme_id: marigold_palette_dark.id,- )- end+ before { SiteSetting.interface_color_selector = "sidebar_footer" }it "does not show the sidebar button if there are no user-selectable color palettes" doColorScheme.update_all(user_selectable: false)