feat: use swipe to complete items
ci / docker (push) Successful in 3m22s

This commit is contained in:
2026-09-06 08:12:44 +08:00
parent 35e562026c
commit 13715945d5
10 changed files with 69 additions and 25 deletions
+8 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import { dateKey, habitWeek, isHabitComplete, isTaskView, numericHabitInputValue } from './mvp-utils'
import { dateKey, habitWeek, isHabitComplete, isTaskView, numericHabitInputValue, shouldToggleHabitSwipe } from './mvp-utils'
describe('MVP view utilities', () => {
it('formats a local date as YYYY-MM-DD', () => {
@@ -28,4 +28,11 @@ describe('MVP view utilities', () => {
expect(numericHabitInputValue('')).toBeNull()
expect(numericHabitInputValue(4)).toBe(4)
})
it('toggles a habit only for a deliberate horizontal swipe', () => {
expect(shouldToggleHabitSwipe(78, 8)).toBe(true)
expect(shouldToggleHabitSwipe(-78, 8)).toBe(false)
expect(shouldToggleHabitSwipe(30, 2)).toBe(false)
expect(shouldToggleHabitSwipe(80, 35)).toBe(false)
})
})
+4
View File
@@ -34,3 +34,7 @@ export function numericHabitInputValue(input: number | string | undefined) {
const value = Number(input)
return Number.isFinite(value) && value >= 0 ? value : null
}
export function shouldToggleHabitSwipe(deltaX: number, deltaY: number) {
return deltaX >= 64 && Math.abs(deltaY) <= 24 && deltaX > Math.abs(deltaY) * 1.5
}