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:
@@ -196,3 +196,30 @@ export function sortItemsByName<T extends { name: string }>(items: T[], locale?:
|
||||
return collator.compare(a.name.trim(), b.name.trim())
|
||||
})
|
||||
}
|
||||
|
||||
/** The packed count an item shows (#2296): all of it once ticked, its partial count before that. */
|
||||
export function packedOf(item: { checked?: number | boolean; packed_quantity?: number | null; quantity?: number }): number {
|
||||
return item.checked ? (item.quantity || 1) : (item.packed_quantity ?? 0)
|
||||
}
|
||||
|
||||
type SharingItem = { category?: string | null; name: string; is_private?: number; owner_id?: number | null; recipients?: { user_id: number }[] }
|
||||
|
||||
/**
|
||||
* The tier a new item takes in the given category (#2241). In "my list" a category
|
||||
* whose own items are all shared with the very same people shares the next one with
|
||||
* them too, so a list kept for two does not need every new line shared by hand. Any
|
||||
* difference between the items, or one kept to myself, and the new item stays mine
|
||||
* alone: sharing is only ever carried over when the category is unanimous about it.
|
||||
*/
|
||||
export function newItemSharing(
|
||||
items: SharingItem[],
|
||||
category: string,
|
||||
view: 'common' | 'personal',
|
||||
userId: number | null | undefined,
|
||||
): { visibility: 'common' | 'personal' | 'shared'; recipient_ids?: number[] } {
|
||||
if (view !== 'personal') return { visibility: 'common' }
|
||||
const own = items.filter(i => i.category === category && i.name !== PACKING_PLACEHOLDER_NAME && !!i.is_private && i.owner_id === userId)
|
||||
const sets = own.map(i => (i.recipients || []).map(r => r.user_id).sort((a, b) => a - b).join(','))
|
||||
if (!own.length || !sets[0] || sets.some(set => set !== sets[0])) return { visibility: 'personal' }
|
||||
return { visibility: 'shared', recipient_ids: sets[0].split(',').map(Number) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user