mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 17:41:51 +00:00
15aefa449e
Everything here came out of putting the first commit in front of somebody and watching them use it. **The marker card is one card now, and it carries the entry's photos.** Leaflet showed a one-line label and the GL map a two-line card, so the same marker said different things depending on a renderer setting nobody connects to journeys. Both now build from one module: a strip of up to three thumbnails bleeding to the card's edges, the name, and the place and date as chips. On the GL map the thumbnails open the entry's photos; the rest of the card still never takes the pointer, so the map drags from anywhere on it. **A pin that would not sit still.** Dragging the map left the marker trailing behind and snapping back at the end. The app's press-feedback rule puts a 180ms transition on `[role="button"]`, MapLibre and Mapbox give their marker element exactly that role, and both rewrite its `transform` on every frame of a movement. Markers are excluded now — every map in TREK, not just this one. **The phone card, after four rounds of looking at it.** The day is the card's own edge rather than a bar across its foot, and the ring is inset because the carousel clips. A card without a photo is opaque: it was a wash of the day's colour over the map. The country is a real flag rather than two letters — Windows has no flag glyphs, so the emoji drew "DE" where a flag was meant, and the image falls back to the emoji when it cannot be fetched. Mood, weather and the date share the top edge; the flag sits opposite them. **The day bar answers to a finger.** Press the date and slide sideways to run through the days. The bar is still a row of buttons underneath, because that is the only version of it a keyboard can reach, and each one is 20px tall now rather than 3. Also here: - Videos upload to an entry (issue #2341). The gallery has taken them since #823 and an entry could not: everything went through the images-only filter and came back 400, reported as "1 of 1 photos failed". Same two-part upload, same absence of transcoding, and the editor now previews a clip in a `<video>` instead of a broken-image glyph. - The search box takes the gap the toolbar already had instead of clipping its own placeholder. - Entry cards line up with the day header again: the reorder arrows moved out of a column of their own into the feed's padding and appear on hover, and the day-coloured ring on the active card is a layer over it — an outline tight enough to sit on the card's edge was painting behind it. - Map attribution is collapsed to its ⓘ. It cannot go away — the OSM licence asks for it — but it does not have to lie under the carousel. - The suggestion dismiss and the day-header plus use TREK's own tooltip rather than the browser's.
95 lines
3.9 KiB
TypeScript
95 lines
3.9 KiB
TypeScript
import { formatLocationName } from '../../utils/formatters'
|
|
import { DAY_COLORS } from './dayColors'
|
|
import type { JourneyEntry } from '../../store/journeyStore'
|
|
|
|
/**
|
|
* What a timeline card needs to know about an entry, worked out once.
|
|
*
|
|
* The phone shell and the tablet/public timeline draw the same card in two
|
|
* different token sets, so the markup lives in `JourneyEntryCover` and the
|
|
* questions it asks live here. Anything a card has to decide — which photo,
|
|
* what to call an entry with no title, which flag — is decided in this file so
|
|
* the two surfaces cannot answer it differently.
|
|
*/
|
|
|
|
/** A photo as either shell hands it over: the journey's own carry `photo_id`, shared ones only `id`. */
|
|
export interface CardPhoto {
|
|
photo_id?: number
|
|
id?: number
|
|
}
|
|
|
|
export function cardPhotoId(photo: CardPhoto | undefined): number | undefined {
|
|
return photo?.photo_id ?? photo?.id
|
|
}
|
|
|
|
/**
|
|
* The country an entry happened in, as the two letters to stamp on its card.
|
|
*
|
|
* Letters rather than the flag emoji: the two regional-indicator code points
|
|
* that make a flag are only drawn as one on Apple platforms and Android. Windows
|
|
* has never shipped the glyphs, so a card there showed a bare "DE" where a flag
|
|
* was clearly meant — which reads as something broken rather than as a country.
|
|
* The code reads the same everywhere, and in a chip it looks deliberate.
|
|
*/
|
|
export function countryBadge(code: string | null | undefined): string {
|
|
if (!code || !/^[A-Za-z]{2}$/.test(code)) return ''
|
|
return code.toUpperCase()
|
|
}
|
|
|
|
/** Short date for the card corner: "12 Sep", in the reader's locale and order. */
|
|
export function cardDateLabel(entryDate: string, locale: string): string {
|
|
return new Date(entryDate + 'T00:00:00').toLocaleDateString(locale, { day: 'numeric', month: 'short' })
|
|
}
|
|
|
|
/**
|
|
* The name to put on a card.
|
|
*
|
|
* An untitled entry is common — quick capture used to have no title field at all
|
|
* — so the fallback matters as much as the title. A suggestion says what it is,
|
|
* because a card that says "Untitled" over a photo of somewhere you have not been
|
|
* yet is a lie; anything else falls back to its place before it falls back to a
|
|
* placeholder, since where you were is at least true.
|
|
*/
|
|
export function cardTitle(
|
|
entry: Pick<JourneyEntry, 'title' | 'type' | 'location_name'>,
|
|
t: (key: string) => string,
|
|
): string {
|
|
if (entry.title?.trim()) return entry.title
|
|
if (entry.type === 'skeleton') return t('journey.entry.suggestion')
|
|
const place = formatLocationName(entry.location_name)
|
|
if (place) return place
|
|
return entry.type === 'checkin' ? t('journey.detail.journeyTab') : t('journey.editor.titlePlaceholder')
|
|
}
|
|
|
|
/** The place line under the title, left out when the title is already the place. */
|
|
export function cardPlace(
|
|
entry: Pick<JourneyEntry, 'title' | 'location_name'>,
|
|
): string {
|
|
const place = formatLocationName(entry.location_name)
|
|
if (!place) return ''
|
|
return entry.title?.trim() ? place : ''
|
|
}
|
|
|
|
/** One day of a journey, in the order it happened, with the colour everything else uses for it. */
|
|
export interface JourneyDay {
|
|
date: string
|
|
color: string
|
|
}
|
|
|
|
/**
|
|
* The days a set of entries spans, and which colour each of them wears.
|
|
*
|
|
* The map markers, the card edges and the day bar all have to agree on "day
|
|
* three is teal", and they used to work it out separately from the same list —
|
|
* which held only as long as all three filtered that list identically.
|
|
*/
|
|
export function journeyDays(entries: { entry_date: string }[]): JourneyDay[] {
|
|
const dates = [...new Set(entries.map(e => e.entry_date))].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0))
|
|
return dates.map((date, i) => ({ date, color: DAY_COLORS[i % DAY_COLORS.length] }))
|
|
}
|
|
|
|
/** Look a date's colour up out of `journeyDays`, falling back to the first day's. */
|
|
export function dayColorOf(days: JourneyDay[], date: string): string {
|
|
return days.find(d => d.date === date)?.color ?? DAY_COLORS[0]
|
|
}
|