mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-24 16:03:02 +00:00
bdf5767a5f
The rail lists its sections in the order a book is made: Pages, Content, Layouts, Elements and Travel, then Theme and Layers set apart below a rule. Stickers are a tab of Elements beside the icons instead of a rail section of their own, and Elements has six tabs (text, shapes, lines, frames with the grids, icons, stickers). The quotation mark moved to the text styles, the outline rectangle to the basic shapes and the plain rule to the lines. The rail and every tab row are tab lists the arrow keys walk through, and a long name wraps instead of being cut. The icon and sticker searches say in the field how many match, which the sticker library's own head used to. Every panel on both sides opens on the same head, and every labelled control uses one row that moves the control under its label when the two do not fit, so no label sits in a fixed column any more. Number fields, chips, sliders, tab labels, theme names and travel cards wrap the same way, a country beside a stop wraps under itself, and an upload cell holds its words to two lines with the whole label in its tooltip. The heads, shelves and groups are real headings, so a screen reader can walk the panels by them. The inspector shows every kind in one order: what the element is and says, its position and size, its look, its effects, then Arrange. Align and the stacking buttons are one Arrange group with a button that opens the page in Layers; its rows sit under their labels, each in two sets that move to a second line whole. Rarely used groups start folded and open on an element that already uses them (a turned element, a map held at a zoom, a summary set in another face), and every group mounts afresh for the next selection. A sticker's duplicate angle and opacity are gone in favour of the shared position group, which now has the turn buttons for every kind. With several elements selected it keeps their angle, opacity and turn, and the mirror when all of them are stickers, and leaves the frame's numbers to one element. A photo's fill page and fill spread sit under its crop. With nothing selected the inspector shows the page background, the book's theme with the way to the Theme panel, and the page numbers. Seventeen translation keys nothing has used since before the rebuild (the old inspector title, the empty spread note, the summary and country list names, the roads buttons and others) are gone from every language. The broad key template the old panels used had counted them as reached; the format names, the empty photo grid messages and the map source hints are now named where the key check can read them. Also fixed on the way: the travel stops list shared its class with the gradient stops and was laid out as sixteen pixel handles; the alignment buttons were named in raw English; the map's print resolution note joined its two halves with a dash.
158 lines
5.7 KiB
TypeScript
158 lines
5.7 KiB
TypeScript
import type { BookElement } from '@trek/shared';
|
|
import { bookCoordValue, formatBookCoords, formatBookDate } from '@trek/shared';
|
|
import { Camera } from 'lucide-react';
|
|
|
|
import { MOOD_CONFIG, WEATHER_CONFIG } from '../../../pages/journeyDetail/JourneyDetailPage.constants';
|
|
import { formatDate } from '../../../utils/formatters';
|
|
import type { JourneySource } from '../StudioSidebar';
|
|
import { markDrop, prosConsDrop, textDrop, type DropPlace } from './contentDrops';
|
|
|
|
type Entry = JourneySource['entries'][number];
|
|
|
|
/** One chip of an entry: what it says, and the element it places, built when it is pressed. */
|
|
interface EntryChip {
|
|
key: string;
|
|
label: string;
|
|
make: () => BookElement;
|
|
/** How many pieces it places, for the pros and cons. */
|
|
count?: number;
|
|
}
|
|
|
|
/**
|
|
* The pieces of an entry that can go on a page, in the order the card offers
|
|
* them: its words (title, story, place), its day and its point, set the way the
|
|
* rest of the book sets them (the long date, coordinates in degrees), its mood
|
|
* and weather, and its pros and cons. A piece the entry has not got is not
|
|
* offered. Each element is built only when its chip is pressed, so a card
|
|
* drawn twice mints no ids.
|
|
*/
|
|
function entryChips(entry: Entry, place: DropPlace, locale: string, t: (k: string) => string): EntryChip[] {
|
|
const { id, title, story, location, date, lat, lng, mood, weather, pros, cons } = entry;
|
|
// The short marks (a date, a point) land on a short line rather than across the whole column.
|
|
const markWidth = place.page.pageWidth * 0.36;
|
|
const bold = { size: 8, weight: 700 } as const;
|
|
const chips: EntryChip[] = [];
|
|
if (title)
|
|
chips.push({
|
|
key: 'title',
|
|
label: t('journey.studio.addTitle'),
|
|
make: () => textDrop(place, title, { size: 22, weight: 700 }, { entryId: id, source: 'entry.title' }),
|
|
});
|
|
if (story)
|
|
chips.push({
|
|
key: 'story',
|
|
label: t('journey.studio.addStory'),
|
|
make: () => textDrop(place, story, { size: 10, weight: 400 }, { entryId: id, source: 'entry.story' }),
|
|
});
|
|
if (location)
|
|
chips.push({
|
|
key: 'place',
|
|
label: t('journey.studio.addPlace'),
|
|
make: () => textDrop(place, location, bold, { entryId: id, source: 'entry.location' }),
|
|
});
|
|
if (date)
|
|
chips.push({
|
|
key: 'date',
|
|
label: t('journey.studio.dateMark'),
|
|
make: () =>
|
|
textDrop(
|
|
place,
|
|
formatBookDate(date, locale),
|
|
bold,
|
|
{ entryId: id, source: 'entry.date', value: date },
|
|
markWidth
|
|
),
|
|
});
|
|
if (lat != null && lng != null)
|
|
chips.push({
|
|
key: 'coords',
|
|
label: t('journey.studio.coordsMark'),
|
|
make: () =>
|
|
textDrop(
|
|
place,
|
|
formatBookCoords(lat, lng, 'dms'),
|
|
bold,
|
|
{ entryId: id, source: 'entry.location', format: 'dms', value: bookCoordValue(lat, lng) },
|
|
markWidth
|
|
),
|
|
});
|
|
const moodMark = mood ? MOOD_CONFIG[mood] : undefined;
|
|
if (mood && moodMark) {
|
|
const label = t(moodMark.label);
|
|
chips.push({ key: 'mood', label, make: () => markDrop(place, 'mood', mood, label) });
|
|
}
|
|
const weatherMark = weather ? WEATHER_CONFIG[weather] : undefined;
|
|
if (weather && weatherMark) {
|
|
const label = t(weatherMark.label);
|
|
chips.push({ key: 'weather', label, make: () => markDrop(place, 'weather', weather, label) });
|
|
}
|
|
if (pros.length > 0 || cons.length > 0)
|
|
chips.push({
|
|
key: 'proscons',
|
|
label: t('journey.studio.addProsCons'),
|
|
count: pros.length + cons.length,
|
|
make: () => prosConsDrop(place, { pros, cons }, { pro: t('journey.editor.pros'), con: t('journey.editor.cons') }),
|
|
});
|
|
return chips;
|
|
}
|
|
|
|
/**
|
|
* One entry of the journal in Content > Entries: its name, its day and place,
|
|
* and a chip for every piece of it that can go on a page.
|
|
*
|
|
* Each chip shows what it places rather than the field it comes from ("Sunny"
|
|
* tells you what you are about to place; "Weather" does not), and every piece
|
|
* arrives still bound to the entry. The last chip is not a drop: it opens the
|
|
* entry's photos, because the day is how anyone thinks of its pictures.
|
|
*/
|
|
export function StudioEntryCard({
|
|
entry,
|
|
place,
|
|
locale,
|
|
t,
|
|
onAdd,
|
|
onPhotos,
|
|
}: {
|
|
entry: Entry;
|
|
place: DropPlace;
|
|
locale: string;
|
|
t: (k: string) => string;
|
|
onAdd: (el: BookElement) => void;
|
|
/** Opens the photos tab on this entry's pictures. */
|
|
onPhotos: (entryId: number) => void;
|
|
}) {
|
|
const { id, title, location, date, photoIds } = entry;
|
|
return (
|
|
<div className="st-entry">
|
|
<div className="st-entry-head">{title || location || t('journey.studio.untitled')}</div>
|
|
{(date || location) && (
|
|
<div className="st-entry-meta">
|
|
{/* Two facts, two badges. Joined by a dot they read as one string. The date follows the app's
|
|
language, like every other date in TREK (utils/formatters.ts). */}
|
|
{date && <span className="st-badge">{formatDate(date, locale) ?? date}</span>}
|
|
{location && (
|
|
<span className="st-badge is-quiet" title={location}>
|
|
{location}
|
|
</span>
|
|
)}
|
|
</div>
|
|
)}
|
|
<div className="st-row st-entry-chips">
|
|
{entryChips(entry, place, locale, t).map((chip) => (
|
|
<button type="button" key={chip.key} className="st-chip" onClick={() => onAdd(chip.make())}>
|
|
{chip.label}
|
|
{chip.count != null && <span className="st-chip-count">{chip.count}</span>}
|
|
</button>
|
|
))}
|
|
{photoIds.length > 0 && (
|
|
<button type="button" className="st-chip" onClick={() => onPhotos(id)}>
|
|
<Camera size={12} aria-hidden />
|
|
{t('journey.studio.entryPhotos')}
|
|
<span className="st-chip-count">{photoIds.length}</span>
|
|
</button>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|