Skip to content

[FEATURE]: Add dark mode support for web app#663

Open
Ashvin-KS wants to merge 2 commits into
AOSSIE-Org:mainfrom
Ashvin-KS:feat/web-dark-mode-toggle-661
Open

[FEATURE]: Add dark mode support for web app#663
Ashvin-KS wants to merge 2 commits into
AOSSIE-Org:mainfrom
Ashvin-KS:feat/web-dark-mode-toggle-661

Conversation

@Ashvin-KS
Copy link
Copy Markdown
Contributor

@Ashvin-KS Ashvin-KS commented Apr 12, 2026

Addressed Issues:
Implements issue #661 by adding dark mode support with a persistent theme toggle across the web app.

Fixes #661

Screenshots/Recordings:
Not attached from CLI environment.

Additional Notes:
This PR introduces a lightweight global theme controller without changing existing route structure.

Key Improvements:

  • Added a global theme toggle component rendered across all web routes
  • Added persistent theme preference storage (localStorage) so user choice survives reloads
  • Added dark/light mode class switching via document.documentElement
  • Added light-theme CSS overrides for existing dark-styled utility classes
  • Kept current dark UI as the default mode

AI Usage Disclosure:

  • This PR does not contain AI-generated code at all.
  • This PR contains AI-generated code. I have read the AI Usage Policy and this PR complies with this policy. I have tested the code locally and I am responsible for it.
  • AI models/tools used: GitHub Copilot (GPT-5.3-Codex)

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.
  • My code follows the project's code style and conventions
  • If applicable, I have made corresponding changes or additions to the documentation
  • If applicable, I have made corresponding changes or additions to tests
  • My changes generate no new warnings or errors
  • I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • I have read the Contribution Guidelines
  • Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.
  • I have filled this PR template completely and carefully, and I understand that my PR may be closed without review otherwise.

Validation:

  • npm --prefix eduaid_web run build (successful)
  • Existing lint warnings in unrelated files are unchanged

Summary by CodeRabbit

Release Notes

  • New Features
    • Added a theme toggle button to switch between dark and light modes.
    • Theme preference is automatically saved and persists across sessions.

Copilot AI review requested due to automatic review settings April 12, 2026 13:12
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 12, 2026

Warning

Rate limit exceeded

@Ashvin-KS has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 10 minutes and 53 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 10 minutes and 53 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c1ad8c11-0ccb-4801-8fe5-7e1b5f38e16d

📥 Commits

Reviewing files that changed from the base of the PR and between cb245cc and f51bcd6.

📒 Files selected for processing (2)
  • eduaid_web/src/components/ThemeToggle.jsx
  • eduaid_web/src/index.css
📝 Walkthrough

Walkthrough

A dark mode feature has been added to the web app. The new ThemeToggle component manages theme state, persists user preference to localStorage, and toggles a light-theme CSS class on the document root. Global CSS styles now define dark mode as default and provide light mode overrides for color utilities and form elements.

Changes

Cohort / File(s) Summary
Theme Toggle Component
eduaid_web/src/components/ThemeToggle.jsx
New React component that manages dark/light theme state, persists selection to localStorage, and toggles the light-theme class on document.documentElement. Renders a fixed-position button with sun/moon icons and full accessibility labels.
App Integration
eduaid_web/src/App.js
Imported and rendered ThemeToggle component at the top level inside HashRouter, before Routes, with no routing modifications.
Global Theming
eduaid_web/src/index.css
Added :root { color-scheme: dark; } as default, introduced .theme-toggle button styling with hover effects, and created .light-theme override class that adjusts color-scheme and redefines colors for utility classes and textarea elements.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hops of joy for modes so bright!
Now darkness yields to golden light,
LocalStorage holds the theme so dear,
A toggle switch brings cheer! 🌙✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding dark mode support, which is the primary feature across all three modified files.
Linked Issues check ✅ Passed The code implements the core requirement from issue #661: provides a dark mode option via a theme toggle component with persistent localStorage storage for user preference.
Out of Scope Changes check ✅ Passed All changes are directly aligned with the dark mode feature objective; no out-of-scope modifications detected in the three affected files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a global, persistent theme toggle to support light mode across the EduAid web app while keeping the current dark UI as the default.

Changes:

  • Introduced a new ThemeToggle component that persists the selected theme in localStorage and toggles a root class on document.documentElement.
  • Added global CSS for the toggle styling plus light-mode overrides for existing dark-styled utility classes.
  • Rendered the toggle globally across all routes via App.js.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
eduaid_web/src/index.css Adds theme-related CSS (color-scheme, toggle styles, and light-mode overrides).
eduaid_web/src/components/ThemeToggle.jsx Implements persistent theme state + DOM class switching and the UI button.
eduaid_web/src/App.js Mounts the global theme toggle for all routes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +15 to +24
useEffect(() => {
const savedTheme = localStorage.getItem(STORAGE_KEY);
const initialTheme =
savedTheme === LIGHT_THEME || savedTheme === DARK_THEME
? savedTheme
: DARK_THEME;

setTheme(initialTheme);
applyTheme(initialTheme);
}, []);
type="button"
onClick={toggleTheme}
className="theme-toggle fixed right-4 top-4 z-[1000] rounded-full px-4 py-2 text-sm font-semibold"
aria-label="Toggle dark mode"
Comment thread eduaid_web/src/index.css Outdated
radial-gradient(circle at 90% -15%, rgba(255, 19, 132, 0.16) 0%, transparent 40%) !important;
}

