From c49fa67d327e366a8c936641d52da0481da2293b Mon Sep 17 00:00:00 2001 From: rathi Date: Mon, 18 Nov 2024 13:53:40 -0500 Subject: [PATCH] cleaned up habitlist.tsx --- habits.db | Bin 20480 -> 20480 bytes src/components/HabitList.tsx | 32 ++------------------------------ 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/habits.db b/habits.db index ad7d8ffd0f6f9b3f32d700163936b3e0f42e9951..ad88032d6520eb7b36b42870aff03d2636cec6e5 100644 GIT binary patch delta 351 zcmZozz}T>Wae_2skBcGvpc7Hvg1o6W~ze<-g2O%yD=!yTMI9P8CiOP8NWae_3X+e8^>Mz@U#GvpanH~*Ap6W~zg<-g33!)Y>^-QecN#t@FpCYBf2 Wm~%KzOlEhuxv}vD`{olK7VH46m=-($ diff --git a/src/components/HabitList.tsx b/src/components/HabitList.tsx index 4c7adb3..2361676 100644 --- a/src/components/HabitList.tsx +++ b/src/components/HabitList.tsx @@ -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}`}