feat(items): edit quantity and notes inline, with swipe feedback
The PATCH endpoint now also accepts notes. Swiping an item to the left (or right-clicking it) opens an inline editor below the row for its quantity and notes, focused on the quantity input, instead of the quantity dialog. The row slides with the finger during the swipe and snaps back on release, and only one row edits at a time. Toggling an item no longer moves the focus to the add-item input, and notes show under the item's name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -79,10 +79,12 @@ export function useCreateItem(listId: string) {
|
||||
|
||||
type UpdateItemInput = {
|
||||
itemId: string
|
||||
/** New bought state; omitted when only the quantity is being changed. */
|
||||
/** New bought state; omitted when only the details are being changed. */
|
||||
completed?: boolean
|
||||
/** New quantity (`null` clears it); omitted when only the bought state changes. */
|
||||
/** New quantity (`null` clears it); omitted to leave it untouched. */
|
||||
quantity?: string | null
|
||||
/** New notes (`null` clears them); omitted to leave them untouched. */
|
||||
notes?: string | null
|
||||
}
|
||||
|
||||
const updateItemMutationKey = (listId: string) => ['lists', listId, 'items', 'update']
|
||||
@@ -95,16 +97,17 @@ export function useUpdateItem(listId: string) {
|
||||
return useMutation({
|
||||
mutationKey,
|
||||
mutationFn: (input: UpdateItemInput) => {
|
||||
const body: { completed?: boolean; quantity?: string | null } = {}
|
||||
const body: { completed?: boolean; quantity?: string | null; notes?: string | null } = {}
|
||||
if (input.completed !== undefined) body.completed = input.completed
|
||||
if (input.quantity !== undefined) body.quantity = input.quantity
|
||||
if (input.notes !== undefined) body.notes = input.notes
|
||||
|
||||
return apiFetch<ListItem>(`/lists/${listId}/items/${input.itemId}`, {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
},
|
||||
onMutate: async ({ itemId, completed, quantity }) => {
|
||||
onMutate: async ({ itemId, completed, quantity, notes }) => {
|
||||
// Cancel the outgoing refetch so it cannot overwrite our optimistic one.
|
||||
await queryClient.cancelQueries({ queryKey })
|
||||
|
||||
@@ -120,6 +123,7 @@ export function useUpdateItem(listId: string) {
|
||||
? { completed, boughtAt: completed ? new Date().toISOString() : null }
|
||||
: {}),
|
||||
...(quantity !== undefined ? { quantity: quantity?.trim() || null } : {}),
|
||||
...(notes !== undefined ? { notes: notes?.trim() || null } : {}),
|
||||
}
|
||||
}),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user