fix(mobile): split the new phone sheets and cards below the lint limits, follow the tests to the new rows

This commit is contained in:
Maurice
2026-10-22 21:43:15 +02:00
parent 49afee161d
commit 8e420cc1f1
14 changed files with 644 additions and 514 deletions
@@ -266,9 +266,9 @@ function CatalogSearch({ admin }: { admin: Admin }) {
);
}
function RegionRow({ region, admin }: { region: PaddleRegion; admin: Admin }) {
/** What a region's read stands at: its status, where it came from, its objects, its date and its water. */
function RegionBadges({ region }: { region: PaddleRegion }) {
const { t, language } = useTranslation();
const busy = admin.busyId === region.id;
const percent = progressPercent(region);
const status =
region.status === 'importing' && region.progress
@@ -280,6 +280,38 @@ function RegionRow({ region, admin }: { region: PaddleRegion; admin: Admin }) {
const km = region.network
? new Intl.NumberFormat(language, { maximumFractionDigits: 0 }).format(region.network.water_km)
: null;
return (
<div className="mt-1 flex flex-wrap gap-1">
<MBadge
caps={false}
className={TONE[regionStatusTone(region.status)]}
icon={region.status === 'importing' ? <Loader2 size={10} className="animate-spin" /> : undefined}
>
{status}
{percent === null ? '' : ` ${new Intl.NumberFormat(language, { style: 'percent' }).format(percent / 100)}`}
</MBadge>
{region.origin === 'auto' && (
<MBadge caps={false} icon={<Sparkles size={10} strokeWidth={2.2} />}>
{t('admin.paddleRegions.origin.auto')}
</MBadge>
)}
{region.imported_at && (
<MBadge caps={false}>{t('admin.paddleRegions.objects', { count: region.feature_count })}</MBadge>
)}
{region.imported_at && date && <MBadge caps={false}>{t('admin.paddleRegions.asOf', { date })}</MBadge>}
{km !== null && <MBadge caps={false}>{t('admin.paddleRegions.network.km', { km })}</MBadge>}
{!region.network && region.imported_at && region.status !== 'importing' && (
<MBadge caps={false} className="!text-[color:var(--m-st-pending)]">
{t('admin.paddleRegions.network.missing')}
</MBadge>
)}
</div>
);
}
function RegionRow({ region, admin }: { region: PaddleRegion; admin: Admin }) {
const { t } = useTranslation();
const busy = admin.busyId === region.id;
return (
<div
data-testid="paddle-region-row"
@@ -295,31 +327,7 @@ function RegionRow({ region, admin }: { region: PaddleRegion; admin: Admin }) {
<div className="truncate text-[length:calc(13px*var(--fs-scale-body,1))] font-semibold text-m-ink">
{region.name}
</div>
<div className="mt-1 flex flex-wrap gap-1">
<MBadge
caps={false}
className={TONE[regionStatusTone(region.status)]}
icon={region.status === 'importing' ? <Loader2 size={10} className="animate-spin" /> : undefined}
>
{status}
{percent === null ? '' : ` ${new Intl.NumberFormat(language, { style: 'percent' }).format(percent / 100)}`}
</MBadge>
{region.origin === 'auto' && (
<MBadge caps={false} icon={<Sparkles size={10} strokeWidth={2.2} />}>
{t('admin.paddleRegions.origin.auto')}
</MBadge>
)}
{region.imported_at && (
<MBadge caps={false}>{t('admin.paddleRegions.objects', { count: region.feature_count })}</MBadge>
)}
{region.imported_at && date && <MBadge caps={false}>{t('admin.paddleRegions.asOf', { date })}</MBadge>}
{km !== null && <MBadge caps={false}>{t('admin.paddleRegions.network.km', { km })}</MBadge>}
{!region.network && region.imported_at && region.status !== 'importing' && (
<MBadge caps={false} className="!text-[color:var(--m-st-pending)]">
{t('admin.paddleRegions.network.missing')}
</MBadge>
)}
</div>
<RegionBadges region={region} />
{region.status === 'failed' && region.error && (
<p className="mt-1 line-clamp-2 break-words font-geist text-[length:calc(10px*var(--fs-scale-caption,1))] text-[color:var(--m-st-danger)]">
{region.error}
@@ -219,6 +219,188 @@ function RegionSheet({ region, busy, offline, error, onClose, onSave }: EditorPr
);
}
type Catalog = ReturnType<typeof useSchoolHolidayCatalog>;
type Removal = { label: string; action: () => Promise<boolean> };
/** Offline, loading and a failed read, each said where the card starts. */
function CatalogNotices({ state, disabled }: { state: Catalog; disabled: boolean }) {
const { t } = useTranslation();
return (
<>
{state.offline && (
<p
role="status"
className="flex items-center gap-2 rounded-[12px] bg-[color:var(--m-ic)] px-3 py-2 text-[length:calc(11px*var(--fs-scale-caption,1))] font-semibold text-[color:var(--m-st-pending)]"
>
<WifiOff size={13} className="flex-none" />
{t('schoolCatalog.offline')}
</p>
)}
{state.loading && (
<p
role="status"
className="flex items-center gap-2 font-geist text-[length:calc(11px*var(--fs-scale-caption,1))] text-m-muted"
>
<Loader2 size={13} className="animate-spin" />
{t('common.loading')}
</p>
)}
{state.error && !state.editor && (
<div role="alert" className="flex items-center gap-2 rounded-[12px] bg-[color:var(--m-ic)] px-3 py-2">
<span className="min-w-0 flex-1 text-[length:calc(11px*var(--fs-scale-caption,1))] font-semibold text-[color:var(--m-st-danger)]">
{state.error}
</span>
<MAdminButton variant="ghost" disabled={disabled} onClick={() => void state.refresh()}>
{t('schoolCatalog.retry')}
</MAdminButton>
</div>
)}
</>
);
}
/** The country shown, with adding one and deleting the shown one (only while it has no regions). */
function CountryPicker({
state,
selected,
regionCount,
disabled,
onSelect,
onAdd,
onRemove,
}: {
state: Catalog;
selected: string;
regionCount: number;
disabled: boolean;
onSelect: (code: string) => void;
onAdd: () => void;
onRemove: (removal: Removal) => void;
}) {
const { t } = useTranslation();
return (
<>
{state.catalog.countries.length > 0 ? (
<div>
<span className={LABEL}>{t('schoolCatalog.country')}</span>
<div className="flex items-center gap-2">
<CustomSelect
value={selected}
onChange={(value) => onSelect(String(value))}
searchable
disabled={disabled}
size="sm"
options={state.catalog.countries.map((item) => ({ value: item.code, label: item.name }))}
placeholder={t('schoolCatalog.country')}
style={{ flex: 1, minWidth: 0 }}
/>
<button
type="button"
aria-label={t('schoolCatalog.addCountry')}
disabled={disabled}
onClick={onAdd}
className={ROUND}
>
<Plus size={16} strokeWidth={2.2} />
</button>
<button
type="button"
aria-label={t('schoolCatalog.deleteCountry')}
disabled={disabled || regionCount > 0}
onClick={() => onRemove({ label: selected, action: () => state.deleteCountry(selected) })}
className={ROUND}
>
<Trash2 size={15} strokeWidth={2} />
</button>
</div>
{regionCount > 0 && (
<p className="mt-1.5 font-geist text-[length:calc(9.5px*var(--fs-scale-caption,1))] text-m-faint">
{t('schoolCatalog.deleteHint')}
</p>
)}
</div>
) : (
!state.loading && (
<MAdminButton variant="ghost" disabled={disabled} onClick={onAdd} className="self-start">
<Plus size={13} strokeWidth={2.2} />
{t('schoolCatalog.addCountry')}
</MAdminButton>
)
)}
</>
);
}
/** The regions of a country, each opened or deleted, and the button that adds one. */
function RegionList({
state,
country,
regions,
disabled,
onRemove,
}: {
state: Catalog;
country: string;
regions: Catalog['catalog']['regions'];
disabled: boolean;
onRemove: (removal: Removal) => void;
}) {
const { t } = useTranslation();
return (
<>
{regions.length === 0 ? (
<p className="rounded-[14px] border border-dashed border-[color:var(--m-rowbr)] px-4 py-4 text-center font-geist text-[length:calc(11px*var(--fs-scale-caption,1))] text-m-faint">
{t('schoolCatalog.empty')}
</p>
) : (
<div className="flex flex-col divide-y divide-[color:var(--m-rowbr)] rounded-[14px] border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)]">
{regions.map((region) => (
<div key={region.id} className="flex items-center gap-2 py-1.5 pe-2 ps-1.5">
<button
type="button"
disabled={disabled}
onClick={() => void state.openRegion(region.id)}
className="flex min-w-0 flex-1 items-center gap-2.5 px-1.5 py-1 text-start"
>
<span
aria-hidden="true"
className="flex h-[32px] w-[32px] flex-none items-center justify-center rounded-full bg-[color:var(--m-sheetop)] text-m-muted"
>
<MapPinned size={14} strokeWidth={1.9} />
</span>
<span className="min-w-0 flex-1 truncate text-[length:calc(13px*var(--fs-scale-body,1))] font-semibold text-m-ink">
{region.name}
</span>
<ChevronRight aria-hidden="true" size={15} className="flex-none text-m-faint rtl:rotate-180" />
</button>
<button
type="button"
aria-label={`${t('common.delete')} ${region.name}`}
disabled={disabled}
onClick={() =>
onRemove({ label: region.name, action: () => state.deleteRegion(region.id, region.revision) })
}
className="flex h-[32px] w-[32px] flex-none items-center justify-center rounded-full bg-[color:var(--m-sheetop)] text-m-muted disabled:opacity-40"
>
<Trash2 size={13} strokeWidth={2} />
</button>
</div>
))}
</div>
)}
<button
type="button"
disabled={disabled}
onClick={() => state.setEditor({ id: 0, country, name: '', code: '', revision: 0, holidays: [] })}
className="flex h-[42px] items-center justify-center gap-1.5 rounded-full border border-dashed border-[color:var(--m-rowbr)] text-[length:calc(12px*var(--fs-scale-body,1))] font-semibold text-m-muted disabled:opacity-40"
>
<Plus size={14} strokeWidth={2.2} />
{t('schoolCatalog.addRegion')}
</button>
</>
);
}
/**
* The school holiday catalog on the phone: the shared holiday regions per
* country that everyone can pick in their vacation settings. The state is
@@ -229,7 +411,7 @@ export default function MAdminSchoolHolidayCatalog() {
const state = useSchoolHolidayCatalog();
const [country, setCountry] = useState('');
const [adding, setAdding] = useState(false);
const [remove, setRemove] = useState<{ label: string; action: () => Promise<boolean> } | null>(null);
const [remove, setRemove] = useState<Removal | null>(null);
const selectedCountry =
state.catalog.countries.find((item) => item.code === country)?.code || state.catalog.countries[0]?.code || '';
const regions = state.catalog.regions.filter((region) => region.country === selectedCountry);
@@ -257,139 +439,26 @@ export default function MAdminSchoolHolidayCatalog() {
<div
className={`mt-3 flex flex-col gap-3 border-t border-[color:var(--m-rowbr)] pt-3 ${state.busy ? 'opacity-60' : ''}`}
>
{state.offline && (
<p
role="status"
className="flex items-center gap-2 rounded-[12px] bg-[color:var(--m-ic)] px-3 py-2 text-[length:calc(11px*var(--fs-scale-caption,1))] font-semibold text-[color:var(--m-st-pending)]"
>
<WifiOff size={13} className="flex-none" />
{t('schoolCatalog.offline')}
</p>
)}
{state.loading && (
<p
role="status"
className="flex items-center gap-2 font-geist text-[length:calc(11px*var(--fs-scale-caption,1))] text-m-muted"
>
<Loader2 size={13} className="animate-spin" />
{t('common.loading')}
</p>
)}
{state.error && !state.editor && (
<div role="alert" className="flex items-center gap-2 rounded-[12px] bg-[color:var(--m-ic)] px-3 py-2">
<span className="min-w-0 flex-1 text-[length:calc(11px*var(--fs-scale-caption,1))] font-semibold text-[color:var(--m-st-danger)]">
{state.error}
</span>
<MAdminButton variant="ghost" disabled={disabled} onClick={() => void state.refresh()}>
{t('schoolCatalog.retry')}
</MAdminButton>
</div>
)}
<CatalogNotices state={state} disabled={disabled} />
{state.catalog.countries.length > 0 ? (
<div>
<span className={LABEL}>{t('schoolCatalog.country')}</span>
<div className="flex items-center gap-2">
<CustomSelect
value={selectedCountry}
onChange={(value) => setCountry(String(value))}
searchable
disabled={disabled}
size="sm"
options={state.catalog.countries.map((item) => ({ value: item.code, label: item.name }))}
placeholder={t('schoolCatalog.country')}
style={{ flex: 1, minWidth: 0 }}
/>
<button
type="button"
aria-label={t('schoolCatalog.addCountry')}
disabled={disabled}
onClick={() => setAdding(true)}
className={ROUND}
>
<Plus size={16} strokeWidth={2.2} />
</button>
<button
type="button"
aria-label={t('schoolCatalog.deleteCountry')}
disabled={disabled || regions.length > 0}
onClick={() =>
setRemove({ label: selectedCountry, action: () => state.deleteCountry(selectedCountry) })
}
className={ROUND}
>
<Trash2 size={15} strokeWidth={2} />
</button>
</div>
{regions.length > 0 && (
<p className="mt-1.5 font-geist text-[length:calc(9.5px*var(--fs-scale-caption,1))] text-m-faint">
{t('schoolCatalog.deleteHint')}
</p>
)}
</div>
) : (
!state.loading && (
<MAdminButton variant="ghost" disabled={disabled} onClick={() => setAdding(true)} className="self-start">
<Plus size={13} strokeWidth={2.2} />
{t('schoolCatalog.addCountry')}
</MAdminButton>
)
)}
<CountryPicker
state={state}
selected={selectedCountry}
regionCount={regions.length}
disabled={disabled}
onSelect={setCountry}
onAdd={() => setAdding(true)}
onRemove={setRemove}
/>
{selectedCountry && (
<>
{regions.length === 0 ? (
<p className="rounded-[14px] border border-dashed border-[color:var(--m-rowbr)] px-4 py-4 text-center font-geist text-[length:calc(11px*var(--fs-scale-caption,1))] text-m-faint">
{t('schoolCatalog.empty')}
</p>
) : (
<div className="flex flex-col divide-y divide-[color:var(--m-rowbr)] rounded-[14px] border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)]">
{regions.map((region) => (
<div key={region.id} className="flex items-center gap-2 py-1.5 pe-2 ps-1.5">
<button
type="button"
disabled={disabled}
onClick={() => void state.openRegion(region.id)}
className="flex min-w-0 flex-1 items-center gap-2.5 px-1.5 py-1 text-start"
>
<span
aria-hidden="true"
className="flex h-[32px] w-[32px] flex-none items-center justify-center rounded-full bg-[color:var(--m-sheetop)] text-m-muted"
>
<MapPinned size={14} strokeWidth={1.9} />
</span>
<span className="min-w-0 flex-1 truncate text-[length:calc(13px*var(--fs-scale-body,1))] font-semibold text-m-ink">
{region.name}
</span>
<ChevronRight aria-hidden="true" size={15} className="flex-none text-m-faint rtl:rotate-180" />
</button>
<button
type="button"
aria-label={`${t('common.delete')} ${region.name}`}
disabled={disabled}
onClick={() =>
setRemove({ label: region.name, action: () => state.deleteRegion(region.id, region.revision) })
}
className="flex h-[32px] w-[32px] flex-none items-center justify-center rounded-full bg-[color:var(--m-sheetop)] text-m-muted disabled:opacity-40"
>
<Trash2 size={13} strokeWidth={2} />
</button>
</div>
))}
</div>
)}
<button
type="button"
disabled={disabled}
onClick={() =>
state.setEditor({ id: 0, country: selectedCountry, name: '', code: '', revision: 0, holidays: [] })
}
className="flex h-[42px] items-center justify-center gap-1.5 rounded-full border border-dashed border-[color:var(--m-rowbr)] text-[length:calc(12px*var(--fs-scale-body,1))] font-semibold text-m-muted disabled:opacity-40"
>
<Plus size={14} strokeWidth={2.2} />
{t('schoolCatalog.addRegion')}
</button>
</>
<RegionList
state={state}
country={selectedCountry}
regions={regions}
disabled={disabled}
onRemove={setRemove}
/>
)}
</div>