File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { useLayoutEffect , useRef } from 'react'
12import SortableList , { SortableItem } from 'react-easy-sort'
23import { SUPPORTED_CARDS } from 'src/config'
34import { CustomRssCard } from 'src/features/cards'
5+ import { trackPageDrag } from 'src/lib/analytics'
46import { useUserPreferences } from 'src/stores/preferences'
57import { SelectedCard , SupportedCardType } from 'src/types'
68
@@ -12,17 +14,27 @@ export const DesktopCards = ({
1214 userCustomCards : SupportedCardType [ ]
1315} ) => {
1416 const AVAILABLE_CARDS = [ ...SUPPORTED_CARDS , ...userCustomCards ]
15-
1617 const { updateCardOrder } = useUserPreferences ( )
18+ const scrollHolderRef = useRef < HTMLElement | null > ( null )
1719
1820 const onSortEnd = ( oldIndex : number , newIndex : number ) => {
1921 updateCardOrder ( oldIndex , newIndex )
22+ trackPageDrag ( )
23+ if ( newIndex === 0 || ( oldIndex > 3 && newIndex < 3 ) ) {
24+ scrollHolderRef . current ?. scrollTo ( 0 , 0 )
25+ }
2026 }
2127
28+ useLayoutEffect ( ( ) => {
29+ scrollHolderRef . current = document . querySelector ( '.Cards' )
30+ } , [ ] )
31+
2232 return (
2333 < SortableList
2434 as = "div"
2535 onSortEnd = { onSortEnd }
36+ lockAxis = "x"
37+ customHolderRef = { scrollHolderRef }
2638 className = "Cards HorizontalScroll"
2739 draggedItemClassName = "draggedBlock" >
2840 { cards
You can’t perform that action at this time.
0 commit comments