Spaces:
Sleeping
Sleeping
Tristan Yu commited on
Commit ·
141c062
1
Parent(s): 263a752
Fix page transition animation - properly reset transition state after navigation
Browse files
client/src/components/Layout.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import React, { useState, useEffect } from 'react';
|
| 2 |
import { Link, useLocation } from 'react-router-dom';
|
| 3 |
import {
|
| 4 |
HomeIcon,
|
|
@@ -18,15 +18,16 @@ interface User {
|
|
| 18 |
const Layout: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
| 19 |
const location = useLocation();
|
| 20 |
const [isTransitioning, setIsTransitioning] = useState(false);
|
| 21 |
-
const
|
| 22 |
const userData = localStorage.getItem('user');
|
| 23 |
const user: User | null = userData ? JSON.parse(userData) : null;
|
| 24 |
|
| 25 |
// Handle page transitions
|
| 26 |
useEffect(() => {
|
| 27 |
-
|
|
|
|
| 28 |
setIsTransitioning(true);
|
| 29 |
-
|
| 30 |
|
| 31 |
// End transition after animation
|
| 32 |
const timer = setTimeout(() => {
|
|
@@ -35,7 +36,7 @@ const Layout: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
|
| 35 |
|
| 36 |
return () => clearTimeout(timer);
|
| 37 |
}
|
| 38 |
-
}, [location.pathname
|
| 39 |
|
| 40 |
const handleLogout = () => {
|
| 41 |
localStorage.removeItem('token');
|
|
|
|
| 1 |
+
import React, { useState, useEffect, useRef } from 'react';
|
| 2 |
import { Link, useLocation } from 'react-router-dom';
|
| 3 |
import {
|
| 4 |
HomeIcon,
|
|
|
|
| 18 |
const Layout: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
| 19 |
const location = useLocation();
|
| 20 |
const [isTransitioning, setIsTransitioning] = useState(false);
|
| 21 |
+
const previousPathRef = useRef(location.pathname);
|
| 22 |
const userData = localStorage.getItem('user');
|
| 23 |
const user: User | null = userData ? JSON.parse(userData) : null;
|
| 24 |
|
| 25 |
// Handle page transitions
|
| 26 |
useEffect(() => {
|
| 27 |
+
// Only trigger transition if path actually changed
|
| 28 |
+
if (location.pathname !== previousPathRef.current) {
|
| 29 |
setIsTransitioning(true);
|
| 30 |
+
previousPathRef.current = location.pathname;
|
| 31 |
|
| 32 |
// End transition after animation
|
| 33 |
const timer = setTimeout(() => {
|
|
|
|
| 36 |
|
| 37 |
return () => clearTimeout(timer);
|
| 38 |
}
|
| 39 |
+
}, [location.pathname]);
|
| 40 |
|
| 41 |
const handleLogout = () => {
|
| 42 |
localStorage.removeItem('token');
|