Files
TREK/client/src/components/Journey/JourneyDayImportButton.tsx
T
Maurice 94c369b913 feat(journey): prepare the recorded days of a journey's trips in the background, switched on per journey, with each day's state
Journey Settings get "Prepare recorded days automatically" under GPX Tracks,
off by default and set by the owner. With it on, the Dawarich background
check also reads the linked trips of the journey for the owner and every
editor with a connection of their own, within the same 400 day reach and
windows as the trip sync, and only for new and changed stays: a trip the
person travels on is not asked twice, and the stays of a trip they are not
on are filed under no trip. Nothing is written into the journey; the stays
wait at their day, and a stay taken over or left out is never offered again.

Under the switch the caller sees when their stays were last fetched, or why
not (no connection, no dated trip, background check off, the reason of the
last failure beside the state still shown), with a "Fetch now" that the
switch also runs when it is turned on. A day of the trips that is not final
yet carries a dot on its take-over button, on the phone in the stay sheet,
and the tooltip says whether it is still running, was fetched before it
ended, was not fetched yet or shows an older state after a failed refresh.
The day review says so for today too.

Server: migration 046180 adds journeys.auto_prepare_recordings and
journey_recording_prep (the last attempt, last success and last error per
journey and person). JourneyRecordingPrepService in the journey domain lists
the prepared trips and keeps the status; DawarichSyncService walks those
trips in the same loop as the person's own and records each journey's
outcome. GET /api/journeys/:id/recordings/prep answers the caller's status
under a @trek/shared contract, the MCP tool get_journey_recording_prep reads
the same, and update_journey takes auto_prepare_recordings like the PUT
contract. The column stays out of the plugin output. All 27 locales carry
the strings; the Journey, Dawarich and MCP tool wiki pages describe it.
2026-10-21 17:39:33 +02:00

69 lines
2.6 KiB
TypeScript

import { ListChecks } from 'lucide-react';
import type React from 'react';
import { useTranslation } from '../../i18n';
import { fs } from '../shared/DialogShell';
import { Tooltip } from '../shared/Tooltip';
import { dayPrepText, dayPrepUnsettled, type JourneyDayPrep } from './journeyRecordingPrepModel';
/**
* Taking a day over with its stays (JRN-02), in the day header beside the
* route: for an editor whose Dawarich answers, with the number of stays still
* waiting on the day; offline it stays, dimmed, and says why. While the
* journey prepares its days (JRN-03), a dot marks a day that is not final yet
* (still running, fetched before it ended, not fetched, or stale after a
* failed refresh) and the tooltip says which.
*/
export default function JourneyDayImportButton({
pending,
canTakeOver,
needsConnection,
prep,
onOpen,
}: {
/** Stays of the day nobody decided on yet. */
pending: number;
canTakeOver: boolean;
needsConnection: boolean;
/** Where preparing the day stands; absent while the journey does not prepare it. */
prep?: JourneyDayPrep | null;
onOpen: () => void;
}): React.ReactElement | null {
const { t, locale } = useTranslation();
if (!canTakeOver && !needsConnection) return null;
const base = !canTakeOver
? t('dawarich.error.offline')
: pending > 0
? t('journey.dayImport.pending', { count: pending })
: t('journey.dayImport.openHint');
const unsettled = canTakeOver && dayPrepUnsettled(prep);
// The tooltip breaks before the second line; a screen reader reads both as one.
const label = unsettled && prep ? `${base}\n${dayPrepText(prep, t, locale)}` : base;
return (
<Tooltip label={label} placement="top">
<button
type="button"
onClick={canTakeOver ? onOpen : undefined}
aria-disabled={!canTakeOver}
aria-label={label}
data-testid="journey-day-import"
className="inline-flex h-7 items-center gap-1 rounded-full px-2 text-content-secondary transition-colors aria-disabled:cursor-default aria-disabled:opacity-40 [&:not([aria-disabled=true])]:hover:bg-surface-hover"
style={{ background: 'var(--vg-surf2)' }}
>
<ListChecks size={14} strokeWidth={2.2} aria-hidden="true" />
{pending > 0 && (
<span className="font-bold tabular-nums" style={fs(10.5)}>
{pending}
</span>
)}
{unsettled && (
<span
data-testid="journey-day-prep-unsettled"
className="h-1.5 w-1.5 rounded-full bg-warning"
aria-hidden="true"
/>
)}
</button>
</Tooltip>
);
}