Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions static/icons/auto.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 33 additions & 11 deletions static/js/themetoggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ function toggleTheme() {
setTheme("dark");
updateItemToggleTheme();
} else if (localStorage.getItem("theme-storage") === "dark") {
setTheme("auto");
updateItemToggleTheme();
} else {
Comment on lines 12 to +15
Copy link

Copilot AI Oct 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic uses getSavedTheme() at line 61 but directly calls localStorage.getItem(\"theme-storage\") here. Consider using getSavedTheme() consistently for better maintainability and to avoid potential issues if the saved theme is null/undefined.

Copilot uses AI. Check for mistakes.
setTheme("light");
updateItemToggleTheme();
}
Expand All @@ -20,38 +23,57 @@ function updateItemToggleTheme() {

const darkModeStyle = document.getElementById("darkModeStyle");
if (darkModeStyle) {
darkModeStyle.disabled = (mode === "light");
if (mode === "dark" || (mode === "auto" && getSystemPrefersDark())) {
darkModeStyle.disabled = false;
} else {
darkModeStyle.disabled = true;
}
}

const sunIcon = document.getElementById("sun-icon");
const moonIcon = document.getElementById("moon-icon");
if (sunIcon && moonIcon) {
sunIcon.style.display = (mode === "dark") ? "block" : "none";
moonIcon.style.display = (mode === "light") ? "block" : "none";
const autoIcon = document.getElementById("auto-icon");
if (sunIcon && moonIcon && autoIcon) {
sunIcon.style.display = (mode === "light") ? "block" : "none";
moonIcon.style.display = (mode === "dark") ? "block" : "none";
autoIcon.style.display = (mode === "auto") ? "block" : "none";

if (mode === "auto") {
autoIcon.style.filter = getSystemPrefersDark() ? "invert(1)" : "invert(0)";
Copy link

Copilot AI Oct 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The auto icon filter is only updated when mode is 'auto', but the filter persists when switching modes. This could cause visual issues if the icon is reused. Consider resetting the filter when switching away from auto mode or moving this logic outside the conditional.

Suggested change
autoIcon.style.filter = getSystemPrefersDark() ? "invert(1)" : "invert(0)";
autoIcon.style.filter = getSystemPrefersDark() ? "invert(1)" : "invert(0)";
} else {
autoIcon.style.filter = "none";

Copilot uses AI. Check for mistakes.
}
}

let htmlElement = document.querySelector("html");
if (mode === "dark") {
if (mode === "dark" || (mode === "auto" && getSystemPrefersDark())) {
htmlElement.classList.remove("light")
htmlElement.classList.add("dark")
} else if (mode === "light") {
} else {
htmlElement.classList.remove("dark")
htmlElement.classList.add("light")
}
}

function getSystemPrefersDark() {
return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
}

function getSavedTheme() {
let currentTheme = localStorage.getItem("theme-storage");
if(!currentTheme) {
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
currentTheme = "dark";
} else {
currentTheme = "light";
}
currentTheme = getSystemPrefersDark() ? "dark" : "light";
}

return currentTheme;
}

// Update the toggle theme on page load
updateItemToggleTheme();

// Listen for system theme changes in auto mode
if (window.matchMedia) {
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', function(e) {
if (getSavedTheme() === "auto") {
updateItemToggleTheme();
}
});
}
12 changes: 8 additions & 4 deletions templates/partials/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,15 @@ <h1 id="modalTitle" class="page-header">
<a id="dark-mode-toggle"
onclick="toggleTheme(); event.preventDefault();"
href="#">
<img src="{{ get_url(path='icons/sun.svg') }}"
id="sun-icon"
<img src="{{ get_url(path='icons/sun.svg') }}" id="sun-icon" alt="Light" />
<img src="{{ get_url(path='icons/moon.svg') }}"
id="moon-icon"
style="filter: invert(1)"
alt="Light" />
<img src={{ get_url(path="icons/moon.svg") }} id="moon-icon" alt="Dark" />
alt="Dark" />
<img src="{{ get_url(path='icons/auto.svg') }}"
id="auto-icon"
style="filter: invert(1)"
alt="Auto" />
</a>

<!-- Initialize the theme toggle icons -->
Expand Down