mirror of
https://github.com/taskgenius/taskgenius-plugin.git
synced 2026-07-22 06:40:25 +00:00
fix(habit): use boolean values for daily habit completion tracking
- Change daily habit completion from numeric (0/1) to boolean (true/false) for simple habits - Keep numeric value (1) only for habits with completionText to indicate match - Update type definitions to support boolean | string | number | null - Fix completion checking to use strict equality (=== true) instead of truthy values
This commit is contained in:
parent
6e06d6105f
commit
5550cb0f38
3 changed files with 8 additions and 8 deletions
|
|
@ -60,8 +60,8 @@ export class DailyHabitCard extends HabitCard {
|
|||
// If completionText is defined, check if value is 1 (meaning it matched completionText)
|
||||
isCompletedToday = todayValue === 1;
|
||||
} else {
|
||||
// Default behavior: any truthy value means completed
|
||||
isCompletedToday = !!todayValue;
|
||||
// Default behavior: check for boolean true
|
||||
isCompletedToday = todayValue === true;
|
||||
}
|
||||
|
||||
checkbox.checked = isCompletedToday;
|
||||
|
|
@ -85,8 +85,8 @@ export class DailyHabitCard extends HabitCard {
|
|||
if (this.habit.completionText) {
|
||||
return value === 1;
|
||||
}
|
||||
// Default behavior: any truthy value means completed
|
||||
return value > 0;
|
||||
// Default behavior: check for boolean true
|
||||
return value === true;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -193,10 +193,10 @@ export class HabitCard extends Component {
|
|||
case "daily":
|
||||
const dailyHabit = habitToUpdate as DailyHabitProps;
|
||||
if (dailyHabit.completionText) {
|
||||
newCompletionValue = currentCompletionToday === 1 ? 0 : 1;
|
||||
newCompletionValue = currentCompletionToday === 1 ? null : 1;
|
||||
} else {
|
||||
// Default behavior: toggle between 0 and 1
|
||||
newCompletionValue = currentCompletionToday ? 0 : 1;
|
||||
// Default behavior: toggle between true and false
|
||||
newCompletionValue = currentCompletionToday ? false : true;
|
||||
}
|
||||
break;
|
||||
case "count":
|
||||
|
|
|
|||
2
src/types/habit-card.d.ts
vendored
2
src/types/habit-card.d.ts
vendored
|
|
@ -50,7 +50,7 @@ export type BaseHabitData =
|
|||
|
||||
// DailyHabitProps
|
||||
export interface DailyHabitProps extends BaseDailyHabitData {
|
||||
completions: Record<string, string | number>; // String is date, string or number is completion value
|
||||
completions: Record<string, boolean | string | number | null>; // Date -> boolean (for simple check), number (for completionText), null (for unchecked)
|
||||
}
|
||||
|
||||
// CountHabitProps
|
||||
|
|
|
|||
Loading…
Reference in a new issue