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:
Maurice
2026-09-30 23:00:12 +02:00
parent 91dfab3f4b
commit 8fd46c4c18
691 changed files with 9491 additions and 927 deletions
+2
View File
@@ -64,6 +64,8 @@ export interface JourneyEntry {
stats_excluded?: boolean
/** A trip-derived suggestion the traveller waved away. Never sent by the server; the read paths drop it. */
dismissed?: boolean
/** A draft (#696): contributors see it, the journey's public share page does not. */
is_draft?: boolean
photos: JourneyPhoto[]
created_at: number
updated_at: number
@@ -11,9 +11,11 @@ type GetState = StoreApi<TripStoreState>['getState']
export interface AssignmentsSlice {
setAssignmentEndDay: (tripId: number | string, dayId: number, assignmentId: number, endDay: boolean) => Promise<void>
setAssignmentRouteExcluded: (tripId: number | string, dayId: number, assignmentId: number, excluded: boolean) => Promise<void>
setAssignmentTimes: (tripId: number | string, dayId: number, assignmentId: number, times: AssignmentTimes) => Promise<void>
assignPlaceToDay: (tripId: number | string, dayId: number | string, placeId: number | string, position?: number | null) => Promise<Assignment | undefined>
removeAssignment: (tripId: number | string, dayId: number | string, assignmentId: number) => Promise<void>
clearDayAssignments: (tripId: number | string, dayId: number) => Promise<void>
reorderAssignments: (tripId: number | string, dayId: number | string, orderedIds: number[]) => Promise<void>
moveAssignment: (tripId: number | string, assignmentId: number, fromDayId: number | string, toDayId: number | string, toOrderIndex?: number | null) => Promise<void>
setAssignments: (assignments: AssignmentsMap) => void
@@ -37,6 +39,21 @@ export const createAssignmentsSlice = (set: SetState, get: GetState): Assignment
throw err
}
},
setAssignmentRouteExcluded: async (tripId, dayId, assignmentId, excluded) => {
const assignment = get().assignments[String(dayId)]?.find(a => a.id === assignmentId)
if (!assignment || assignmentId < 0) return
const apply = (value: boolean) => set(state => ({
assignments: { ...state.assignments, [String(dayId)]: (state.assignments[String(dayId)] || []).map(a => a.id === assignmentId ? { ...a, route_excluded: value } : a) },
}))
apply(excluded)
try {
const saved = await assignmentRepo.setRouteExcluded(tripId, assignment, excluded)
apply(saved.route_excluded === true)
} catch (err: unknown) {
apply(assignment.route_excluded === true)
throw err
}
},
setAssignmentTimes: async (tripId, dayId, assignmentId, times) => {
const assignment = get().assignments[String(dayId)]?.find(a => a.id === assignmentId)
if (!assignment || assignmentId < 0) return
@@ -157,6 +174,17 @@ export const createAssignmentsSlice = (set: SetState, get: GetState): Assignment
}
},
clearDayAssignments: async (tripId, dayId) => {
const prevAssignments = get().assignments
set(state => ({ assignments: { ...state.assignments, [String(dayId)]: [] } }))
try {
await assignmentRepo.clearDay(tripId, dayId)
} catch (err: unknown) {
set({ assignments: prevAssignments })
throw new Error(getApiErrorMessage(err, 'Error removing assignment'))
}
},
reorderAssignments: async (tripId, dayId, orderedIds) => {
const prevAssignments = get().assignments
const dayItems = get().assignments[String(dayId)] || []
@@ -1,5 +1,6 @@
// FE-STORE-PACKING-001 to FE-STORE-PACKING-002 (reorder, #969)
// FE-STORE-PACKING-003 to FE-STORE-PACKING-015 (three-tier sharing #858, mutation and error paths)
// FE-STORE-PACKING-016 to FE-STORE-PACKING-017 (packed count, #2296)
import { http, HttpResponse } from 'msw';
import { server } from '../../../tests/helpers/msw/server';
import { resetAllStores, seedStore } from '../../../tests/helpers/store';
@@ -282,4 +283,43 @@ describe('packingSlice', () => {
expect(useTripStore.getState().packingItems[0].checked).toBe(0);
expect(addToast).toHaveBeenCalledWith('Write failed', 'error', undefined);
});
it('FE-STORE-PACKING-016: setPackedCount counts ahead of the server and ticks the item once full', async () => {
const item = buildPackingItem({ id: 1, trip_id: 1, checked: 0, quantity: 3 });
seedStore(useTripStore, { packingItems: [item] });
const bodies: unknown[] = [];
server.use(
http.put('/api/trips/1/packing/1', async ({ request }) => {
bodies.push(await request.json());
return HttpResponse.json({ item: { ...item, checked: 1, packed_quantity: null } });
})
);
const pending = useTripStore.getState().setPackedCount(1, 1, 2);
expect(useTripStore.getState().packingItems[0]).toMatchObject({ packed_quantity: 2, checked: 0 });
await pending;
await useTripStore.getState().setPackedCount(1, 1, 3);
expect(useTripStore.getState().packingItems[0]).toMatchObject({ packed_quantity: null, checked: 1 });
expect(bodies).toEqual([{ packed_quantity: 2 }, { packed_quantity: 3 }]);
});
it('FE-STORE-PACKING-017: setPackedCount rolls back and notifies on failure; ticking clears a count', async () => {
const item = buildPackingItem({ id: 1, trip_id: 1, checked: 0, quantity: 5, packed_quantity: 1 });
seedStore(useTripStore, { packingItems: [item] });
server.use(
http.put('/api/trips/1/packing/1', () =>
HttpResponse.json({ error: 'Write failed' }, { status: 500 })
)
);
await useTripStore.getState().setPackedCount(1, 1, 4);
expect(useTripStore.getState().packingItems[0]).toMatchObject({ packed_quantity: 1, checked: 0 });
expect(addToast).toHaveBeenCalledWith('Write failed', 'error', undefined);
// A missing item is a no-op, not a request.
await useTripStore.getState().setPackedCount(1, 99, 1);
server.use(http.put('/api/trips/1/packing/1', () => HttpResponse.json({ item: { ...item, checked: 1, packed_quantity: null } })));
await useTripStore.getState().togglePackingItem(1, 1, true);
expect(useTripStore.getState().packingItems[0]).toMatchObject({ packed_quantity: null, checked: 1 });
});
});
+24 -2
View File
@@ -5,6 +5,7 @@ import type { TripStoreState } from '../tripStore'
import type { PackingItem } from '../../types'
import { getApiErrorMessage } from '../../types'
import { notify } from '../notify'
import { resolvePackedState } from '@trek/shared'
type SetState = StoreApi<TripStoreState>['setState']
type GetState = StoreApi<TripStoreState>['getState']
@@ -14,6 +15,8 @@ export interface PackingSlice {
updatePackingItem: (tripId: number | string, id: number, data: Partial<PackingItem>) => Promise<PackingItem>
deletePackingItem: (tripId: number | string, id: number) => Promise<void>
togglePackingItem: (tripId: number | string, id: number, checked: boolean) => Promise<void>
/** Count how many pieces of a multi-piece item are packed (#2296). */
setPackedCount: (tripId: number | string, id: number, count: number) => Promise<void>
reorderPackingItems: (tripId: number | string, orderedIds: number[]) => Promise<void>
// Three-tier sharing (#858)
setPackingItemSharing: (tripId: number | string, id: number, visibility: 'common' | 'personal' | 'shared', recipientIds: number[]) => Promise<void>
@@ -57,9 +60,11 @@ export const createPackingSlice = (set: SetState, get: GetState): PackingSlice =
},
togglePackingItem: async (tripId, id, checked) => {
const prev = get().packingItems.find(item => item.id === id)
// Ticking decides for the whole item, so a partial count goes with it (#2296).
set(state => ({
packingItems: state.packingItems.map(item =>
item.id === id ? { ...item, checked: checked ? 1 : 0 } : item
item.id === id ? { ...item, checked: checked ? 1 : 0, packed_quantity: null } : item
)
}))
try {
@@ -69,13 +74,30 @@ export const createPackingSlice = (set: SetState, get: GetState): PackingSlice =
// silently would just flip the checkbox with no explanation. Surface it.
set(state => ({
packingItems: state.packingItems.map(item =>
item.id === id ? { ...item, checked: checked ? 0 : 1 } : item
item.id === id ? { ...item, checked: checked ? 0 : 1, packed_quantity: prev?.packed_quantity ?? null } : item
)
}))
notify(getApiErrorMessage(err, 'Error updating item'), 'error')
}
},
setPackedCount: async (tripId, id, count) => {
const prev = get().packingItems.find(item => item.id === id)
if (!prev) return
// The server's own rule, run ahead of it so the counter answers at once.
const next = resolvePackedState(
{ checked: prev.checked ? 1 : 0, packed_quantity: prev.packed_quantity ?? null },
{ bodyKeys: ['packed_quantity'], packed_quantity: count, quantity: prev.quantity || 1 },
)
set(state => ({ packingItems: state.packingItems.map(item => item.id === id ? { ...item, ...next } : item) }))
try {
await packingRepo.update(tripId, id, { packed_quantity: count })
} catch (err: unknown) {
set(state => ({ packingItems: state.packingItems.map(item => item.id === id ? prev : item) }))
notify(getApiErrorMessage(err, 'Error updating item'), 'error')
}
},
reorderPackingItems: async (tripId, orderedIds) => {
const prev = get().packingItems
// Optimistic reorder: rebuild the array in the requested order, reindexing
+13
View File
@@ -13,6 +13,7 @@ export interface PlacesSlice {
addPlace: (tripId: number | string, placeData: Partial<Place> & { name: string }) => Promise<Place>
updatePlace: (tripId: number | string, placeId: number, placeData: Partial<Place>) => Promise<Place>
uploadPlaceImage: (tripId: number | string, placeId: number, file: File) => Promise<Place>
setPlaceImageFromFile: (tripId: number | string, placeId: number, fileId: number) => Promise<Place>
ratePlace: (tripId: number | string, placeId: number, rating: number | null) => Promise<Place>
deletePlace: (tripId: number | string, placeId: number) => Promise<void>
deletePlacesMany: (tripId: number | string, placeIds: number[]) => Promise<void>
@@ -108,6 +109,18 @@ export const createPlacesSlice = (set: SetState, get: GetState): PlacesSlice =>
}
},
setPlaceImageFromFile: async (tripId, placeId, fileId) => {
// Online-only like the upload: the server copies the file, so there is nothing to
// do offline that the next sync could replay.
try {
const data = await placesApi.imageFromFile(tripId, placeId, fileId)
applyUpdatedPlace(set, placeId, data.place)
return data.place
} catch (err: unknown) {
throw new Error(getApiErrorMessage(err, 'Error uploading image'))
}
},
ratePlace: async (tripId, placeId, rating) => {
// Casts (or clears, rating null) the current user's own star vote (#1435)
// and applies the returned place with the fresh average.
+56 -1
View File
@@ -1,5 +1,8 @@
import { create } from 'zustand'
import type { BookDocument, BookElement, BookFrame, BookSpread } from '@trek/shared'
import type { BookDocument, BookElement, BookFrame, BookLayout, BookSpread } from '@trek/shared'
import { MAX_BOOK_LAYOUTS, MAX_SPREAD_ELEMENTS } from '@trek/shared'
import { pastedElements, type StudioClipboard } from '../components/Studio/studioClipboard'
import { applySavedLayout, layoutFromSpread } from '../components/Studio/savedLayouts'
/**
* The book being edited.
@@ -25,6 +28,8 @@ interface StudioState {
future: BookDocument[]
/** The document as it was when the current gesture started. */
gestureBase: BookDocument | null
/** Elements copied for pasting onto any page of the book (#2316). Kept across page switches. */
clipboard: StudioClipboard | null
load: (doc: BookDocument) => void
setActiveSpread: (i: number) => void
@@ -51,6 +56,16 @@ interface StudioState {
removeElements: (spreadIndex: number, ids: string[]) => void
duplicate: (spreadIndex: number, ids: string[]) => void
raise: (spreadIndex: number, id: string, to: 'front' | 'back' | 'up' | 'down') => void
/** Copy elements of a spread to the clipboard (#2316). */
copy: (spreadIndex: number, ids: string[]) => void
/** Put the clipboard onto a spread, as one undo step, and select what arrived. */
paste: (spreadIndex: number) => void
/** Keep a spread's arrangement as one of the book's layouts (#2316). Returns false when the book is full. */
saveLayout: (spreadIndex: number, name: string) => boolean
removeLayout: (id: string) => void
/** Lay a spread out on a saved layout, keeping its pictures and words. */
applyLayout: (spreadIndex: number, id: string) => void
/** Insert an empty spread after `index`, and select it. */
addSpread: (index: number) => void
@@ -119,6 +134,7 @@ export const useStudioStore = create<StudioState>((set, get) => ({
past: [],
future: [],
gestureBase: null,
clipboard: null,
load: doc => set({ doc, selection: [], activeSpread: 0, past: [], future: [], gestureBase: null }),
setActiveSpread: i => set({ activeSpread: i, selection: [] }),
@@ -220,6 +236,45 @@ export const useStudioStore = create<StudioState>((set, get) => ({
return { ...sp, elements: els }
})),
copy: (spreadIndex, ids) => {
const sp = get().doc?.spreads[spreadIndex]
if (!sp) return
const elements = sp.elements.filter(e => ids.includes(e.id))
if (elements.length) set({ clipboard: { fromSpreadId: sp.id, elements } })
},
paste: spreadIndex => {
const { clipboard, doc } = get()
const target = doc?.spreads[spreadIndex]
if (!clipboard || !doc || !target) return
// The spread's own cap: a paste that would push it past what the contract
// accepts takes what fits rather than making the book unsaveable.
const room = Math.max(0, MAX_SPREAD_ELEMENTS - target.elements.length)
const copies = pastedElements(clipboard, target, doc.page).slice(0, room)
if (!copies.length) return
get().commit(d => replaceSpread(d, spreadIndex, sp => ({ ...sp, elements: [...sp.elements, ...copies] })))
set({ selection: copies.map(e => e.id) })
},
saveLayout: (spreadIndex, name) => {
const doc = get().doc
const sp = doc?.spreads[spreadIndex]
if (!doc || !sp || !sp.elements.length) return false
if ((doc.layouts ?? []).length >= MAX_BOOK_LAYOUTS) return false
const layout: BookLayout = layoutFromSpread(sp, doc.page, name)
get().commit(d => ({ ...d, layouts: [...(d.layouts ?? []), layout] }))
return true
},
removeLayout: id => get().commit(d => ({ ...d, layouts: (d.layouts ?? []).filter(l => l.id !== id) })),
applyLayout: (spreadIndex, id) => {
const layout = get().doc?.layouts?.find(l => l.id === id)
if (!layout) return
get().commit(d => replaceSpread(d, spreadIndex, sp => applySavedLayout(sp, layout, d.page)))
set({ selection: [] })
},
/*
* ── Spread management ────────────────────────────────────────────────
*
+10 -9
View File
@@ -15,6 +15,7 @@ import type {
VacayUpdateStatsRequest, VacayShareRequest, VacayShareUpdateRequest,
VacayYearSettingsRequest,
} from '@trek/shared'
import { toggledCompanyHolidays, type CompanyHoliday } from '../components/Vacay/companyHolidays'
const ax = apiClient
@@ -43,7 +44,7 @@ interface VacayYearsResponse {
interface VacayEntriesResponse {
entries: VacayEntry[]
companyHolidays: { date: string; note?: string }[]
companyHolidays: CompanyHoliday[]
}
interface VacayStatsResponse {
@@ -78,7 +79,7 @@ interface VacayApi {
removeYear: (year: number) => Promise<VacayYearsResponse>
getEntries: (year: number) => Promise<VacayEntriesResponse>
toggleEntry: (date: string, targetUserId?: number, fraction?: 0.5 | 1, kind?: 'vacation' | 'comp') => Promise<unknown>
toggleCompanyHoliday: (date: string) => Promise<unknown>
toggleCompanyHoliday: (date: string, fraction?: number) => Promise<unknown>
getStats: (year: number) => Promise<VacayStatsResponse>
updateStats: (year: number, days: number, targetUserId?: number) => Promise<unknown>
getHolidays: (year: number, country: string) => Promise<VacayHolidayRaw[]>
@@ -109,7 +110,7 @@ const api: VacayApi = {
removeYear: (year) => ax.delete(`/addons/vacay/years/${year}`).then((r: AxiosResponse) => r.data),
getEntries: (year) => ax.get(`/addons/vacay/entries/${year}`).then((r: AxiosResponse) => r.data),
toggleEntry: (date, targetUserId, fraction, kind) => ax.post('/addons/vacay/entries/toggle', { date, target_user_id: targetUserId, fraction, kind } satisfies VacayToggleEntryRequest).then((r: AxiosResponse) => r.data),
toggleCompanyHoliday: (date) => ax.post('/addons/vacay/entries/company-holiday', { date } satisfies VacayCompanyHolidayRequest).then((r: AxiosResponse) => r.data),
toggleCompanyHoliday: (date, fraction) => ax.post('/addons/vacay/entries/company-holiday', { date, fraction: fraction === 0.5 ? 0.5 : 1 } satisfies VacayCompanyHolidayRequest).then((r: AxiosResponse) => r.data),
getStats: (year) => ax.get(`/addons/vacay/stats/${year}`).then((r: AxiosResponse) => r.data),
updateStats: (year, days, targetUserId) => ax.put(`/addons/vacay/stats/${year}`, { vacation_days: days, target_user_id: targetUserId } satisfies VacayUpdateStatsRequest).then((r: AxiosResponse) => r.data),
getHolidays: (year, country) => ax.get(`/addons/vacay/holidays/${year}/${country}`).then((r: AxiosResponse) => r.data),
@@ -184,7 +185,7 @@ interface VacayState {
isFused: boolean
years: number[]
entries: VacayEntry[]
companyHolidays: { date: string; note?: string }[]
companyHolidays: CompanyHoliday[]
stats: VacayStat[]
selectedYear: number
selectedUserId: number | null
@@ -212,7 +213,8 @@ interface VacayState {
removeYear: (year: number) => Promise<void>
loadEntries: (year?: number) => Promise<void>
toggleEntry: (date: string, targetUserId?: number, fraction?: 0.5 | 1, kind?: 'vacation' | 'comp') => Promise<void>
toggleCompanyHoliday: (date: string) => Promise<void>
/** Whole (1) or half (0.5) company holiday (#2439); the same size again clears it. */
toggleCompanyHoliday: (date: string, fraction?: number) => Promise<void>
loadStats: (year?: number) => Promise<void>
updateVacationDays: (year: number, days: number, targetUserId?: number) => Promise<void>
loadHolidays: (year?: number) => Promise<void>
@@ -367,16 +369,15 @@ export const useVacayStore = create<VacayState>((set, get) => ({
}
},
toggleCompanyHoliday: async (date: string) => {
toggleCompanyHoliday: async (date: string, fraction = 1) => {
// Optimistic like toggleEntry; a company holiday also overrides personal
// entries on that day, so refetch entries afterwards to reconcile.
const prevEntries = get().entries
const prevCompany = get().companyHolidays
const prevStats = get().stats
const has = prevCompany.some(h => h.date === date)
set({ companyHolidays: has ? prevCompany.filter(h => h.date !== date) : [...prevCompany, { date }] })
set({ companyHolidays: toggledCompanyHolidays(prevCompany, date, fraction) })
try {
await api.toggleCompanyHoliday(date)
await api.toggleCompanyHoliday(date, fraction)
await get().loadEntries()
await get().loadStats()
} catch (e) {