1- import React , { useState , useEffect , useMemo } from 'react' ;
1+ import React , { useState , useEffect , useMemo , useLayoutEffect } from 'react' ;
22import ShareModal from '@/components/ShareModal' ;
33import { useNavigate , useParams , useLocation } from 'react-router-dom' ;
44import { getAllPosts , groupPostsByCategory , Post } from '@/utils/posts-utils' ;
@@ -49,6 +49,18 @@ const NewsPage: React.FC = () => {
4949 return params . get ( 'q' ) || '' ;
5050 } ) ;
5151
52+ useLayoutEffect ( ( ) => {
53+ if ( ! isLoading ) {
54+ const savedY = Number ( sessionStorage . getItem ( 'newsScrollY' ) || 0 ) ;
55+ if ( savedY > 0 ) {
56+ requestAnimationFrame ( ( ) => {
57+ window . scrollTo ( { top : savedY , behavior : 'auto' } ) ;
58+ } ) ;
59+ }
60+ sessionStorage . removeItem ( 'newsScrollY' ) ;
61+ }
62+ } , [ isLoading , activeCategory , searchTerm ] ) ;
63+
5264 useEffect ( ( ) => {
5365 async function load ( ) {
5466 setIsLoading ( true ) ;
@@ -127,7 +139,10 @@ const NewsPage: React.FC = () => {
127139
128140 const hasMore = filteredPosts . length > displayCount ;
129141
130- const handleCategoryClick = ( cat : string ) => setActiveCategory ( cat ) ;
142+ const handleCategoryClick = ( cat : string ) => {
143+ sessionStorage . setItem ( 'newsScrollY' , String ( window . scrollY ) ) ;
144+ setActiveCategory ( cat ) ;
145+ } ;
131146
132147 const handleShowMore = ( ) => {
133148 const total = filteredPosts . length ;
@@ -260,7 +275,7 @@ const NewsPage: React.FC = () => {
260275 className = "text-blue-500 mr-4 animate-pulse"
261276 size = { 32 }
262277 />
263- < h1 className = "text-8xl font-bold font-Caveat text-transparent bg-clip-text bg-gradient-to-r from-blue-600 to-green-600" >
278+ < h1 className = "p-4 text-8xl font-bold font-Caveat text-transparent bg-clip-text bg-gradient-to-r from-blue-600 to-green-600" >
264279 NEWS
265280 </ h1 >
266281 < TrendingUp
@@ -296,6 +311,10 @@ const NewsPage: React.FC = () => {
296311 value = { searchTerm }
297312 onChange = { ( e ) => {
298313 const value = e . target . value ;
314+ sessionStorage . setItem (
315+ 'newsScrollY' ,
316+ String ( window . scrollY ) ,
317+ ) ;
299318 setSearchTerm ( value ) ;
300319 const catPath =
301320 activeCategory === 'All'
@@ -561,7 +580,7 @@ const NewsPage: React.FC = () => {
561580 Read more
562581 < ArrowRight
563582 size = { 14 }
564- className = "ml-1 group-hover:translate-x-1 transition-transform duration-300"
583+ className = "ml-1 mt-1 group-hover:translate-x-1 transition-transform duration-300"
565584 />
566585 </ div >
567586 </ div >
@@ -584,7 +603,9 @@ const NewsPage: React.FC = () => {
584603 whileHover = "hover"
585604 whileTap = "tap"
586605 >
587- < div className = "absolute inset-0 bg-white opacity-0 group-hover:opacity-10 transition-opacity duration-300" > </ div >
606+ < div className = "relative group rounded-xl overflow-hidden" >
607+ < div className = "absolute inset-0 bg-white opacity-0 group-hover:opacity-10 transition-opacity duration-300 rounded-xl" > </ div >
608+ </ div >
588609 < span className = "relative z-10" > Load More Articles</ span >
589610 < ArrowRight
590611 size = { 18 }
0 commit comments