Skip to content

Add theme toggle implementation#72

Open
rahul-vyas-dev wants to merge 1 commit into
AOSSIE-Org:mainfrom
rahul-vyas-dev:feat/theme-toggle
Open

Add theme toggle implementation#72
rahul-vyas-dev wants to merge 1 commit into
AOSSIE-Org:mainfrom
rahul-vyas-dev:feat/theme-toggle

Conversation

@rahul-vyas-dev

@rahul-vyas-dev rahul-vyas-dev commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Screenshots/Recordings:

Before:
https://1drv.ms/v/c/49769719fd71e0ee/IQBw8_zmESfLR7LQ_HTb68K6AQr9aR_oNi1aMxGHwrPZHVo?e=1EPLVE

After:
https://1drv.ms/v/c/49769719fd71e0ee/IQCmGYAtcZfcSru74o9NKCqDAa_GeuzD70IXJyir9yShDng?e=yh5p89

Additional Notes:

This PR adds a theme toggle feature to improve the user experience by allowing users to switch between different themes dynamically across the application.

  • Users can switch themes instantly
  • Theme preference persists across sessions
  • Responsive and accessible toggle UI
  • Consistent styling throughout the application

Checklist

  • My code follows the project's code style and conventions
  • I have made corresponding changes to the documentation
  • 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 Contributing Guidelines

⚠️ AI Notice - Important!

We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact.

Summary by CodeRabbit

  • New Features
    • Introduced dark and light theme modes with a toggle button in the navigation bar for seamless switching.
    • User theme preference is automatically saved and restored on subsequent visits.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Adds a complete dark/light theme system with React Context state management and localStorage persistence. ThemeProvider initializes theme from storage, manages document data-theme attributes, and exposes toggleTheme. ThemeToggle component renders a sun/moon icon button in the navbar. Light mode CSS variables override global theme tokens. App wraps providers with ThemeProvider at the top level.

Changes

Dark/Light Theme Implementation

Layer / File(s) Summary
Theme Context and useTheme Hook
src/context/ThemeContext.jsx
ThemeProvider initializes theme from localStorage with dark default, syncs document data-theme attribute, persists changes to storage, and provides toggleTheme flipper. useTheme hook consumes context and throws error if used outside provider.
Light Theme CSS Variable Overrides
src/styles/global.css
[data-theme="light"] rule block overrides global CSS variables for backgrounds, surfaces, borders, accent, and text colors, plus semantic color tokens (green, red, blue, amber, purple).
ThemeToggle Component
src/components/ThemeToggle.jsx
Wires useTheme hook into a styled button that toggles theme on click, conditionally renders sun/moon icons, and updates button title based on current theme state.
App Provider Wrapping
src/App.jsx
Restructures provider tree to wrap AppProvider with ThemeProvider at top level. Extracts Routes and Layout into new AppContent component to keep hierarchy clean while maintaining all route paths and redirect behavior.
Navbar Theme Toggle Placement
src/components/Navbar.jsx
Imports and renders ThemeToggle component in navbar's right-side section, enabling user theme switching without affecting existing org-based links or rate-limit display.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Navbar
  participant ThemeToggle
  participant useTheme
  participant ThemeProvider
  participant localStorage
  participant document
  
  User->>Navbar: Load page
  Navbar->>ThemeToggle: Render toggle button
  ThemeToggle->>useTheme: Access theme state
  useTheme->>ThemeProvider: Read context
  ThemeProvider->>localStorage: Initialize theme (default: dark)
  ThemeProvider->>document: Set data-theme attribute
  
  User->>ThemeToggle: Click toggle button
  ThemeToggle->>useTheme: Call toggleTheme()
  useTheme->>ThemeProvider: Flip theme value
  ThemeProvider->>document: Update data-theme attribute
  ThemeProvider->>localStorage: Persist theme to storage
  Note over document: CSS applies [data-theme="light"] styles
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

Typescript Lang

Suggested reviewers

  • bhavik-mangla
  • Zahnentferner

Poem

🐰 A rabbit hops through dark and light,
With context hooks held ever tight,
The toggle button, sun and moon,
Now users choose—in dark or soon!
Theme persistence, localStorage keeps,
While CSS dreams and data-theme sleeps.

