Multiuser support (#60)

This commit is contained in:
Doh
2025-02-18 23:43:23 -05:00
committed by GitHub
parent 363b31e934
commit 8ac2ec053d
48 changed files with 2678 additions and 271 deletions

View File

@@ -0,0 +1,40 @@
import { Badge } from '@/components/ui/badge'
import { Habit } from '@/lib/types'
import { isHabitDue, getCompletionsForDate } from '@/lib/utils'
interface CompletionCountBadgeProps {
habits: Habit[]
selectedDate: luxon.DateTime
timezone: string
type: 'tasks' | 'habits'
}
export function CompletionCountBadge({ habits, selectedDate, timezone, type }: CompletionCountBadgeProps) {
const filteredHabits = habits.filter(habit => {
const isTask = type === 'tasks'
if ((habit.isTask === isTask) && isHabitDue({
habit,
timezone,
date: selectedDate
})) {
const completions = getCompletionsForDate({ habit, date: selectedDate, timezone })
return completions >= (habit.targetCompletions || 1)
}
return false
}).length
const totalHabits = habits.filter(habit =>
(habit.isTask === (type === 'tasks')) &&
isHabitDue({
habit,
timezone,
date: selectedDate
})
).length
return (
<Badge variant="secondary">
{`${filteredHabits}/${totalHabits} Completed`}
</Badge>
)
}