mirror of
https://github.com/plausible/analytics.git
synced 2024-12-23 17:44:43 +03:00
fix theme applying based on the 'theme' query param (#3639)
This commit is contained in:
parent
9e783ebb41
commit
77ca5abbc8
@ -7,13 +7,13 @@ defmodule PlausibleWeb.Components.Layout do
|
||||
~H"""
|
||||
<script>
|
||||
(function(){
|
||||
var userPref = '<%= current_theme(assigns[:current_user]) %>';
|
||||
var themePref = '<%= theme_preference(assigns) %>';
|
||||
function reapplyTheme() {
|
||||
var darkMediaPref = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
var htmlRef = document.querySelector('html');
|
||||
var hcaptchaRefs = Array.from(document.getElementsByClassName('h-captcha'));
|
||||
|
||||
var isDark = userPref === 'dark' || (userPref === 'system' && darkMediaPref);
|
||||
var isDark = themePref === 'dark' || (themePref === 'system' && darkMediaPref);
|
||||
|
||||
if (isDark) {
|
||||
htmlRef.classList.add('dark')
|
||||
@ -31,6 +31,12 @@ defmodule PlausibleWeb.Components.Layout do
|
||||
"""
|
||||
end
|
||||
|
||||
defp current_theme(nil), do: "system"
|
||||
defp current_theme(user), do: user.theme
|
||||
defp theme_preference(%{theme: theme}) when not is_nil(theme), do: theme
|
||||
|
||||
defp theme_preference(%{current_user: %Plausible.Auth.User{theme: theme}})
|
||||
when not is_nil(theme) do
|
||||
theme
|
||||
end
|
||||
|
||||
defp theme_preference(_assigns), do: "system"
|
||||
end
|
||||
|
@ -45,7 +45,7 @@
|
||||
<%= Map.get(assigns, :inner_layout) || @inner_content %>
|
||||
</main>
|
||||
|
||||
<PlausibleWeb.Components.Layout.theme_script current_user={@conn.assigns[:current_user]} />
|
||||
<PlausibleWeb.Components.Layout.theme_script {Map.take(assigns, [:current_user, :theme])} />
|
||||
|
||||
<%= if assigns[:embedded] do %>
|
||||
<div data-iframe-height></div>
|
||||
|
Loading…
Reference in New Issue
Block a user