File tree Expand file tree Collapse file tree 4 files changed +36
-0
lines changed Expand file tree Collapse file tree 4 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -4,9 +4,11 @@ import Feed from '@/components/feed/Feed'
44import Footer from '@/components/footer/Footer'
55import Navigation from '@/components/navigation/Navigation'
66import { useFocusTrap } from '@/hooks/useFocusTrap'
7+ import { useSetWindowScrollY } from '@/hooks/useSetWindowScrollY'
78
89export default function Home ( ) {
910 useFocusTrap ( )
11+ useSetWindowScrollY ( )
1012
1113 return (
1214 < div className = "min-h-svh flex flex-col items-center justify-start bg-gradient-to-b from-stone-700 to-stone-800" >
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import {
1414import fetchFeedItems from '@/api/fetchFeedItems'
1515import { FeedItemsType } from '@/types/types'
1616import { getItemFromSessionStorage } from '@/utils/getItemFromSessionStorage'
17+ import { getWindowScrollY } from '@/utils/getWindowScrollY'
1718
1819const Feed = ( ) => {
1920 const PAGE_SIZE = 10
@@ -35,6 +36,8 @@ const Feed = () => {
3536
3637 if ( ! parsedStorageData ?. feedItems ?. length ) {
3738 loadMoreItems ( )
39+ } else {
40+ getWindowScrollY ( )
3841 }
3942 } , [ loadMoreItems ] )
4043
Original file line number Diff line number Diff line change 1+ 'use client'
2+
3+ import { useEffect } from 'react'
4+ import { setItemInSessionStorage } from '@/utils/setItemInSessionStorage'
5+
6+ export const useSetWindowScrollY = ( ) => {
7+ useEffect ( ( ) => {
8+ const onScroll = ( ) => {
9+ setItemInSessionStorage ( 'scrollY' , window . scrollY )
10+ }
11+
12+ window . addEventListener ( 'scroll' , onScroll )
13+
14+ return ( ) => window . removeEventListener ( 'scroll' , onScroll )
15+ } , [ ] )
16+ }
Original file line number Diff line number Diff line change 1+ import { getItemFromSessionStorage } from '@/utils/getItemFromSessionStorage'
2+
3+ export const getWindowScrollY = ( ) => {
4+ const parsedStorageData = getItemFromSessionStorage ( )
5+
6+ const scrollY = parsedStorageData ?. scrollY || 0
7+
8+ const scrollToPosition = ( ) => {
9+ window . scrollTo ( { top : scrollY , left : 0 , behavior : 'smooth' } )
10+ }
11+
12+ requestAnimationFrame ( ( ) => {
13+ setTimeout ( scrollToPosition , 0 )
14+ } )
15+ }
You can’t perform that action at this time.
0 commit comments