mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 15:17:30 +00:00
feat: quality of life sweep from the feature discussions
Small requests from the discussions, each built end to end: planner and map (cycling mode, date first headings, clear a day, stay times per day, off-route stops, map lock, compact unplanned markers, pending stays, cable car, transit quick picks), places (location filter, category from OSM, open in maps, geo: link, image from an attachment, enrichment on file import, places near a pin, place name language, Amap first in China), lists and costs (packed counter, inherited sharing, Markdown to-dos, payment notes, bookings CSV, my plan PDF), sharing (unplanned places, travel only, without photos), journey (photo zoom, drafts, photo order, trip suggestion, day jump), atlas (region counter, region bucket list, places per country), vacay half company holidays, studio copy and paste plus the book's own layouts, and RESTORE_FROM_BACKUP for a first start restore.
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import { resolvePackedState } from './packed-count';
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
|
||||
const open = { checked: 0, packed_quantity: null };
|
||||
|
||||
describe('resolvePackedState (#2296)', () => {
|
||||
it('PACKED-001: keeps a partial count and leaves the box unticked', () => {
|
||||
expect(resolvePackedState(open, { bodyKeys: ['packed_quantity'], packed_quantity: 4, quantity: 10 })).toEqual({
|
||||
checked: 0,
|
||||
packed_quantity: 4,
|
||||
});
|
||||
});
|
||||
|
||||
it('PACKED-002: a full or overfull count ticks the item and drops the count', () => {
|
||||
expect(resolvePackedState(open, { bodyKeys: ['packed_quantity'], packed_quantity: 10, quantity: 10 })).toEqual({
|
||||
checked: 1,
|
||||
packed_quantity: null,
|
||||
});
|
||||
expect(resolvePackedState(open, { bodyKeys: ['packed_quantity'], packed_quantity: 99, quantity: 10 })).toEqual({
|
||||
checked: 1,
|
||||
packed_quantity: null,
|
||||
});
|
||||
});
|
||||
|
||||
it('PACKED-003: zero or null clears the count and unticks a finished item', () => {
|
||||
const done = { checked: 1, packed_quantity: null };
|
||||
expect(resolvePackedState(done, { bodyKeys: ['packed_quantity'], packed_quantity: 0, quantity: 3 })).toEqual({
|
||||
checked: 0,
|
||||
packed_quantity: null,
|
||||
});
|
||||
expect(resolvePackedState(done, { bodyKeys: ['packed_quantity'], packed_quantity: null, quantity: 3 })).toEqual({
|
||||
checked: 0,
|
||||
packed_quantity: null,
|
||||
});
|
||||
});
|
||||
|
||||
it('PACKED-004: the box decides for the whole item', () => {
|
||||
const partial = { checked: 0, packed_quantity: 2 };
|
||||
expect(resolvePackedState(partial, { bodyKeys: ['checked'], checked: 1, quantity: 5 })).toEqual({
|
||||
checked: 1,
|
||||
packed_quantity: null,
|
||||
});
|
||||
expect(resolvePackedState(partial, { bodyKeys: ['checked'], checked: 0, quantity: 5 })).toEqual({
|
||||
checked: 0,
|
||||
packed_quantity: null,
|
||||
});
|
||||
});
|
||||
|
||||
it('PACKED-005: a lowered quantity the count reaches finishes the item, anything else is left alone', () => {
|
||||
const partial = { checked: 0, packed_quantity: 4 };
|
||||
expect(resolvePackedState(partial, { bodyKeys: ['quantity'], quantity: 4 })).toEqual({
|
||||
checked: 1,
|
||||
packed_quantity: null,
|
||||
});
|
||||
expect(resolvePackedState(partial, { bodyKeys: ['quantity'], quantity: 8 })).toBe(partial);
|
||||
expect(resolvePackedState(partial, { bodyKeys: ['name'], quantity: 8 })).toBe(partial);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* The packed count of a multi-piece item (#2296) and its checkbox, kept in step.
|
||||
*
|
||||
* `packed_quantity` only holds a partial count: zero is stored as null, and a count
|
||||
* that reaches the quantity is the checked box itself. That keeps one truth for
|
||||
* "done" and lets every older client keep reading `checked`.
|
||||
*/
|
||||
export interface PackedState {
|
||||
checked: number;
|
||||
packed_quantity: number | null;
|
||||
}
|
||||
|
||||
interface PackedInput {
|
||||
/** The keys the write actually named, as the update's presence protocol has them. */
|
||||
bodyKeys: string[];
|
||||
checked?: number;
|
||||
packed_quantity?: number | null;
|
||||
/** The quantity after the write. */
|
||||
quantity: number;
|
||||
}
|
||||
|
||||
export function resolvePackedState(current: PackedState, input: PackedInput): PackedState {
|
||||
const { bodyKeys, quantity } = input;
|
||||
if (bodyKeys.includes('packed_quantity')) {
|
||||
const count = Math.max(0, Math.min(quantity, Math.floor(Number(input.packed_quantity) || 0)));
|
||||
if (count >= quantity) return { checked: 1, packed_quantity: null };
|
||||
return { checked: 0, packed_quantity: count > 0 ? count : null };
|
||||
}
|
||||
// Ticking or unticking the box is a decision about the whole item.
|
||||
if (bodyKeys.includes('checked')) return { checked: input.checked ? 1 : 0, packed_quantity: null };
|
||||
// A lowered quantity the count already reaches finishes the item.
|
||||
if (current.packed_quantity != null && current.packed_quantity >= quantity)
|
||||
return { checked: 1, packed_quantity: null };
|
||||
return current;
|
||||
}
|
||||
@@ -29,6 +29,9 @@ export const packingItemSchema = z.object({
|
||||
weight_grams: z.number().nullable().optional(),
|
||||
bag_id: z.number().nullable().optional(),
|
||||
quantity: z.number().optional(),
|
||||
// How many of `quantity` are already in the bag (#2296). Null when the
|
||||
// counter is not in use: the item is then simply checked or not.
|
||||
packed_quantity: z.number().nullable().optional(),
|
||||
// Three-tier sharing (#858). is_private is the raw SQLite INTEGER (0/1):
|
||||
// 0 = Common (group pool, visible to all), 1 = restricted. owner_id is the
|
||||
// "bringer". A restricted item with no recipients is Personal; with recipients
|
||||
@@ -124,6 +127,9 @@ export const packingUpdateItemRequestSchema = z.object({
|
||||
weight_grams: z.number().nullable().optional(),
|
||||
bag_id: z.number().nullable().optional(),
|
||||
quantity: z.number().optional(),
|
||||
// Count packed pieces of a multi-piece item (#2296). Reaching the quantity
|
||||
// checks the item; null or 0 clears the count. Ticking `checked` resets it.
|
||||
packed_quantity: z.number().int().min(0).max(999).nullable().optional(),
|
||||
// Toggle the item's privacy (#858).
|
||||
is_private: z.boolean().optional(),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user