From db88434d80181f5695d000b230219bf50290a866 Mon Sep 17 00:00:00 2001 From: "Luna D." Date: Wed, 3 Jul 2024 22:00:12 +0200 Subject: [PATCH] fix theme select for prod --- assets/js/settings.ts | 7 +++++- .../templates/setting/edit.html.slime | 1 + lib/philomena_web/views/setting_view.ex | 25 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/assets/js/settings.ts b/assets/js/settings.ts index e4ab8927..0bc8a9d7 100644 --- a/assets/js/settings.ts +++ b/assets/js/settings.ts @@ -13,6 +13,11 @@ export function setupSettings() { const localCheckboxes = $$('[data-tab="local"] input[type="checkbox"]'); const themeSelect = assertNotNull($('#user_theme_name')); const themeColorSelect = assertNotNull($('#user_theme_color')); + const themePaths: Record = JSON.parse( + assertNotUndefined( + assertNotNull($('#js-theme-paths')).dataset.themePaths + ) + ); const styleSheet = assertNotNull($('#js-theme-stylesheet')); // Local settings @@ -27,7 +32,7 @@ export function setupSettings() { const themeName = assertNotUndefined(themeSelect.options[themeSelect.selectedIndex].value); const themeColor = assertNotUndefined(themeColorSelect.options[themeColorSelect.selectedIndex].value); - styleSheet.href = `/css/${themeName}-${themeColor}.css`; + styleSheet.href = themePaths[`${themeName}-${themeColor}`]; }; themeSelect.addEventListener('change', themePreviewCallback); diff --git a/lib/philomena_web/templates/setting/edit.html.slime b/lib/philomena_web/templates/setting/edit.html.slime index 524ee17c..cef78b67 100644 --- a/lib/philomena_web/templates/setting/edit.html.slime +++ b/lib/philomena_web/templates/setting/edit.html.slime @@ -93,6 +93,7 @@ h1 Content Settings => select f, :theme_color, theme_colors(), class: "input" = error_tag f, :theme_color .fieldlabel: i Color of the theme, don't forget to save settings to apply the theme + .hidden#js-theme-paths data-theme-paths=theme_paths_json() .field => label f, :scale_large_images .with-error diff --git a/lib/philomena_web/views/setting_view.ex b/lib/philomena_web/views/setting_view.ex index 63030bb2..59d9a74c 100644 --- a/lib/philomena_web/views/setting_view.ex +++ b/lib/philomena_web/views/setting_view.ex @@ -22,6 +22,31 @@ defmodule PhilomenaWeb.SettingView do ] end + def theme_paths_json do + Jason.encode!( + %{ + "dark-red": ~p"/css/dark-red.css", + "dark-orange": ~p"/css/dark-orange.css", + "dark-yellow": ~p"/css/dark-yellow.css", + "dark-blue": ~p"/css/dark-blue.css", + "dark-green": ~p"/css/dark-green.css", + "dark-purple": ~p"/css/dark-purple.css", + "dark-cyan": ~p"/css/dark-cyan.css", + "dark-pink": ~p"/css/dark-pink.css", + "dark-silver": ~p"/css/dark-silver.css", + "light-red": ~p"/css/light-red.css", + "light-orange": ~p"/css/light-orange.css", + "light-yellow": ~p"/css/light-yellow.css", + "light-blue": ~p"/css/light-blue.css", + "light-green": ~p"/css/light-green.css", + "light-purple": ~p"/css/light-purple.css", + "light-cyan": ~p"/css/light-cyan.css", + "light-pink": ~p"/css/light-pink.css", + "light-silver": ~p"/css/light-silver.css" + } + ) + end + def scale_options do [ [key: "Load full images on image pages", value: "false"],