fix(tours): sorts that name their order, the note focused without autofocus

The checklist and the obstacle data sorted texts without a compare
function. They now sort by code units through one shared compareCodeUnits,
the order a bare sort gave, the same on every machine; the material data of
a lock's parts no longer orders by the server's locale, so its hash cannot
change with it. The note editor takes the focus through a ref instead of
autoFocus, a direct function reference in a map becomes a call, and the
GPX import's default fields are a named constant.
This commit is contained in:
Maurice
2026-10-17 03:18:04 +00:00
parent 9272151c07
commit 09caf4bc3f
10 changed files with 48 additions and 13 deletions
@@ -18,7 +18,7 @@ import {
Unlink,
X,
} from 'lucide-react';
import { useLayoutEffect, useRef, useState, type KeyboardEvent, type ReactNode } from 'react';
import { useEffect, useLayoutEffect, useRef, useState, type KeyboardEvent, type ReactNode } from 'react';
import { useTranslation } from '../../../i18n';
import { fs } from '../../shared/DialogShell';
import { Tooltip } from '../../shared/Tooltip';
@@ -197,6 +197,11 @@ function NoteEditor({
onCancel: () => void;
}) {
const { t } = useTranslation();
const box = useRef<HTMLTextAreaElement>(null);
// The note opens for writing, so it takes the focus once, when it opens.
useEffect(() => {
box.current?.focus();
}, []);
const onKeyDown = (event: KeyboardEvent<HTMLTextAreaElement>) => {
if (event.key !== 'Escape') return;
// The map card and the dialog close on Escape; inside the note it only ends the edit.
@@ -209,8 +214,8 @@ function NoteEditor({
<textarea
rows={2}
maxLength={NOTE_MAX}
ref={box}
value={draft}
autoFocus
aria-label={t('tours.paddle.check.note')}
onChange={(event) => onChange(event.target.value)}
onKeyDown={onKeyDown}
@@ -1,3 +1,4 @@
import { compareCodeUnits } from '@trek/shared';
import { AlertTriangle, Info, Loader2, WifiOff } from 'lucide-react';
import { useShallow } from 'zustand/react/shallow';
import { useTranslation } from '../../../i18n';
@@ -9,7 +10,7 @@ function dataDate(regions: readonly { source_timestamp?: string | null }[], lang
const times = regions
.map((region) => region.source_timestamp)
.filter((time): time is string => !!time)
.sort();
.sort(compareCodeUnits);
return times[0] ? new Date(times[0]).toLocaleDateString(language, { dateStyle: 'medium' }) : null;
}