@@ -16,7 +16,7 @@ import ProjectDetail from '../components/projects/ProjectDetail';
16
16
import ProjectModal from '../components/projects/ProjectModal' ;
17
17
18
18
const Projects = ( ) => {
19
- const { _reducedMotion } = useAnimationContext ( ) ;
19
+ const { reducedMotion } = useAnimationContext ( ) ;
20
20
const [ isLoading , setIsLoading ] = useState ( true ) ;
21
21
const [ error , setError ] = useState ( null ) ;
22
22
const navigate = useNavigate ( ) ;
@@ -56,7 +56,7 @@ const Projects = () => {
56
56
( projectId , action = 'page' ) => {
57
57
if ( action === 'reset' ) {
58
58
resetFilters ( ) ;
59
- navigate ( '/projects' ) ;
59
+ navigate ( '/projects' , { replace : true } ) ;
60
60
return ;
61
61
}
62
62
@@ -78,25 +78,38 @@ const Projects = () => {
78
78
[ navigate , location . search , resetFilters , openProjectModal , projectsData , viewProjectDetails ]
79
79
) ;
80
80
81
- // Initialize project data and hooks
81
+ // Check for direct project link in URL or reset view mode
82
82
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 ( ) ;
85
86
}
86
-
87
+
87
88
// Check for direct project link in URL
88
89
const urlParams = new URLSearchParams ( location . search ) ;
89
90
const projectId = urlParams . get ( 'project' ) ;
91
+
90
92
if ( projectId && projectsData && projectsData . length > 0 ) {
93
+ // If we have a project ID in the URL and data is loaded, show the project
91
94
handleViewDetails ( projectId ) ;
92
95
}
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 ] ) ;
94
102
95
- // Handle back to gallery
103
+ // Handle back to gallery with proper state management
96
104
const handleBackToGallery = ( ) => {
97
- // Update URL to remove project parameter
98
- navigate ( '/projects' ) ;
105
+ // First reset state - this is important to do BEFORE navigation
99
106
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 ) ;
100
113
} ;
101
114
102
115
return (
@@ -276,4 +289,4 @@ const Projects = () => {
276
289
) ;
277
290
} ;
278
291
279
- export default Projects ;
292
+ export default Projects ;
0 commit comments