@@ -118,13 +118,39 @@ const Activities = () => {
118
118
</ Paragraph >
119
119
< ScrollView contentContainerStyle = { { gap : 8 } } >
120
120
< Button text = "Adicionar Atividade" onPress = { handleNewActivityPress } />
121
- { userActivities . map ( ( activity , index ) => (
121
+ { userActivities
122
+ . sort ( ( a , b ) => {
123
+
124
+ // Then, sort by checked status, unchecked items first
125
+ if ( a . checked !== b . checked ) {
126
+ return a . checked ? 1 : - 1 ;
127
+ }
128
+
129
+ const today = new Date ( ) . setHours ( 0 , 0 , 0 , 0 ) ;
130
+
131
+ // First, sort by finish date, placing past dates at the bottom
132
+ const dateA = new Date ( a . finishDate ) . setHours ( 0 , 0 , 0 , 0 ) ;
133
+ const dateB = new Date ( b . finishDate ) . setHours ( 0 , 0 , 0 , 0 ) ;
134
+
135
+ if ( dateA !== dateB ) {
136
+ // Activities in the future or today come first, past activities come last
137
+ if ( dateA >= today && dateB >= today ) {
138
+ return dateA - dateB ; // Future or today, sort ascending by date
139
+ }
140
+ return dateA < today ? 1 : - 1 ; // Past dates to the bottom
141
+ }
142
+
143
+ return 0 ; // If both date and checked status are the same, keep original order
144
+ } )
145
+ . map ( ( activity , index ) => (
122
146
< Card
123
147
key = { `activity-${ activity . id } ` }
124
148
title = { activity . name }
125
149
color = {
126
150
verifyIfIsActivityFinished ( activity . finishDate )
127
- ? theme . colors . gray . gray2
151
+ ? activity . checked
152
+ ? theme . colors . gray . gray2
153
+ : theme . colors . red . red1
128
154
: activity . checked
129
155
? theme . colors . gray . gray4
130
156
: getActivityColorByType ( activity . type )
0 commit comments