Skip to content
Merged
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
2 changes: 1 addition & 1 deletion app/ycode/components/HeaderBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ export default function HeaderBar({
<InviteUserButton />

{/* Save Status Indicator */}
<div className="flex items-center justify-end w-16 text-xs text-white/50">
<div className="flex items-center justify-end w-16 text-xs text-zinc-500 dark:text-white/50">
{isSaving ? (
<>
<span>Saving</span>
Expand Down
27 changes: 23 additions & 4 deletions components/DarkModeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,43 @@
import { usePathname } from 'next/navigation';
import { useEffect } from 'react';

/**
* Resolves whether dark mode should be active based on the user's
* saved theme preference and the system color scheme.
*/
function shouldApplyDark(): boolean {
const saved = localStorage.getItem('theme') as 'system' | 'light' | 'dark' | null;
const theme = saved || 'dark';

if (theme === 'light') return false;
if (theme === 'dark') return true;
return window.matchMedia('(prefers-color-scheme: dark)').matches;
}

/**
* DarkModeProvider
*
* Client component that applies dark mode class to <html> element
* based on the current pathname. This avoids using headers() in
* the root layout which would force all pages to be dynamic.
*
* Dark mode is applied for /ycode/* routes except /ycode/preview/*
* For /ycode/* routes (except preview), it respects the user's
* saved theme preference from localStorage.
* For all other routes, dark mode is removed.
*/
export default function DarkModeProvider({ children }: { children: React.ReactNode }) {
const pathname = usePathname();

useEffect(() => {
const isPreviewRoute = pathname?.startsWith('/ycode/preview');
const isDarkMode = !isPreviewRoute && pathname?.startsWith('/ycode');
const isBuilderRoute = !isPreviewRoute && pathname?.startsWith('/ycode');

if (isDarkMode) {
document.documentElement.classList.add('dark');
if (isBuilderRoute) {
if (shouldApplyDark()) {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}
} else {
document.documentElement.classList.remove('dark');
}
Expand Down