Skip to content

Commit 9a154bd

Browse files
committed
Sort history by recency and completed first
1 parent 245ed7f commit 9a154bd

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

KonditionExpo/app/(tabs)/history.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,19 @@ const WorkoutHistoryScreen = () => {
241241
) : !Array.isArray(workouts) || workouts.length === 0 ? (
242242
renderEmptyState()
243243
) : (
244-
workouts.map(renderWorkoutItem)
244+
[...workouts]
245+
.sort((a, b) => {
246+
// 1. Completed workouts first
247+
if (a.is_completed !== b.is_completed) {
248+
return b.is_completed ? 1 : -1;
249+
}
250+
251+
// 2. Then sort by date (fallback to created_at if completed_date is missing)
252+
const aDate = new Date(a.completed_date || a.created_at).getTime();
253+
const bDate = new Date(b.completed_date || b.created_at).getTime();
254+
return bDate - aDate;
255+
})
256+
.map(renderWorkoutItem)
245257
)}
246258
</ScrollView>
247259
</SafeAreaView>

0 commit comments

Comments
 (0)