mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 01:28:55 +00:00
feat(places): colour tags, tabs for the texts and opening hours on the phone
Tags on the place form are pills in their own colour, with a palette under the dot that recolours a tag for the whole trip (PUT /trips/:id/tags/:id was there already, the client now reaches it through repo and store) and a custom colour field of its own instead of the system picker. A new tag is made in a colour picked the same way. Description, notes and the note for one day's visit sit in one card under a switch, each with a line on where the text shows up; the day tab is named after its day and is only there with one visit in context. Nothing about the three fields changes underneath. Opening hours get a switch for open around the clock next to closed. Google writes a place open all week as one period on Sunday that never closes; it read as Sunday open and every other day closed, and now opens every day. The phone form follows the desktop: category as one field with a list, tags in one field, the texts switch, and phone, e-mail and opening hours, which it did not have. The hours and the text tabs are shared hooks (usePlaceHours, usePlaceTextTabs). Files and costs on the phone sheets are drawn as fields like the rest, and the paste hint, a keyboard shortcut a phone has no use for, is gone with its key.
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
import { useState } from 'react';
|
||||
|
||||
type Translate = (key: string, params?: Record<string, string | number>) => string;
|
||||
|
||||
export type PlaceTextField = 'description' | 'notes' | 'assignment_notes';
|
||||
|
||||
export interface PlaceTextTab {
|
||||
field: PlaceTextField;
|
||||
/** The tab's own short name. */
|
||||
label: string;
|
||||
/** The field's name for a screen reader, the one it always had. */
|
||||
aria: string;
|
||||
/** Where the text shows up, under the tabs. */
|
||||
hint: string;
|
||||
value: string;
|
||||
/** Rendered as Markdown where it is shown, so the desktop offers the formatting bar. */
|
||||
markdown: boolean;
|
||||
maxLength?: number;
|
||||
}
|
||||
|
||||
interface PlaceTextTabsOptions {
|
||||
description: string;
|
||||
notes: string;
|
||||
/** null when no single day-assignment is in context. */
|
||||
dayNotes: string | null;
|
||||
/** The day that visit is on, to name the tab after it ("Only day 3"). */
|
||||
dayNumber?: number | null;
|
||||
t: Translate;
|
||||
}
|
||||
|
||||
/**
|
||||
* The place form's three texts as tabs: what the place is, notes on it, and the
|
||||
* note for one day's visit, which is only there when the form edits one visit.
|
||||
* The one logic path behind the desktop card and the phone sheet; each draws its
|
||||
* own tabs and field over it.
|
||||
*/
|
||||
export function usePlaceTextTabs({ description, notes, dayNotes, dayNumber = null, t }: PlaceTextTabsOptions) {
|
||||
const [active, setActive] = useState<PlaceTextField>('description');
|
||||
const tabs: PlaceTextTab[] = [
|
||||
{
|
||||
field: 'description',
|
||||
label: t('places.notesTabAbout'),
|
||||
aria: t('places.formDescription'),
|
||||
hint: t('places.notesHintDescription'),
|
||||
value: description,
|
||||
markdown: true,
|
||||
},
|
||||
{
|
||||
field: 'notes',
|
||||
label: t('places.formNotes'),
|
||||
aria: t('places.formNotes'),
|
||||
hint: t('places.notesHintNotes'),
|
||||
value: notes,
|
||||
markdown: true,
|
||||
maxLength: 2000,
|
||||
},
|
||||
];
|
||||
if (dayNotes !== null) {
|
||||
tabs.push({
|
||||
field: 'assignment_notes',
|
||||
label: dayNumber ? t('places.notesTabDayN', { day: dayNumber }) : t('places.notesTabDay'),
|
||||
aria: t('places.assignmentNotes'),
|
||||
hint: t('places.notesHintDay'),
|
||||
value: dayNotes,
|
||||
markdown: false,
|
||||
});
|
||||
}
|
||||
// The day tab can go away under an open form (the visit is removed elsewhere).
|
||||
const shown = tabs.find((tab) => tab.field === active) ?? tabs[0];
|
||||
return { tabs, shown, setActive };
|
||||
}
|
||||
Reference in New Issue
Block a user