🚥 Pre-merge checks | ✅ 4
✅ 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 a complete theme toggle feature with provider, context hook, UI component, and styling.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

@github-actions github-actions Bot added no-issue-linked PR has no linked issue frontend Frontend changes javascript JavaScript/TypeScript changes size/M 51-200 lines changed external-contributor External contributor and removed size/M 51-200 lines changed labels Jun 9, 2026
@rahul-vyas-dev rahul-vyas-dev added the gsoc GSoC students label Jun 9, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/components/Navbar.jsx (1)

23-30: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Make the navbar background theme-aware instead of hardcoded dark.

Line 25 uses a fixed dark RGBA value, so the navbar does not visually switch with light theme. Use theme variables for this background.

Proposed fix
     <nav style={{
       position: 'sticky', top: 0, zIndex: 100,
-      background: 'rgba(13,13,13,.97)',
+      background: 'var(--surface)',
       backdropFilter: 'blur(10px)',
       borderBottom: '1px solid var(--border)',
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/Navbar.jsx` around lines 23 - 30, The nav inline style in
Navbar.jsx currently hardcodes a dark RGBA background; change it to use a theme
CSS variable instead (e.g., replace the 'background' property's hardcoded
'rgba(13,13,13,.97)' with a theme-aware CSS variable like --navbar-bg or
--surface-translucent, with a sensible fallback) so the bar respects light/dark
themes; update the nav style in the render of Navbar.jsx and ensure the chosen
CSS variable is defined in the global/theme stylesheet.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/ThemeToggle.jsx`:
- Line 21: The title prop in ThemeToggle.jsx currently hardcodes the user-facing
string (`title={`Switch to ${theme === "dark" ? "light" : "dark"} theme`}`)
which must be externalized for i18n; replace this inline string with a lookup
from the localization resource (e.g., use a key like "theme.switchTo" and pass
the computed target theme as a variable), update the component to import/use the
i18n helper (e.g., t or useTranslation) and call it where the title is set
(referencing ThemeToggle and the theme variable), and add the corresponding key
with pluralization/variable placeholder to the locale files so translations can
render "Switch to {target} theme".
- Around line 8-24: The icon-only theme toggle button in ThemeToggle.jsx lacks
explicit accessibility semantics; update the button element used with the
toggleTheme handler to include type="button", an aria-label that reflects the
target action (e.g., "Switch to light theme" or "Switch to dark theme" based on
the theme prop/state), and aria-pressed set to true/false according to the
current theme (use the theme variable to compute the boolean) so assistive tech
can determine its name and state; ensure these attributes are added alongside
the existing props on the same button that renders the FiSun/FiMoon icons.

In `@src/context/ThemeContext.jsx`:
- Around line 6-8: The theme initializer in ThemeContext.jsx currently trusts
localStorage.getItem('oe_theme') directly; update the useState initializer (the
theme/setTheme logic) to read the persisted value, validate it against an
allowed whitelist ('dark' or 'light'), and return the persisted value only if it
matches, otherwise return the fallback 'dark' so invalid values never get
applied to data-theme or token overrides.

---

Outside diff comments:
In `@src/components/Navbar.jsx`:
- Around line 23-30: The nav inline style in Navbar.jsx currently hardcodes a
dark RGBA background; change it to use a theme CSS variable instead (e.g.,
replace the 'background' property's hardcoded 'rgba(13,13,13,.97)' with a
theme-aware CSS variable like --navbar-bg or --surface-translucent, with a
sensible fallback) so the bar respects light/dark themes; update the nav style
in the render of Navbar.jsx and ensure the chosen CSS variable is defined in the
global/theme stylesheet.
🪄 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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 14c8b4b6-b40a-43ee-957a-f026354ab01a

📥 Commits

Reviewing files that changed from the base of the PR and between 775f7ad and 58487a8.

📒 Files selected for processing (5)
  • src/App.jsx
  • src/components/Navbar.jsx
  • src/components/ThemeToggle.jsx
  • src/context/ThemeContext.jsx
  • src/styles/global.css

Comment thread src/components/ThemeToggle.jsx
Comment thread src/components/ThemeToggle.jsx
Comment thread src/context/ThemeContext.jsx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contributor External contributor frontend Frontend changes gsoc GSoC students javascript JavaScript/TypeScript changes no-issue-linked PR has no linked issue size/M 51-200 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant