Skip to content

Commit 9d3de38

Browse files
committed
✨ Add current target bar on LoggedTimeBadge
1 parent b7bf451 commit 9d3de38

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

src/app/features/TimeEntries/components/LoggedStats/LoggedStats.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@ export const TimeReportedStats = () => {
1717
// TODO: this should calculate average reported time but only for days which has entries
1818
const thisWeekReportedTime = useAppSelector(selectThisWeekReportedTime);
1919

20+
const dayOfWeek = (new Date().getDay() + 6) % 7;
21+
const weekTargetHoursToDate = 6 * (dayOfWeek + 1);
22+
2023
// TODO: use constant from settings
2124
const todayPercentage = (todayReportedTime / hoursToMs(6)) * 100;
2225
const todayGrade = calculateGrade(todayPercentage);
2326

2427
// TODO: use constant from settings
25-
const weekPercentage = (thisWeekReportedTime / hoursToMs(6 * 5)) * 100;
28+
const weekPercentage =
29+
(thisWeekReportedTime / hoursToMs(weekTargetHoursToDate)) * 100;
2630
const weekGrade = calculateGrade(weekPercentage);
2731

2832
const isAdjustableTimeReportingEnabled = useAppSelector(
@@ -51,6 +55,7 @@ export const TimeReportedStats = () => {
5155
reportedTimePerDay={thisWeekReportedTime}
5256
// TODO: use constant from settings
5357
targetHours={6 * 5}
58+
targetHoursToDate={weekTargetHoursToDate}
5459
/>
5560
<GradeIcon grade={weekGrade} />
5661
</div>

src/app/features/TimeEntries/components/LoggedTimeBadge/LoggedTimeBadge.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ export const LoggedTimeBadge = ({
44
label,
55
reportedTimePerDay,
66
targetHours,
7+
targetHoursToDate,
78
}: {
89
label: string;
910
targetHours: number;
1011
reportedTimePerDay: number;
12+
targetHoursToDate?: number; // used for showing target as a marker on the progress bar
1113
}) => {
1214
const percentage = (reportedTimePerDay / hoursToMs(targetHours)) * 100;
13-
const grade = calculateGrade(percentage);
15+
const percentageToDate = targetHoursToDate
16+
? (reportedTimePerDay / hoursToMs(targetHoursToDate)) * 100
17+
: undefined;
18+
const grade = calculateGrade(percentageToDate ?? percentage);
1419

1520
const colors = {
1621
bad: "#ba4244",
@@ -31,6 +36,9 @@ export const LoggedTimeBadge = ({
3136
case "GOOD":
3237
backgroundColor = colors.good;
3338
break;
39+
case "GREAT":
40+
backgroundColor = colors.good;
41+
break;
3442
}
3543

3644
return (
@@ -53,6 +61,14 @@ export const LoggedTimeBadge = ({
5361
}}
5462
/>
5563
</div>
64+
{targetHoursToDate && (
65+
<div
66+
className="w-[2px] h-1 bg-black absolute"
67+
style={{
68+
left: `${(targetHoursToDate / targetHours) * 100}%`,
69+
}}
70+
/>
71+
)}
5672
</div>
5773
);
5874
};

0 commit comments

Comments
 (0)