mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 19:40:34 +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,122 @@
|
||||
import { CalendarDays, Info, StickyNote } from 'lucide-react';
|
||||
import { useRef, type ReactNode } from 'react';
|
||||
|
||||
import { fs } from '../shared/DialogShell';
|
||||
import NoteFormatToolbar from '../shared/NoteFormatToolbar';
|
||||
import { PANEL, Segmented } from '../shared/dialogParts';
|
||||
import { usePlaceTextTabs, type PlaceTextField } from './usePlaceTextTabs';
|
||||
|
||||
type Translate = (key: string, params?: Record<string, string | number>) => string;
|
||||
|
||||
/** The desktop draws each tab with an icon; the phone keeps to the words. */
|
||||
const ICONS: Record<PlaceTextField, ReactNode> = {
|
||||
description: <Info size={13} strokeWidth={2} />,
|
||||
notes: <StickyNote size={13} strokeWidth={2} />,
|
||||
assignment_notes: <CalendarDays size={13} strokeWidth={2} />,
|
||||
};
|
||||
|
||||
const DOT = 'h-1.5 w-1.5 flex-none rounded-full bg-current opacity-60';
|
||||
/** The field's frame, holding the text and, under it, the formatting bar, like a message composer. */
|
||||
const FIELD_BOX =
|
||||
'overflow-hidden rounded-[10px] border border-edge bg-surface-input focus-within:ring-2 focus-within:ring-[color:var(--text-primary)]';
|
||||
const BARE_TEXTAREA =
|
||||
'block w-full min-w-0 resize-y border-0 bg-transparent px-3 py-2 text-[length:calc(13px*var(--fs-scale-body,1))] leading-normal text-content outline-none placeholder:text-content-faint';
|
||||
const FIELD_BAR = 'flex items-center justify-end border-t border-edge-faint px-1.5 py-0.5';
|
||||
|
||||
/**
|
||||
* The place's three texts in one card: what the place is, notes on it, and the
|
||||
* note for this day's visit. A switch on top picks the one to write; the others
|
||||
* stay mounted and only hidden, so each keeps its caret and undo history, and a
|
||||
* dot marks a tab that already holds text. The day tab is there only when the
|
||||
* form edits one day-assignment.
|
||||
*/
|
||||
export function PlaceFormTexts({
|
||||
fieldId,
|
||||
description,
|
||||
notes,
|
||||
dayNotes,
|
||||
dayNumber = null,
|
||||
onChange,
|
||||
t,
|
||||
}: {
|
||||
fieldId: string;
|
||||
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;
|
||||
onChange: (field: PlaceTextField, value: string) => void;
|
||||
t: Translate;
|
||||
}) {
|
||||
const { tabs, shown, setActive } = usePlaceTextTabs({ description, notes, dayNotes, dayNumber, t });
|
||||
const refs = {
|
||||
description: useRef<HTMLTextAreaElement | null>(null),
|
||||
notes: useRef<HTMLTextAreaElement | null>(null),
|
||||
assignment_notes: useRef<HTMLTextAreaElement | null>(null),
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={PANEL}>
|
||||
<Segmented
|
||||
fill
|
||||
value={shown.field}
|
||||
onChange={setActive}
|
||||
label={t('places.notesKind')}
|
||||
options={tabs.map((tab) => ({
|
||||
value: tab.field,
|
||||
label: tab.value.trim() ? (
|
||||
<>
|
||||
{tab.label}
|
||||
<span aria-hidden="true" className={DOT} />
|
||||
</>
|
||||
) : (
|
||||
tab.label
|
||||
),
|
||||
icon: (
|
||||
<span aria-hidden="true" className="flex">
|
||||
{ICONS[tab.field]}
|
||||
</span>
|
||||
),
|
||||
}))}
|
||||
/>
|
||||
{tabs.map((tab) => (
|
||||
<p
|
||||
key={tab.field}
|
||||
id={`${fieldId}-${tab.field}-hint`}
|
||||
hidden={tab.field !== shown.field}
|
||||
className="m-0 -mb-1 leading-snug text-content-muted"
|
||||
style={fs(11)}
|
||||
>
|
||||
{tab.hint}
|
||||
</p>
|
||||
))}
|
||||
{/* The box hides, not the field: the field's own `block` class would win over `hidden`. */}
|
||||
{tabs.map((tab) => (
|
||||
<div key={tab.field} hidden={tab.field !== shown.field} className={FIELD_BOX}>
|
||||
<textarea
|
||||
id={`${fieldId}-${tab.field}`}
|
||||
ref={refs[tab.field]}
|
||||
aria-label={tab.aria}
|
||||
aria-describedby={`${fieldId}-${tab.field}-hint`}
|
||||
value={tab.value}
|
||||
onChange={(e) => onChange(tab.field, e.target.value)}
|
||||
rows={3}
|
||||
maxLength={tab.maxLength}
|
||||
className={BARE_TEXTAREA}
|
||||
/>
|
||||
{tab.markdown && (
|
||||
<div className={FIELD_BAR}>
|
||||
<NoteFormatToolbar
|
||||
textareaRef={refs[tab.field]}
|
||||
onChange={(v) => onChange(tab.field, v)}
|
||||
compact
|
||||
customTooltips
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user