Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4a692a6
Add Dark Mode Toggle Feature (#85-10)
Subham-KRLX Dec 15, 2025
213dc01
Merge branch 'main' into feat/dark-mode-toggle
Subham-KRLX Dec 15, 2025
e758bd8
Refactor Dark Mode implementation based on code review feedback
Subham-KRLX Dec 15, 2025
bb05600
Fix CSS issues from code review
Subham-KRLX Dec 15, 2025
811e7d1
Merge branch 'main' into feat/dark-mode-toggle
Subham-KRLX Dec 16, 2025
c62c857
Merge branch 'main' into feat/dark-mode-toggle
BaseMax Dec 16, 2025
52a8baf
Merge branch 'main' into feat/dark-mode-toggle
jbampton Dec 16, 2025
c73304f
Fix flash of incorrect theme and refactor CSS to use variables
Subham-KRLX Dec 17, 2025
0dcb22c
Merge upstream/main into feat/dark-mode-toggle: Resolve conflicts and…
Subham-KRLX Dec 17, 2025
a07db53
fix(review): remove extra braces, unused var, and use gradient hover
Subham-KRLX Dec 17, 2025
8a2d7d5
Fix dark mode: update reset button style and remove FOIT
Subham-KRLX Dec 17, 2025
8b81cd7
Implement code review feedback for dark mode feature
Subham-KRLX Dec 18, 2025
7387b13
Merge branch 'main' into feat/dark-mode-toggle
BaseMax Dec 18, 2025
29b1eb0
Refactor CSS variables for better consistency and maintainability
Subham-KRLX Dec 18, 2025
7d71e0b
Address code review feedback: improve button consistency and accessib…
Subham-KRLX Dec 18, 2025
88bfb0f
fix: remove invalid CSS syntax from dark mode styles
Subham-KRLX Dec 18, 2025
ad63804
Merge branch 'main' into feat/dark-mode-toggle
BaseMax Dec 18, 2025
9d9aa48
Merge branch 'main' into feat/dark-mode-toggle
BaseMax Dec 18, 2025
f7e562f
Fix dark mode button hover consistency - use red shade for reset button
Subham-KRLX Dec 18, 2025
73f88bb
fix: unset top property for dark mode toggle on mobile view
Subham-KRLX Dec 18, 2025
53a6d30
Merge branch 'main' into feat/dark-mode-toggle
BaseMax Dec 18, 2025
ab42079
Merge upstream/main into feat/dark-mode-toggle: Resolve conflicts in …
Subham-KRLX Dec 18, 2025
8eb146b
Merge branch 'main' into feat/dark-mode-toggle
jbampton Dec 19, 2025
86c9333
fix: move dark mode toggle from top-right to bottom-right to avoid fo…
Subham-KRLX Dec 22, 2025
3ef2d81
Merge upstream/main into feat/dark-mode-toggle and resolve conflicts
Subham-KRLX Dec 25, 2025
e7ff00b
Merge branch 'main' into feat/dark-mode-toggle
Subham-KRLX Dec 25, 2025
113bc4b
Merge branch 'main' into feat/dark-mode-toggle
jbampton Dec 26, 2025
c4ec293
Merge upstream/main into feat/dark-mode-toggle: Resolve conflicts
Subham-KRLX Dec 26, 2025
d22457d
fix: resolve merge conflict in hideLoadingState function
Subham-KRLX Dec 26, 2025
a9576ac
fix: resolve merge conflict in layouts/layout.html
Subham-KRLX Dec 26, 2025
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
52 changes: 52 additions & 0 deletions docs/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@

let allUsers = [];
let filteredUsers = [];
let darkModeToggleElement = null;

// Dark mode constants
const DARK_MODE_KEY = 'darkMode';
const THEME_ENABLED = 'enabled';
const THEME_DISABLED = 'disabled';

// ============================================================================
// INITIALIZATION
Expand All @@ -41,6 +47,7 @@ document.addEventListener('DOMContentLoaded', initializeApp);
* Initialize the application on page load
*/
function initializeApp() {
initializeDarkMode();
const cards = document.querySelectorAll('.card');
Comment thread
jbampton marked this conversation as resolved.
Outdated
showLoadingState();
document.getElementById('totalCount').textContent = cards.length.toLocaleString();
Expand Down Expand Up @@ -508,3 +515,48 @@ function hideLoadingState() {
if (loadingState) loadingState.style.display = 'none';
Comment thread
jbampton marked this conversation as resolved.
Outdated
if (loadingStateDesktop) loadingStateDesktop.style.display = 'none';
}
// ============================================================================
// DARK MODE TOGGLE
// ============================================================================
/**
* Initialize dark mode functionality
* - Load saved preference from localStorage
Comment thread
jbampton marked this conversation as resolved.
Outdated
* - Set up toggle button listener
* - Apply dark mode class if preference is set
* - Cache DOM element for performance
*/
function initializeDarkMode() {
darkModeToggleElement = document.getElementById('darkModeToggle');
const isDarkMode = localStorage.getItem(DARK_MODE_KEY) === THEME_ENABLED;

if (isDarkMode) {
document.body.classList.add('dark-mode');
updateDarkModeIcon(true);
}

if (darkModeToggleElement) {
darkModeToggleElement.addEventListener('click', toggleDarkMode);
}
}
Comment thread
jbampton marked this conversation as resolved.

/**
* Toggle dark mode on/off
* - Saves preference to localStorage
* - Applies/removes dark-mode class from body
*/
function toggleDarkMode() {
const isDarkMode = document.body.classList.toggle('dark-mode');
localStorage.setItem(DARK_MODE_KEY, isDarkMode ? THEME_ENABLED : THEME_DISABLED);
updateDarkModeIcon(isDarkMode);
}
Comment on lines +1136 to +1140

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Accessing localStorage can throw an exception in some browser environments, such as in private browsing mode or if the user has disabled it. This would cause the toggleDarkMode function to crash. It's best practice to wrap localStorage operations in a try...catch block to handle these edge cases gracefully and ensure the rest of the function (like updating the icon) still executes.

function toggleDarkMode() {
  const isDarkMode = document.documentElement.classList.toggle('dark-mode');
  try {
    localStorage.setItem(DARK_MODE_KEY, isDarkMode ? THEME_ENABLED : THEME_DISABLED);
  } catch (error) {
    console.error('Failed to save dark mode preference:', error);
  }
  updateDarkModeIcon(isDarkMode);
}


/**
* Update dark mode toggle icon
* @param {boolean} isDarkMode - Whether dark mode is currently enabled
*/
function updateDarkModeIcon(isDarkMode) {
if (darkModeToggleElement) {
darkModeToggleElement.textContent = isDarkMode ? 'β˜€οΈ' : 'πŸŒ™';
darkModeToggleElement.title = isDarkMode ? 'Switch to Light Mode' : 'Switch to Dark Mode';
}
}
Comment thread
jbampton marked this conversation as resolved.
Outdated
184 changes: 183 additions & 1 deletion docs/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,28 @@
box-sizing: border-box;
}

/* ============================================================================ */
/* CSS VARIABLES FOR THEMING */
/* ============================================================================ */
:root {
--bg-color: #f0f2f5;
--text-color: #333;
--text-secondary: #666;
--card-bg: #ffffff;
--card-border: #ddd;
--input-bg: #ffffff;
--input-border: #ccc;
--header-bg: #ffffff;
--footer-bg: #ffffff;
--footer-border: #e0e0e0;
--link-color: #667eea;
--link-hover: #764ba2;
}

body {
font-family: 'Arial', sans-serif;
background: #f0f2f5;
background: var(--bg-color);
color: var(--text-color);
margin: 0;
padding: 0;
}
Expand Down Expand Up @@ -593,3 +612,166 @@ footer {
display: none;
}
}

