mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 19:40:34 +00:00
31859651d7
Every help screen checked against the v5 redesign. Tours is documented for the first time, as a screen of its own with twelve screens under it, and notifications get help of their own. All pictures are taken again on a realistic demo trip, with short loops where a still cannot show the motion. The English is plain and every language is written naturally rather than word for word. The switcher shows two levels at most, a screen's overview lists its sub-screens as cards above its guides, each wiki page is linked once, and the help sidebar is wider. Fixes found along the way: Save to Collection keeps a tour's route, a track dropped on the places column opens the Tours import, tour Share on desktop, the unsaved tour draft lives on the account, a route click no longer adds an end point, Trip places leaves the trip's tours out, Escape closes a stage's day menu, confirms before destructive deletes, DWD warnings sharing one id kept apart, a booking's date moves with it, and smaller fixes across notifications, bookings, the day plan, stays, Atlas, Collections, Vacay and the admin screens.
54 lines
2.0 KiB
TypeScript
54 lines
2.0 KiB
TypeScript
import { z } from 'zod';
|
|
|
|
/**
|
|
* The Tours planner's unsaved draft, kept on the account per user and trip so
|
|
* a draft started on one device opens on the next. The draft is the planner's
|
|
* own state (its fields change with the planner's versions), so the contract
|
|
* carries it as JSON text the server stores and hands back whole: the server
|
|
* checks that it is a JSON object within the size cap, and the planner checks
|
|
* its fields when it takes the draft back.
|
|
*/
|
|
|
|
/**
|
|
* The longest a draft may be, in characters of its JSON text. A draft holds
|
|
* the control points and their fixed legs, never the routed line, so even a
|
|
* ride along a long horse route section stays far below this; the JSON body
|
|
* that carries it escaped stays under the tour write ceiling.
|
|
*/
|
|
export const TOUR_DRAFT_MAX_CHARS = 512 * 1024;
|
|
|
|
function isJsonObject(text: string): boolean {
|
|
try {
|
|
const value: unknown = JSON.parse(text);
|
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/** A draft as JSON text: an object, within TOUR_DRAFT_MAX_CHARS. */
|
|
export const tourDraftPayloadSchema = z
|
|
.string()
|
|
.min(2)
|
|
.max(TOUR_DRAFT_MAX_CHARS)
|
|
.refine(isJsonObject, { message: 'The draft must be a JSON object' });
|
|
|
|
/** PUT /api/trips/:tripId/tour-draft: the draft that replaces the one kept before. */
|
|
export const tourDraftPutRequestSchema = z.object({
|
|
payload: tourDraftPayloadSchema,
|
|
});
|
|
export type TourDraftPutRequest = z.infer<typeof tourDraftPutRequestSchema>;
|
|
|
|
/** A kept draft and when it was last written. */
|
|
export const tourDraftSchema = z.object({
|
|
payload: z.string(),
|
|
updated_at: z.string(),
|
|
});
|
|
export type TourDraft = z.infer<typeof tourDraftSchema>;
|
|
|
|
/** GET and PUT /api/trips/:tripId/tour-draft: the user's draft in the trip, null while there is none. */
|
|
export const tourDraftResponseSchema = z.object({
|
|
draft: tourDraftSchema.nullable(),
|
|
});
|
|
export type TourDraftResponse = z.infer<typeof tourDraftResponseSchema>;
|