Skip to content

Commit

Permalink
Show icons for dark/light theme #1166
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Jul 19, 2023
1 parent 6352619 commit a610a07
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
14 changes: 0 additions & 14 deletions static/dark-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ const DARK_THEME_KEY = 'startInDarkTheme';
function setDarkTheme() {
document.body.classList.remove(LIGHT_THEME_CLASS);
document.body.classList.add(DARK_THEME_CLASS);
setThemeButtonText("Light Theme");
}

function setLightTheme() {
document.body.classList.remove(DARK_THEME_CLASS);
document.body.classList.add(LIGHT_THEME_CLASS);
setThemeButtonText("Dark Theme");
}

function toggleDarkTheme() {
Expand All @@ -24,17 +22,6 @@ function toggleDarkTheme() {
}
}

/**
* Safely modify theme button text only if it exists
* @param {string} text label for button
*/
function setThemeButtonText(text) {
const button = document.getElementById('dark-theme-button')
if (button) {
button.innerHTML = text
}
}

// enable dark theme as soon as possible so first paint is already dark mode
(function () {
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
Expand All @@ -54,6 +41,5 @@ function setThemeButtonText(text) {
// handle theme button label and listener once DOM fully loaded
window.addEventListener('DOMContentLoaded', function () {
const isDarkTheme = document.body.classList.contains(DARK_THEME_CLASS)
setThemeButtonText(isDarkTheme ? "Light Theme" : "Dark Theme")
document.getElementById('dark-theme-button').addEventListener('click', toggleDarkTheme)
})
20 changes: 20 additions & 0 deletions static/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ dd + dt { margin-top: 1em; }
background-color: #fff;
}

.dark-theme #dark-theme-label { display: none; }
.dark-theme #light-theme-label { display: block; }
.light-theme #dark-theme-label { display: block; }
.light-theme #light-theme-label { display: none; }

.light-theme .tag.playable { color: #28a745; }
.light-theme .tag.semi-playable { color: #CB9423; }
.light-theme .tag.unplayable { color: #dc3545; }
Expand Down Expand Up @@ -360,3 +365,18 @@ dd + dt { margin-top: 1em; }
.game-spacer {
margin: 10px;
}

.lg-view{
display:inline-block;
}
.sm-view{
display:none;
}
@media screen and (max-width: 500px) {
.lg-view{
display:none;
}
.sm-view{
display:inline-block;
}
}
5 changes: 4 additions & 1 deletion templates/common.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@
<span class="nav-count">xxxx/yyyy games</span>
</li>
</ul>
<span id="dark-theme-button" class="nav-btn">Dark Theme</span>
<span id="dark-theme-button" class="nav-btn">
<span id="dark-theme-label"><i class="fa-solid fa-moon"></i></span>
<span id="light-theme-label"><i class="fa-solid fa-sun"></i></span>
</span>
<span id='sortButton' class="nav-btn">Sort by ........</span>
</div>
</header>
Expand Down

0 comments on commit a610a07

Please sign in to comment.