/* ============================================================================ */
/* DARK MODE STYLES - USING CSS VARIABLES */
/* ============================================================================ */
body.dark-mode {
--bg-color: #1e1e1e;
--text-color: #e0e0e0;
--text-secondary: #b0b0b0;
--card-bg: #2d2d2d;
--card-border: #444;
--input-bg: #3a3a3a;
--input-border: #555;
--header-bg: #2d2d2d;
--footer-bg: #2d2d2d;
--footer-border: #444;
--link-color: #667eea;
--link-hover: #764ba2;
}
Comment thread
jbampton marked this conversation as resolved.
Outdated
Comment thread
jbampton marked this conversation as resolved.

body.dark-mode {
background: var(--bg-color);
color: var(--text-color);
}
Comment thread
jbampton marked this conversation as resolved.
Outdated

body.dark-mode h1 {
color: var(--text-color);
}

body.dark-mode .header-section {
background: var(--header-bg);
}

body.dark-mode .filters-aside {
background: var(--header-bg);
border-right: 1px solid var(--card-border);
}

body.dark-mode .filters-aside h2,
body.dark-mode .filters-content,
body.dark-mode .filters-content label {
color: var(--text-color);
}

body.dark-mode input[type="text"],
body.dark-mode select {
background: var(--input-bg);
color: var(--text-color);
border: 1px solid var(--input-border);
}

