@@ -16,7 +16,7 @@ import ProjectDetail from '../components/projects/ProjectDetail';
1616import ProjectModal from '../components/projects/ProjectModal' ;
1717
1818const Projects = ( ) => {
19- const { _reducedMotion } = useAnimationContext ( ) ;
19+ const { reducedMotion } = useAnimationContext ( ) ;
2020 const [ isLoading , setIsLoading ] = useState ( true ) ;
2121 const [ error , setError ] = useState ( null ) ;
2222 const navigate = useNavigate ( ) ;
@@ -56,7 +56,7 @@ const Projects = () => {
5656 ( projectId , action = 'page' ) => {
5757 if ( action === 'reset' ) {
5858 resetFilters ( ) ;
59- navigate ( '/projects' ) ;
59+ navigate ( '/projects' , { replace : true } ) ;
6060 return ;
6161 }
6262
@@ -78,25 +78,38 @@ const Projects = () => {
7878 [ navigate , location . search , resetFilters , openProjectModal , projectsData , viewProjectDetails ]
7979 ) ;
8080
81- // Initialize project data and hooks
81+ // Check for direct project link in URL or reset view mode
8282 useEffect ( ( ) => {
83- if ( ! projectsLoading ) {
84- setIsLoading ( false ) ;
83+ // If we're not on a specific project page, ensure we're in gallery mode
84+ if ( ! location . search && viewMode !== 'gallery' ) {
85+ returnToGallery ( ) ;
8586 }
86-
87+
8788 // Check for direct project link in URL
8889 const urlParams = new URLSearchParams ( location . search ) ;
8990 const projectId = urlParams . get ( 'project' ) ;
91+
9092 if ( projectId && projectsData && projectsData . length > 0 ) {
93+ // If we have a project ID in the URL and data is loaded, show the project
9194 handleViewDetails ( projectId ) ;
9295 }
93- } , [ projectsLoading , projectsData , location . search , handleViewDetails ] ) ;
96+
97+ // Set loading state based on projects data
98+ if ( ! projectsLoading ) {
99+ setIsLoading ( false ) ;
100+ }
101+ } , [ projectsLoading , projectsData , location . search , handleViewDetails , viewMode , returnToGallery ] ) ;
94102
95- // Handle back to gallery
103+ // Handle back to gallery with proper state management
96104 const handleBackToGallery = ( ) => {
97- // Update URL to remove project parameter
98- navigate ( '/projects' ) ;
105+ // First reset state - this is important to do BEFORE navigation
99106 returnToGallery ( ) ;
107+
108+ // Then update URL (after state is reset)
109+ // This prevents the temporary blank page
110+ setTimeout ( ( ) => {
111+ navigate ( '/projects' , { replace : true } ) ;
112+ } , 0 ) ;
100113 } ;
101114
102115 return (
@@ -276,4 +289,4 @@ const Projects = () => {
276289 ) ;
277290} ;
278291
279- export default Projects ;
292+ export default Projects ;
0 commit comments