fix: replay completion motion reliably
ci / gitleaks (push) Successful in 6s
ci / docker (push) Successful in 3m29s

This commit is contained in:
2026-09-09 09:52:53 +08:00
parent aff070d2f7
commit 17005b0a50
4 changed files with 55 additions and 25 deletions
+5 -8
View File
@@ -4,6 +4,7 @@ import { Activity, ArchiveRestore, Check, Download, FileJson, GripVertical, LogO
import { moveItemWithinScope } from './lib/task-utils'
import { dateKey, habitButtonNotice, habitButtonValue, isHabitComplete, isHabitScheduledToday, mergePage, nextHabitSwipeValue, previousHabitSwipeValue, readHabitGridCache, readStoredBoolean, shouldToggleRowSwipe, writeHabitGridCache, writeStoredBoolean } from './lib/mvp-utils'
import { csrfHeader } from './lib/csrf'
import { createCompletionPulse } from './lib/completion-motion'
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> }
@@ -43,6 +44,10 @@ const habitSwipeOffsets = ref<Record<string, number>>({})
const habitReorder = ref<{ id: string; startY: number; offsetY: number } | null>(null)
const habitReorderTarget = ref('')
const justCompletedHabitIds = ref(new Set<string>())
const markHabitJustCompleted = createCompletionPulse(
(id) => { justCompletedHabitIds.value = new Set(justCompletedHabitIds.value).add(id) },
(id) => { const next = new Set(justCompletedHabitIds.value); next.delete(id); justCompletedHabitIds.value = next },
)
const HIDE_COMPLETED_HABITS_STORAGE_KEY = 'dodo.hide-completed-habits'
const hideCompletedHabits = ref(readStoredBoolean(window.localStorage, HIDE_COMPLETED_HABITS_STORAGE_KEY, false))
const todayHabits = computed(() => habits.value.filter((item) => isHabitScheduledToday(item, todayKey.value)))
@@ -210,14 +215,6 @@ function setLocalHabitValue(h: Habit, next: number | boolean) {
})
}
function markHabitJustCompleted(id: string) {
justCompletedHabitIds.value = new Set(justCompletedHabitIds.value).add(id)
window.setTimeout(() => {
const next = new Set(justCompletedHabitIds.value)
next.delete(id)
justCompletedHabitIds.value = next
}, 420)
}
async function applyHabitSwipe(h: Habit, deltaX: number) {
const current = logFor(h, todayKey.value)?.value
const wasDone = isHabitComplete(h.kind, current, h.target ?? 1)