Skip to content

Commit ed7c670

Browse files
authored
Fix top Navigation Bar blue color while reloading (#290)
1 parent 9ab12e8 commit ed7c670

File tree

3 files changed

+64
-4
lines changed

3 files changed

+64
-4
lines changed

webui/src/app/globals.css

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,33 @@ body {
8787
background-color: #121212;
8888
color: #e0e0e0;
8989
}
90+
91+
.MuiAppBar-root {
92+
transition: background-color 0.3s ease, color 0.3s ease !important;
93+
}
94+
95+
.dark .MuiAppBar-root {
96+
background-color: var(--primary-dark, #1565c0) !important;
97+
opacity: 0.9;
98+
}
99+
100+
.dark .MuiAppBar-root,
101+
.navbar-dark-mode {
102+
background-color: #1565c0 !important;
103+
color: white !important;
104+
opacity: 0.9;
105+
}
106+
107+
.navbar-dark-mode {
108+
background-color: #1565c0 !important;
109+
color: white !important;
110+
}
111+
112+
.dark .MuiAppBar-root *,
113+
.navbar-dark-mode * {
114+
color: white !important;
115+
}
116+
117+
.MuiAppBar-root[class*='navbar-dark-mode'] {
118+
background-color: #1565c0 !important;
119+
}

webui/src/app/theme-provider.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,39 @@ export const useTheme = () => useContext(ThemeContext);
3737

3838
export function ThemeProvider({ children }: { children: React.ReactNode }) {
3939
const [isDarkMode, setIsDarkMode] = useState(false);
40+
const [mounted, setMounted] = useState(false);
4041

4142
useEffect(() => {
4243
// Check if user has already set a preference
4344
const storedTheme = localStorage.getItem("theme");
4445
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
4546

46-
if (storedTheme === "dark" || (!storedTheme && prefersDark)) {
47-
setIsDarkMode(true);
47+
const shouldBeDark = storedTheme === "dark" || (!storedTheme && prefersDark);
48+
49+
// Apply dark mode styles
50+
if (shouldBeDark) {
4851
document.documentElement.classList.add("dark");
52+
// Also add the special class to navbar if it exists
53+
document.getElementById('navbar')?.classList.add('navbar-dark-mode');
4954
} else {
50-
setIsDarkMode(false);
5155
document.documentElement.classList.remove("dark");
56+
document.getElementById('navbar')?.classList.remove('navbar-dark-mode');
5257
}
58+
59+
setIsDarkMode(shouldBeDark);
60+
setMounted(true);
5361
}, []);
5462

5563
const toggleTheme = () => {
5664
setIsDarkMode((prev) => {
5765
const newMode = !prev;
5866
if (newMode) {
5967
document.documentElement.classList.add("dark");
68+
document.getElementById('navbar')?.classList.add('navbar-dark-mode');
6069
localStorage.setItem("theme", "dark");
6170
} else {
6271
document.documentElement.classList.remove("dark");
72+
document.getElementById('navbar')?.classList.remove('navbar-dark-mode');
6373
localStorage.setItem("theme", "light");
6474
}
6575
return newMode;

webui/src/app/ui/banner.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import Brightness4Icon from "@mui/icons-material/Brightness4";
2727
import Brightness7Icon from "@mui/icons-material/Brightness7";
2828
import GitHubIcon from "@mui/icons-material/GitHub";
2929
import { usePathname } from "next/navigation";
30+
import { useEffect, useState } from "react";
3031

3132
const links = [
3233
{
@@ -45,12 +46,31 @@ const links = [
4546
export default function Banner() {
4647
const { isDarkMode, toggleTheme } = useTheme();
4748
const pathname = usePathname();
49+
const [mounted, setMounted] = useState(false);
50+
51+
useEffect(() => {
52+
const storedTheme = localStorage.getItem("theme");
53+
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
54+
const shouldBeDark = storedTheme === "dark" || (!storedTheme && prefersDark);
55+
56+
if (shouldBeDark) {
57+
document.getElementById('navbar')?.classList.add('navbar-dark-mode');
58+
}
59+
60+
setMounted(true);
61+
}, []);
4862

4963
// Generate breadcrumb from pathname
5064
const breadcrumbs = pathname.split('/').filter(Boolean);
5165

5266
return (
53-
<AppBar position="fixed" elevation={1} className="bg-white dark:bg-dark-paper text-gray-800 dark:text-gray-100">
67+
<AppBar
68+
position="fixed"
69+
elevation={1}
70+
id="navbar"
71+
className={`transition-colors duration-300 ${isDarkMode ? 'navbar-dark-mode' : 'bg-white text-gray-800'}`}
72+
sx={{ bgcolor: isDarkMode ? '#1565c0 !important' : '#ffffff' }}
73+
>
5474
<Container maxWidth={false}>
5575
<Toolbar className="flex justify-between">
5676
<div className="flex items-center">

0 commit comments

Comments
 (0)