From e97e03b81495444a4af631c3769d4d29679446eb Mon Sep 17 00:00:00 2001 From: Mo Tarbin Date: Mon, 11 Aug 2025 17:01:27 -0400 Subject: [PATCH] Refactor: reorder imports and clean up whitespace in PageTransition component --- src/components/animations/PageTransition.jsx | 31 ++++++++++++-------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/components/animations/PageTransition.jsx b/src/components/animations/PageTransition.jsx index b2f714f..5fb011a 100644 --- a/src/components/animations/PageTransition.jsx +++ b/src/components/animations/PageTransition.jsx @@ -1,6 +1,6 @@ -import React, { useEffect, useRef } from 'react' -import { CSSTransition, TransitionGroup } from 'react-transition-group' +import { useEffect, useRef } from 'react' import { useLocation } from 'react-router-dom' +import { CSSTransition, TransitionGroup } from 'react-transition-group' import './PageTransition.css' // Route hierarchy for determining navigation direction @@ -24,7 +24,7 @@ const getRouteLevel = pathname => { if (routeHierarchy[pathname] !== undefined) { return routeHierarchy[pathname] } - + // Check for dynamic routes (e.g., /chores/123/edit) if (pathname.includes('/chores/') && pathname.includes('/edit')) { return 3 @@ -32,13 +32,17 @@ const getRouteLevel = pathname => { if (pathname.includes('/chores/') && pathname.includes('/history')) { return 3 } - if (pathname.includes('/chores/') && !pathname.includes('/edit') && !pathname.includes('/history')) { + if ( + pathname.includes('/chores/') && + !pathname.includes('/edit') && + !pathname.includes('/history') + ) { return 2 } if (pathname.includes('/things/')) { return 2 } - + // Default level return 1 } @@ -51,18 +55,23 @@ const PageTransition = ({ children }) => { useEffect(() => { const currentLevel = getRouteLevel(location.pathname) const previousLevel = getRouteLevel(prevLocation.current.pathname) - + // Determine if we're navigating back (to a higher level in hierarchy) isNavigatingBack.current = currentLevel < previousLevel - + window.scrollTo({ top: 0, left: 0, behavior: 'instant' }) + prevLocation.current = location }, [location]) const getTransitionClasses = () => { - if (location.pathname.includes('/login') || location.pathname.includes('/signup') || location.pathname.includes('/landing')) { + if ( + location.pathname.includes('/login') || + location.pathname.includes('/signup') || + location.pathname.includes('/landing') + ) { return 'fade' // Use fade for auth pages } - + return isNavigatingBack.current ? 'page-back' : 'page' } @@ -77,9 +86,7 @@ const PageTransition = ({ children }) => { }} unmountOnExit > -
- {children} -
+
{children}
)