body.dark-mode input[type="text"]::placeholder {
color: var(--text-secondary);
}

body.dark-mode input[type="text"]:focus,
body.dark-mode select:focus {
border-color: var(--link-color);
background: var(--input-bg);
}

body.dark-mode .card {
background: var(--card-bg);
color: var(--text-color);
border: 1px solid var(--card-border);
}

body.dark-mode .card:hover {
box-shadow: 0 8px 20px rgba(102, 126, 234, 0.3);
}

body.dark-mode .details-box {
background: var(--bg-color);
}
Comment thread
jbampton marked this conversation as resolved.

body.dark-mode .details-box strong {
color: #fff;
}
Comment thread
jbampton marked this conversation as resolved.
Outdated

body.dark-mode .details-box span {
color: var(--text-secondary);
}

body.dark-mode .details-box a,
body.dark-mode footer a {
color: var(--link-color);
}

body.dark-mode .details-box a:hover,
body.dark-mode footer a:hover {
color: var(--link-hover);
}

body.dark-mode .btn-apply,
body.dark-mode .btn-reset {
background: var(--link-color);
color: white;
border: none;
}

body.dark-mode .btn-apply:hover,
body.dark-mode .btn-reset:hover {
background: var(--link-hover);
}

body.dark-mode .results-info,
body.dark-mode .results-info strong {
color: var(--text-color);
}

body.dark-mode footer {
background: var(--footer-bg);
color: var(--text-secondary);
border-top: 1px solid var(--footer-border);
}
Comment thread
jbampton marked this conversation as resolved.
Outdated

/* Dark Mode Toggle Button */
.dark-mode-toggle {
position: fixed;
top: 20px;
right: 20px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border: none;
color: white;
width: 50px;
height: 50px;
border-radius: 50%;
cursor: pointer;
font-size: 20px;
display: flex;
align-items: center;
justify-content: center;
z-index: 999;
Comment thread
jbampton marked this conversation as resolved.
Outdated
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
transition: all 0.3s ease;
}

.dark-mode-toggle:hover {
transform: scale(1.1);
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}
Comment thread
jbampton marked this conversation as resolved.

.dark-mode-toggle:active {
transform: scale(0.95);
}

body.dark-mode .dark-mode-toggle {
background: linear-gradient(135deg, #f4a460 0%, #ff8c69 100%);
box-shadow: 0 4px 15px rgba(255, 140, 105, 0.4);
}

body.dark-mode .dark-mode-toggle:hover {
box-shadow: 0 6px 20px rgba(255, 140, 105, 0.6);
}

@media (max-width: 768px) {
.dark-mode-toggle {
top: 10px;
right: 10px;
width: 45px;
height: 45px;
font-size: 18px;
}
}
5 changes: 5 additions & 0 deletions layouts/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
<img class="github-ribbon" src="https://github.blog/wp-content/uploads/2008/12/forkme_right_darkblue_121621.png?resize=149%2C149" alt="Fork me on GitHub">
</a>

<!-- Dark Mode Toggle Button -->
<button id="darkModeToggle" class="dark-mode-toggle" title="Switch to Dark Mode" aria-label="Toggle dark mode">
πŸŒ™
</button>

<!-- Mobile Filter Toggle Button -->
<button id="filterToggleBtn" class="filter-toggle-btn" onclick="toggleFiltersPanel()" aria-label="Toggle filters">
πŸ” Filters
Expand Down