@@ -5,7 +5,7 @@ import type { Card, CollectionRow } from '@/types'
55import { type Row , createColumnHelper , getCoreRowModel , getGroupedRowModel , useReactTable } from '@tanstack/react-table'
66import { useVirtualizer } from '@tanstack/react-virtual'
77import { ID , type Models } from 'appwrite'
8- import { type FC , useMemo , useRef } from 'react'
8+ import { type FC , useEffect , useMemo , useRef , useState } from 'react'
99import FancyCard from '../../../components/FancyCard.tsx'
1010import type { Card as CardType } from '../../../types'
1111
@@ -88,6 +88,39 @@ export const Cards: FC<Props> = ({ user, ownedCards, setOwnedCards }) => {
8888
8989 const Pack = ( { cards } : { cards : CardType [ ] } ) => {
9090 const parentRef = useRef < HTMLDivElement > ( null )
91+ const [ scrollPosition , setScrollPosition ] = useState ( ( ) => {
92+ const savedPosition = localStorage . getItem ( 'scrollPosition' )
93+ return savedPosition ? Number . parseInt ( savedPosition , 10 ) : 0
94+ } )
95+
96+ useEffect ( ( ) => {
97+ const handleScroll = ( ) => {
98+ if ( parentRef . current ) {
99+ const newPosition = parentRef . current . scrollTop
100+ setScrollPosition ( newPosition )
101+ localStorage . setItem ( 'scrollPosition' , newPosition . toString ( ) )
102+ console . log ( 'handleScroll - scrollPosition:' , newPosition )
103+ }
104+ }
105+
106+ const parentElement = parentRef . current
107+ if ( parentElement ) {
108+ parentElement . addEventListener ( 'scroll' , handleScroll )
109+ }
110+
111+ return ( ) => {
112+ if ( parentElement ) {
113+ parentElement . removeEventListener ( 'scroll' , handleScroll )
114+ }
115+ }
116+ } , [ ] )
117+
118+ useEffect ( ( ) => {
119+ if ( parentRef . current ) {
120+ parentRef . current . scrollTop = scrollPosition
121+ console . log ( 'useEffect - scrollPosition set to:' , scrollPosition )
122+ }
123+ } , [ scrollPosition ] )
91124
92125 const columns = useMemo ( ( ) => {
93126 return [
0 commit comments