11import { useFocusEffect } from '@react-navigation/native' ;
22import { useNavigation } from '@react-navigation/native' ;
3- import React , {
4- ReactElement ,
5- memo ,
6- useCallback ,
7- useMemo ,
8- useState ,
9- } from 'react' ;
3+ import React , { ReactElement , memo , useCallback , useState } from 'react' ;
104import { useTranslation } from 'react-i18next' ;
115import { StyleSheet } from 'react-native' ;
126import DraggableFlatList , {
@@ -52,18 +46,6 @@ const Widgets = (): ReactElement => {
5246
5347 useFocusEffect ( useCallback ( ( ) => setEditing ( false ) , [ ] ) ) ;
5448
55- const sortedWidgets = useMemo ( ( ) => {
56- const savedWidgets = Object . keys ( widgets ) ;
57-
58- const sorted = savedWidgets . sort ( ( a , b ) => {
59- const indexA = sortOrder . indexOf ( a ) ;
60- const indexB = sortOrder . indexOf ( b ) ;
61- return indexA - indexB ;
62- } ) ;
63-
64- return sorted ;
65- } , [ widgets , sortOrder ] ) ;
66-
6749 const onDragEnd = useCallback (
6850 ( { data } ) => {
6951 const order = data . map ( ( id ) : string => id ) ;
@@ -83,7 +65,7 @@ const Widgets = (): ReactElement => {
8365 ( { item : id , drag } : RenderItemParams < string > ) : ReactElement => {
8466 const initiateDrag = ( ) : void => {
8567 // only allow dragging if there are more than 1 widget
86- if ( sortedWidgets . length > 1 && editing ) {
68+ if ( sortOrder . length > 1 && editing ) {
8769 drag ( ) ;
8870 }
8971 } ;
@@ -168,14 +150,14 @@ const Widgets = (): ReactElement => {
168150 />
169151 ) ;
170152 } ,
171- [ editing , widgets , sortedWidgets . length ] ,
153+ [ editing , widgets , sortOrder . length ] ,
172154 ) ;
173155
174156 return (
175157 < View style = { styles . root } >
176158 < View style = { styles . title } testID = "WidgetsTitle" >
177159 < Caption13Up color = "secondary" > { t ( 'widgets' ) } </ Caption13Up >
178- { sortedWidgets . length > 0 && (
160+ { sortOrder . length > 0 && (
179161 < TouchableOpacity
180162 hitSlop = { { top : 15 , right : 15 , bottom : 15 , left : 15 } }
181163 testID = "WidgetsEdit"
@@ -190,7 +172,7 @@ const Widgets = (): ReactElement => {
190172 </ View >
191173
192174 < DraggableFlatList
193- data = { sortedWidgets }
175+ data = { sortOrder }
194176 keyExtractor = { ( id ) : string => id }
195177 renderItem = { ( params ) : ReactElement => (
196178 < ScaleDecorator > { renderItem ( params ) } </ ScaleDecorator >
0 commit comments