1- import React from 'react'
1+ import SortableList , { SortableItem } from 'react-easy-sort '
22import { SUPPORTED_CARDS } from 'src/config'
33import { CustomRssCard } from 'src/features/cards'
4+ import { useUserPreferences } from 'src/stores/preferences'
45import { SelectedCard , SupportedCardType } from 'src/types'
56
67export const DesktopCards = ( {
@@ -11,20 +12,37 @@ export const DesktopCards = ({
1112 userCustomCards : SupportedCardType [ ]
1213} ) => {
1314 const AVAILABLE_CARDS = [ ...SUPPORTED_CARDS , ...userCustomCards ]
15+
16+ const { updateCardOrder } = useUserPreferences ( )
17+
18+ const onSortEnd = ( oldIndex : number , newIndex : number ) => {
19+ updateCardOrder ( oldIndex , newIndex )
20+ }
21+
1422 return (
15- < >
16- { cards . map ( ( card , index ) => {
17- const constantCard = AVAILABLE_CARDS . find ( ( c ) => c . value === card . name )
18- if ( ! constantCard ) {
19- return null
20- }
23+ < SortableList
24+ as = "div"
25+ onSortEnd = { onSortEnd }
26+ className = "AppContent HorizontalScroll"
27+ draggedItemClassName = "draggedBlock" >
28+ { cards
29+ . sort ( ( a , b ) => a . id - b . id )
30+ . map ( ( card , index ) => {
31+ const constantCard = AVAILABLE_CARDS . find ( ( c ) => c . value === card . name )
32+ if ( ! constantCard ) {
33+ return null
34+ }
35+
36+ const Component = constantCard ?. component || CustomRssCard
2137
22- return React . createElement ( constantCard ?. component || CustomRssCard , {
23- key : card . name ,
24- meta : constantCard ,
25- withAds : index === 0 ,
26- } )
27- } ) }
28- </ >
38+ return (
39+ < SortableItem key = { card . name } >
40+ < div >
41+ < Component key = { card . name } meta = { constantCard } withAds = { index === 0 } />
42+ </ div >
43+ </ SortableItem >
44+ )
45+ } ) }
46+ </ SortableList >
2947 )
3048}
0 commit comments