feat(items): edit an item's quantity by swiping or right-clicking it

The PATCH endpoint now accepts quantity alongside completed (at least one
field is required), and the row shows the quantity only when its leading
number is above one. A small dialog edits it, opened by a left swipe on
touch or by right-clicking the row on desktop.
This commit is contained in:
Jose Selesan
2026-10-20 15:02:41 -03:00
parent 247ea903a9
commit db7cdd5585
10 changed files with 464 additions and 38 deletions

View File

@@ -38,3 +38,19 @@ export function splitItems(items: ListItem[], now: Date): SplitItems {
return { pending, boughtToday }
}
/**
* The quantity to show at the right of an item's name, or `null` when it must
* stay hidden. Only quantities above one earn their place in the row, so a
* plain "1" does not add noise: the leading number of the string is parsed
* ("2" → 2, "2 kg" → 2, "0,5" → 0.5) and anything without one is hidden.
*/
export function quantityLabel(quantity: string | null): string | null {
if (!quantity) return null
const trimmed = quantity.trim()
const leadingNumber = /^(\d+(?:[.,]\d+)?)/.exec(trimmed)
if (!leadingNumber) return null
return Number.parseFloat(leadingNumber[1].replace(',', '.')) > 1 ? trimmed : null
}