feat: add habits to today overview
ci / gitleaks (push) Successful in 35s
ci / docker (push) Successful in 4m0s

This commit is contained in:
2026-09-08 13:49:21 +08:00
parent 11400025ba
commit 0f8955e890
4 changed files with 26 additions and 4 deletions
+10 -1
View File
@@ -9,7 +9,11 @@ type View = 'habits' | 'today-habits' | 'settings'
type Habit = { id: string; name: string; kind?: string; target?: number; max_value?: number | null; unit?: string; cells?: Array<{ day: string; scheduled?:boolean; paused?:boolean; value: number | boolean }>; stats?: Record<string, number> }
type Session = { id: string; created_at?: string; last_seen_at?: string; current?: boolean; user_agent?: string }
const props = defineProps<{ view: View }>()
const emit = defineEmits<{ changed: []; notice: [message: string] }>()
const emit = defineEmits<{
changed: []
notice: [message: string]
summary: [value: { total: number; completed: number }]
}>()
const habits = ref<Habit[]>([])
const sessions = ref<Session[]>([])
const audit = ref<any[]>([])
@@ -39,6 +43,11 @@ const hideCompletedHabits = ref(readStoredBoolean(window.localStorage, HIDE_COMP
const todayHabits = computed(() => habits.value.filter((item) => isHabitScheduledToday(item, todayKey.value)))
const visibleTodayHabits = computed(() => hideCompletedHabits.value ? todayHabits.value.filter((item) => !isDone(item, todayKey.value)) : todayHabits.value)
const visibleHabits = computed(() => hideCompletedHabits.value ? habits.value.filter((item) => !isDone(item, todayKey.value)) : habits.value)
const todayHabitSummary = computed(() => ({
total: todayHabits.value.length,
completed: todayHabits.value.filter((item) => isDone(item, todayKey.value)).length,
}))
watch(todayHabitSummary, (value) => emit('summary', value), { immediate: true })
watch(hideCompletedHabits, (value) => writeStoredBoolean(window.localStorage, HIDE_COMPLETED_HABITS_STORAGE_KEY, value))
let dayRolloverTimer: ReturnType<typeof setInterval> | undefined