From 3d79f9fd88ab2784b292c8eafc46070472b2a4c9 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 1 Dec 2024 03:04:09 +0300 Subject: [PATCH] Make a generic preferred color scheme method --- app/controllers/application_controller.rb | 6 +++--- app/views/layouts/_head.html.erb | 2 +- app/views/layouts/site.html.erb | 4 +++- app/views/preferences/edit.html.erb | 2 +- app/views/preferences/show.html.erb | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 56d9a6763..5bfec4ab6 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -281,15 +281,15 @@ class ApplicationController < ActionController::Base end end - def preferred_site_color_scheme + def preferred_color_scheme(subject) if current_user - current_user.preferences.find_by(:k => "site.color_scheme")&.v || "auto" + current_user.preferences.find_by(:k => "#{subject}.color_scheme")&.v || "auto" else "auto" end end - helper_method :preferred_editor, :preferred_site_color_scheme + helper_method :preferred_editor, :preferred_color_scheme def update_totp if Settings.key?(:totp_key) diff --git a/app/views/layouts/_head.html.erb b/app/views/layouts/_head.html.erb index 8cab52223..bab19c217 100644 --- a/app/views/layouts/_head.html.erb +++ b/app/views/layouts/_head.html.erb @@ -5,7 +5,7 @@ <%= javascript_include_tag "turbo", :type => "module" %> <%= javascript_include_tag "application" %> <%= javascript_include_tag "i18n/#{I18n.locale}" %> - <% if preferred_site_color_scheme == "auto" %> + <% if preferred_color_scheme(:site) == "auto" %> <%= stylesheet_link_tag "screen-auto-#{dir}", :media => "screen" %> <% else %> <%= stylesheet_link_tag "screen-manual-#{dir}", :media => "screen" %> diff --git a/app/views/layouts/site.html.erb b/app/views/layouts/site.html.erb index dd573d476..6898b6f0b 100644 --- a/app/views/layouts/site.html.erb +++ b/app/views/layouts/site.html.erb @@ -1,5 +1,7 @@ -<%= tag.html :lang => I18n.locale, :dir => dir, :data => { :bs_theme => (preferred_site_color_scheme if preferred_site_color_scheme != "auto") } do %> +<%= tag.html :lang => I18n.locale, + :dir => dir, + :data => { :bs_theme => (preferred_color_scheme(:site) if preferred_color_scheme(:site) != "auto") } do %> <%= render :partial => "layouts/head" %> <%= render :partial => "layouts/header" %> diff --git a/app/views/preferences/edit.html.erb b/app/views/preferences/edit.html.erb index 34cb72046..2c3cd4ba0 100644 --- a/app/views/preferences/edit.html.erb +++ b/app/views/preferences/edit.html.erb @@ -11,7 +11,7 @@ <%= label_tag "site_color_scheme", t("preferences.show.preferred_site_color_scheme"), :class => "form-label" %> <%= select_tag "site_color_scheme", options_for_select(%w[auto light dark].map { |scheme| [t("preferences.show.site_color_schemes.#{scheme}"), scheme] }, - preferred_site_color_scheme), + preferred_color_scheme(:site)), :class => "form-select" %> diff --git a/app/views/preferences/show.html.erb b/app/views/preferences/show.html.erb index 4b772fba9..7681638ed 100644 --- a/app/views/preferences/show.html.erb +++ b/app/views/preferences/show.html.erb @@ -23,7 +23,7 @@
<%= t ".preferred_site_color_scheme" %>
- <%= t ".site_color_schemes.#{preferred_site_color_scheme}" %> + <%= t ".site_color_schemes.#{preferred_color_scheme(:site)}" %>
-- 2.39.5