mirror of
https://github.com/harivansh-afk/Habit-Tracker.git
synced 2026-04-15 21:03:24 +00:00
cleaned up habitlist.tsx
This commit is contained in:
parent
081963cc21
commit
c49fa67d32
2 changed files with 2 additions and 30 deletions
|
|
@ -39,6 +39,7 @@ const calculateStreak = (completedDates: string[]): { currentStreak: number; bes
|
|||
currentStreak = 0;
|
||||
} else {
|
||||
// Start counting current streak from today
|
||||
/* eslint-disable-next-line prefer-const */
|
||||
let checkDate = new Date(today);
|
||||
currentStreak = 1; // Start with 1 for today
|
||||
|
||||
|
|
@ -89,35 +90,6 @@ const calculateStreak = (completedDates: string[]): { currentStreak: number; bes
|
|||
return { currentStreak, bestStreak };
|
||||
};
|
||||
|
||||
const getCurrentWeekDates = () => {
|
||||
// Start with Sunday (today's week)
|
||||
const now = new Date();
|
||||
const sunday = new Date(now);
|
||||
sunday.setDate(now.getDate() - now.getDay());
|
||||
|
||||
const weekDates = [];
|
||||
for (let i = 0; i < 7; i++) {
|
||||
const date = new Date(sunday);
|
||||
date.setDate(sunday.getDate() + i);
|
||||
// Format as YYYY-MM-DD
|
||||
const formattedDate = date.toISOString().split('T')[0];
|
||||
weekDates.push(formattedDate);
|
||||
}
|
||||
|
||||
return weekDates;
|
||||
};
|
||||
|
||||
// If you want Monday first, rotate the array
|
||||
const currentWeek = (() => {
|
||||
const dates = getCurrentWeekDates();
|
||||
// Move Sunday to the end
|
||||
const sunday = dates.shift()!;
|
||||
dates.push(sunday);
|
||||
return dates;
|
||||
})();
|
||||
|
||||
const daysOfWeek = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
||||
|
||||
export function HabitList({
|
||||
habits,
|
||||
currentWeek,
|
||||
|
|
@ -183,7 +155,7 @@ export function HabitList({
|
|||
? habit.completedDates.filter(d => d !== date)
|
||||
: [...habit.completedDates, date];
|
||||
|
||||
const { currentStreak, bestStreak } = calculateStreak(newCompletedDates);
|
||||
const { bestStreak } = calculateStreak(newCompletedDates);
|
||||
onUpdateStreak(habit.id, bestStreak);
|
||||
}}
|
||||
aria-label={`Mark ${habit.name} as completed for ${date}`}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue