Skip to content

Commit b625545

Browse files
committed
better task ordering
1 parent 1a98200 commit b625545

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

config/theme.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { red } from "react-native-reanimated/lib/typescript/reanimated2/Colors";
2+
13
const theme = {
24
colors: {
35
purple: {
@@ -10,6 +12,9 @@ const theme = {
1012
gray4: "#585858",
1113
gray5: "#CACACA",
1214
},
15+
red: {
16+
red1: "#bd0000",
17+
}
1318
},
1419
};
1520

screens/Activities/index.tsx

+28-2
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,39 @@ const Activities = () => {
118118
</Paragraph>
119119
<ScrollView contentContainerStyle={{ gap: 8 }}>
120120
<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) => (
122146
<Card
123147
key={`activity-${activity.id}`}
124148
title={activity.name}
125149
color={
126150
verifyIfIsActivityFinished(activity.finishDate)
127-
? theme.colors.gray.gray2
151+
? activity.checked
152+
? theme.colors.gray.gray2
153+
: theme.colors.red.red1
128154
: activity.checked
129155
? theme.colors.gray.gray4
130156
: getActivityColorByType(activity.type)

0 commit comments

Comments
 (0)