feat(roadtrip): add daily scheduling and configurable day endings

This commit is contained in:
Maurice
2026-09-11 22:28:02 +02:00
parent 4f8605b529
commit 491cfccc56
124 changed files with 3512 additions and 354 deletions
@@ -3,11 +3,13 @@ import type { StoreApi } from 'zustand'
import type { TripStoreState } from '../tripStore'
import type { Assignment, AssignmentsMap } from '../../types'
import { getApiErrorMessage } from '../../types'
import { assignmentRepo } from '../../repo/assignmentRepo'
type SetState = StoreApi<TripStoreState>['setState']
type GetState = StoreApi<TripStoreState>['getState']
export interface AssignmentsSlice {
setAssignmentEndDay: (tripId: number | string, dayId: number, assignmentId: number, endDay: boolean) => 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>
reorderAssignments: (tripId: number | string, dayId: number | string, orderedIds: number[]) => Promise<void>
@@ -16,6 +18,23 @@ export interface AssignmentsSlice {
}
export const createAssignmentsSlice = (set: SetState, get: GetState): AssignmentsSlice => ({
setAssignmentEndDay: async (tripId, dayId, assignmentId, endDay) => {
const assignment = get().assignments[String(dayId)]?.find(a => a.id === assignmentId)
if (!assignment || assignmentId < 0) return
const apply = (value: boolean) => set(state => ({
assignments: Object.fromEntries(Object.entries(state.assignments).map(([key, items]) => [
key, items.map(a => a.id === assignmentId ? { ...a, end_day: value } : a),
])),
}))
apply(endDay)
try {
const saved = await assignmentRepo.setEndDay(tripId, assignment, endDay)
apply(saved.end_day === true)
} catch (err: unknown) {
apply(assignment.end_day === true)
throw err
}
},
assignPlaceToDay: async (tripId, dayId, placeId, position) => {
const state = get()
const place = state.places.find(p => p.id === Number.parseInt(String(placeId)))