-
Notifications
You must be signed in to change notification settings - Fork 201
Task Done #525
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
Task Done #525
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 |
|---|---|---|
| @@ -1,17 +1,29 @@ | ||
| import { NavLink, Link } from "react-router-dom"; | ||
| import { useState, useContext } from "react"; | ||
| import { useState, useContext, useRef } from "react"; | ||
| import { ThemeContext } from "../context/ThemeContext"; | ||
| import { Moon, Sun, Menu, X, Github } from "lucide-react"; | ||
|
|
||
| const Navbar: React.FC = () => { | ||
| const [isOpen, setIsOpen] = useState(false); | ||
| const [isThemeToggling, setIsThemeToggling] = useState(false); | ||
| const themeToggleRef = useRef<HTMLButtonElement>(null); | ||
|
|
||
| const themeContext = useContext(ThemeContext); | ||
|
|
||
| if (!themeContext) return null; | ||
|
|
||
| const { toggleTheme, mode } = themeContext; | ||
|
|
||
| const handleThemeToggle = () => { | ||
| setIsThemeToggling(true); | ||
| toggleTheme(); | ||
|
|
||
| // Reset animation state after transition | ||
| setTimeout(() => { | ||
| setIsThemeToggling(false); | ||
| }, 300); | ||
| }; | ||
|
Comment on lines
+17
to
+25
Contributor
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. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify timeout lifecycle handling in Navbar theme toggle
rg -n -C2 'handleThemeToggle|setTimeout|clearTimeout|isThemeToggling|useEffect' src/components/Navbar.tsxRepository: GitMetricsLab/github_tracker Length of output: 2086 🏁 Script executed: #!/bin/bash
set -euo pipefail
FILE="src/components/Navbar.tsx"
# Show the whole component header area (imports + state/refs + handleThemeToggle)
sed -n '1,120p' "$FILE"
# Check for any other usage of themeToggleRef in the file
echo "---- themeToggleRef usages ----"
rg -n "themeToggleRef" "$FILE" || trueRepository: GitMetricsLab/github_tracker Length of output: 4204 Stabilize theme-toggle timer lifecycle to avoid animation race conditions.
⏱️ Proposed fix-import { useState, useContext, useRef } from "react";
+import { useState, useContext, useRef, useEffect } from "react";
@@
- const themeToggleRef = useRef<HTMLButtonElement>(null);
+ const themeToggleTimeoutRef = useRef<number | null>(null);
@@
const handleThemeToggle = () => {
+ if (themeToggleTimeoutRef.current !== null) {
+ clearTimeout(themeToggleTimeoutRef.current);
+ }
setIsThemeToggling(true);
toggleTheme();
-
- // Reset animation state after transition
- setTimeout(() => {
+
+ // Reset animation state after transition
+ themeToggleTimeoutRef.current = window.setTimeout(() => {
setIsThemeToggling(false);
}, 300);
};
+
+ useEffect(() => {
+ return () => {
+ if (themeToggleTimeoutRef.current !== null) {
+ clearTimeout(themeToggleTimeoutRef.current);
+ }
+ };
+ }, []);
@@
- ref={themeToggleRef}
onClick={handleThemeToggle}🤖 Prompt for AI Agents |
||
|
|
||
| const navLinkStyles = ({ isActive }: { isActive: boolean }) => | ||
| `px-4 py-2 rounded-xl text-sm lg:text-base font-semibold transition-all duration-300 ${ | ||
| isActive | ||
|
|
@@ -59,14 +71,23 @@ const Navbar: React.FC = () => { | |
|
|
||
| {/* Theme Toggle */} | ||
| <button | ||
| onClick={toggleTheme} | ||
| className="ml-2 p-2 rounded-xl border border-gray-300 dark:border-gray-700 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors" | ||
| ref={themeToggleRef} | ||
| onClick={handleThemeToggle} | ||
| className="ml-2 p-2 rounded-xl border border-gray-300 dark:border-gray-700 hover:bg-gray-100 dark:hover:bg-gray-800 transition-all duration-300" | ||
| aria-label="Toggle Theme" | ||
| > | ||
| {mode === "dark" ? ( | ||
| <Sun className="h-5 w-5 text-yellow-400" /> | ||
| <Sun | ||
| className={`h-5 w-5 text-yellow-400 transition-all duration-300 ${ | ||
| isThemeToggling ? 'rotate-180 scale-0' : 'rotate-0 scale-100' | ||
| }`} | ||
| /> | ||
| ) : ( | ||
| <Moon className="h-5 w-5 text-slate-700" /> | ||
| <Moon | ||
| className={`h-5 w-5 text-slate-700 transition-all duration-300 ${ | ||
| isThemeToggling ? 'rotate-180 scale-0' : 'rotate-0 scale-100' | ||
| }`} | ||
| /> | ||
| )} | ||
| </button> | ||
| </div> | ||
|
|
@@ -76,14 +97,22 @@ const Navbar: React.FC = () => { | |
|
|
||
| {/* Theme Toggle */} | ||
| <button | ||
| onClick={toggleTheme} | ||
| className="p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors" | ||
| onClick={handleThemeToggle} | ||
| className="p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800 transition-all duration-300" | ||
| aria-label="Toggle Theme" | ||
| > | ||
| {mode === "dark" ? ( | ||
| <Sun className="h-5 w-5 text-yellow-400" /> | ||
| <Sun | ||
| className={`h-5 w-5 text-yellow-400 transition-all duration-300 ${ | ||
| isThemeToggling ? 'rotate-180 scale-0' : 'rotate-0 scale-100' | ||
| }`} | ||
| /> | ||
| ) : ( | ||
| <Moon className="h-5 w-5 text-white" /> | ||
| <Moon | ||
| className={`h-5 w-5 text-white transition-all duration-300 ${ | ||
| isThemeToggling ? 'rotate-180 scale-0' : 'rotate-0 scale-100' | ||
| }`} | ||
| /> | ||
| )} | ||
| </button> | ||
|
|
||
|
|
||
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.
Remove unused
Githubimport to satisfy lint checks.Line 4 imports
Githubbut it isn’t used, and ESLint already flags this as an error.🧹 Proposed fix
📝 Committable suggestion
🧰 Tools
🪛 ESLint
[error] 4-4: 'Github' is defined but never used.
(
@typescript-eslint/no-unused-vars)🤖 Prompt for AI Agents