.light-theme .text-white {
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
eduaid_web/src/components/ThemeToggle.jsx (1)

42-43: Use toggle semantics for assistive tech.

Line 42 should expose the current state/action to screen readers. Prefer a dynamic aria-label and add aria-pressed.

Suggested fix
-      aria-label="Toggle dark mode"
+      aria-label={
+        theme === DARK_THEME ? "Switch to light mode" : "Switch to dark mode"
+      }
+      aria-pressed={theme === LIGHT_THEME}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@eduaid_web/src/components/ThemeToggle.jsx` around lines 42 - 43, The toggle
button in ThemeToggle.jsx currently uses a static aria-label; update it to
expose current state by making aria-label dynamic (e.g., theme === DARK_THEME ?
"Dark mode, toggle to light mode" : "Light mode, toggle to dark mode") and add
aria-pressed={theme === DARK_THEME} on the same element (the ThemeToggle
button/component) so assistive tech can read the current state; ensure the label
text matches the title logic and references the DARK_THEME constant and the
ThemeToggle component's theme prop/state.
eduaid_web/src/index.css (1)

52-95: Consider moving from class-by-class overrides to theme tokens.

Line 52-95 relies on many explicit selectors + !important, which becomes fragile as new utility classes are introduced. Defining shared CSS variables per theme will scale better and reduce override churn.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@eduaid_web/src/index.css` around lines 52 - 95, The current stylesheet uses
many explicit selectors and !important overrides (e.g., .light-theme
.bg-\[\#02000F\], .light-theme .bg-cust, .light-theme .bg-custom-gradient,
.light-theme .text-white, .light-theme .bg-black, .light-theme .bg-\[\#3e5063\],
.light-theme .border-\[\#cbd0dc80\]) which is fragile; instead define a set of
theme CSS variables on .light-theme (for example --bg-primary, --bg-surface,
--text-primary, --surface-fade, --border-color, --gradient-overlay) and update
your utility classes to use var(--*) rather than hardcoded colors, then remove
the per-class overrides and !important flags; also replace the custom gradient
value in .bg-custom-gradient with a variable so the theme can switch the
gradient centrally and ensure utilities (background, text, border) reference
these tokens (update places that reference .bg-cust, .text-white, .bg-black,
.bg-custom-gradient, and the bracketed color classes to consume the variables).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@eduaid_web/src/components/ThemeToggle.jsx`:
- Around line 13-29: The component currently defaults theme to DARK_THEME then
reads localStorage in a mount effect, causing an unnecessary write and flash;
change the useState initialization for theme to a lazy initializer that reads
STORAGE_KEY (return LIGHT_THEME or DARK_THEME appropriately) and calls
applyTheme synchronously for the initial value, remove the separate mount
useEffect that sets theme/applyTheme, and keep the existing useEffect([theme])
to persist changes to localStorage via localStorage.setItem(STORAGE_KEY, theme);
reference the state hook (useState/theme/setTheme), STORAGE_KEY, DARK_THEME,
LIGHT_THEME, and applyTheme when making this change.

---

Nitpick comments:
In `@eduaid_web/src/components/ThemeToggle.jsx`:
- Around line 42-43: The toggle button in ThemeToggle.jsx currently uses a
static aria-label; update it to expose current state by making aria-label
dynamic (e.g., theme === DARK_THEME ? "Dark mode, toggle to light mode" : "Light
mode, toggle to dark mode") and add aria-pressed={theme === DARK_THEME} on the
same element (the ThemeToggle button/component) so assistive tech can read the
current state; ensure the label text matches the title logic and references the
DARK_THEME constant and the ThemeToggle component's theme prop/state.

In `@eduaid_web/src/index.css`:
- Around line 52-95: The current stylesheet uses many explicit selectors and
!important overrides (e.g., .light-theme .bg-\[\#02000F\], .light-theme
.bg-cust, .light-theme .bg-custom-gradient, .light-theme .text-white,
.light-theme .bg-black, .light-theme .bg-\[\#3e5063\], .light-theme
.border-\[\#cbd0dc80\]) which is fragile; instead define a set of theme CSS
variables on .light-theme (for example --bg-primary, --bg-surface,
--text-primary, --surface-fade, --border-color, --gradient-overlay) and update
your utility classes to use var(--*) rather than hardcoded colors, then remove
the per-class overrides and !important flags; also replace the custom gradient
value in .bg-custom-gradient with a variable so the theme can switch the
gradient centrally and ensure utilities (background, text, border) reference
these tokens (update places that reference .bg-cust, .text-white, .bg-black,
.bg-custom-gradient, and the bracketed color classes to consume the variables).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ff557e04-2dfd-43e2-8d46-51013879ab32

📥 Commits

Reviewing files that changed from the base of the PR and between 2038116 and cb245cc.

📒 Files selected for processing (3)
  • eduaid_web/src/App.js
  • eduaid_web/src/components/ThemeToggle.jsx
  • eduaid_web/src/index.css

Comment thread eduaid_web/src/components/ThemeToggle.jsx Outdated
@Ashvin-KS
Copy link
Copy Markdown
Contributor Author

Addressed the review feedback with a follow-up commit.

What changed:

  • Switched theme state to lazy initialization from localStorage.
  • Applied theme with useLayoutEffect to reduce initial theme flash.
  • Improved accessibility with dynamic aria-label and aria-pressed on the toggle button.
  • Scoped light-mode text overrides to specific dark-surface containers instead of a global .text-white override.

Validation:

  • npm --prefix eduaid_web run build (successful)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Add dark mode support for web app

2 participants