-
Notifications
You must be signed in to change notification settings - Fork 30
fixed the error #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fixed the error #75
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { useEffect, useState } from "react"; | ||
| import { Sun, Moon } from "lucide-react"; | ||
|
|
||
| export default function ThemeToggle() { | ||
| const [isDark, setIsDark] = useState(() => { | ||
| const savedTheme = localStorage.getItem("theme"); | ||
| if (savedTheme === "dark") return true; | ||
| if (savedTheme === "light") return false; | ||
|
|
||
| // No saved preference β fallback to OS setting | ||
| return window.matchMedia("(prefers-color-scheme: dark)").matches; | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| const root = window.document.documentElement; | ||
|
|
||
| if (isDark) { | ||
| root.classList.add("dark"); | ||
| localStorage.setItem("theme", "dark"); | ||
| } else { | ||
| root.classList.remove("dark"); | ||
| localStorage.setItem("theme", "light"); | ||
| } | ||
| }, [isDark]); | ||
|
|
||
| return ( | ||
| <button | ||
| onClick={() => setIsDark((prev) => !prev)} | ||
| className="p-2 rounded-full bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 transition" | ||
| aria-label="Toggle light/dark mode" | ||
| > | ||
| {isDark ? ( | ||
| <Sun className="text-yellow-400" /> | ||
| ) : ( | ||
| <Moon className="text-gray-800" /> | ||
| )} | ||
| </button> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,17 +6,29 @@ import Navbar from "./components/Navbar"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import Verify from "./components/Verify"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import NotFound from "./components/NotFound"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import DarkVeil from "./components/DarkVeil"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import About from './components/About'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import SignUp from './components/SignUp'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import SignIn from './components/SignIn'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import About from "./components/About"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import SignUp from "./components/SignUp"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import SignIn from "./components/SignIn"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import ThemeToggle from "./components/ThemeToggle"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <header className="flex justify-end p-4"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <ThemeToggle /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </header>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+14
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π οΈ Refactor suggestion Integrate header within the App component. The header is currently rendered outside the App component, which creates a disconnected UI structure. Consider integrating it within the main App component for better component hierarchy. // Remove standalone header
-<header className="flex justify-end p-4">
- <ThemeToggle />
-</header>;
function App() {
return (
<div
style={{
position: "relative",
minHeight: "100vh",
width: "100vw",
overflow: "hidden",
}}
>
<div style={{ position: "absolute", inset: 0, zIndex: 0 }}>
<DarkVeil />
</div>
<div style={{ position: "relative", zIndex: 1 }}>
+ <header className="flex justify-end p-4">
+ <ThemeToggle />
+ </header>
<Router>
<Navbar />
// ... rest of componentπ Committable suggestion
Suggested change
π€ Prompt for AI Agents
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will check that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Kavyasrigotte, sounds good! Feel free to reach out if you need any clarification or run into any issues while implementing the header integration. I'm here to help!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Kavyasrigotte, you're very welcome! Happy to help. Good luck with the header integration - the theme toggle feature looks great overall! π |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function App() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div style={{ position: 'relative', minHeight: '100vh', width: '100vw', overflow: 'hidden' }}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div style={{ position: 'absolute', inset: 0, zIndex: 0 }}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| style={{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| position: "relative", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| minHeight: "100vh", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| width: "100vw", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| overflow: "hidden", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div style={{ position: "absolute", inset: 0, zIndex: 0 }}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <DarkVeil /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div style={{ position: 'relative', zIndex: 1 }}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div style={{ position: "relative", zIndex: 1 }}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Router> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Navbar /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Toaster | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π οΈ Refactor suggestion
Fix file location and add error handling.
The component implementation is solid, but there are several issues to address:
Backendfolder.Apply these fixes:
// Move file from Backend/Theme.jsx to Frontend/src/components/ThemeToggle.jsx import { useEffect, useState } from "react"; import { Sun, Moon } from "lucide-react"; export default function ThemeToggle() { const [isDark, setIsDark] = useState(() => { + try { const savedTheme = localStorage.getItem("theme"); if (savedTheme === "dark") return true; if (savedTheme === "light") return false; // No saved preference β fallback to OS setting + if (typeof window !== "undefined") { return window.matchMedia("(prefers-color-scheme: dark)").matches; + } + return false; // Default for SSR + } catch { + return false; // Fallback if localStorage fails + } }); useEffect(() => { + try { const root = window.document.documentElement; if (isDark) { root.classList.add("dark"); localStorage.setItem("theme", "dark"); } else { root.classList.remove("dark"); localStorage.setItem("theme", "light"); } + } catch { + // Handle localStorage errors gracefully + } }, [isDark]);π Committable suggestion
π€ Prompt for AI Agents