Skip to content

Commit

Permalink
✨ (CursorAnimation.js): Add ErrorBoundary component to catch errors a…
Browse files Browse the repository at this point in the history
…nd improve error handling in AnimatedPointer component

♻️ (NavLinks.jsx): Remove commented out code for status link in NavLinks component
♻️ (NavLinks.scss): Adjust padding in .navBar li to improve spacing in navigation bar
  • Loading branch information
Milan-960 committed Oct 5, 2024
1 parent 24a03fc commit e9846cd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 14 deletions.
61 changes: 50 additions & 11 deletions src/components/Animation/CursorAnimation.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,56 @@
import React from "react";
import React, { useEffect, useState } from "react";
import AnimatedCursor from "react-animated-cursor";

// ErrorBoundary component to catch errors
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}

static getDerivedStateFromError() {
// Update state so the next render will show the fallback UI
return { hasError: true };
}

componentDidCatch(error, info) {
// Log the error to an error reporting service if needed
console.error("Error caught in ErrorBoundary:", error, info);
}

render() {
if (this.state.hasError) {
// You can render any fallback UI
return <div>Error loading cursor</div>;
}

return this.props.children;
}
}

export default function AnimatedPointer() {
const [isClient, setIsClient] = useState(false);

// Ensure the component only renders on the client side (not SSR)
useEffect(() => {
if (typeof window !== "undefined") {
setIsClient(true);
}
}, []);

// Only render AnimatedCursor if on the client side
return (
<div className="App">
<AnimatedCursor
innerSize={8}
outerSize={22}
color="193, 11, 111"
outerAlpha={0.5}
innerScale={0.2}
outerScale={2}
/>
</div>
isClient && (
<ErrorBoundary>
<AnimatedCursor
innerSize={8}
outerSize={22}
color="193, 11, 111"
outerAlpha={0.5}
innerScale={0.2}
outerScale={2}
/>
</ErrorBoundary>
)
);
}
4 changes: 2 additions & 2 deletions src/components/Navigation/NavLinks/NavLinks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const NavLinks = () => {
</a>
</li>

{/* <li>
<li>
<a
href="https://status.milansachani.dev"
target="_blank"
Expand All @@ -99,7 +99,7 @@ const NavLinks = () => {
<GiNetworkBars />
{t("navbar.status")}
</a>
</li> */}
</li>

<li>
<LanguageSwitch />
Expand Down
2 changes: 1 addition & 1 deletion src/styles/Components/Navigation/_NavLinks.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}

.navBar li {
padding: 0.2rem 1.5rem;
padding: 0.2rem 0.6rem;
}

.active {
Expand Down

0 comments on commit e9846cd

Please sign in to comment.