fix(ci): repair mobile client checks

Split mobile view logic at existing UI boundaries and keep shared calendar hooks outside component modules. Register the phone-only files and make the sheet gesture and final budget assertions independent of scheduling.
This commit is contained in:
Maurice
2026-12-04 10:30:11 +01:00
parent b06fa93c4a
commit 34b9b7b0d0
39 changed files with 1434 additions and 1141 deletions
@@ -1,4 +1,5 @@
import { useState, useEffect, useId, type ReactNode } from 'react'
import { useId, type ReactNode } from 'react'
import { useIcsSubscription } from './useIcsSubscription'
import { RefreshCw, Calendar, Power } from 'lucide-react'
import { SubscribeLinks } from './SubscribeLinks'
import ToggleSwitch from '../Settings/ToggleSwitch'
@@ -13,24 +14,6 @@ export interface IcsSubscribeModalProps {
onClose: () => void
}
// A server that has no APP_URL configured hands back a host-relative path; the
// webcal:// handoff and Google deep link need an absolute URL, so resolve it
// against the current origin as a fallback.
function absolutize(url: string): string {
if (!url) return ''
if (/^https?:\/\//i.test(url)) return url
if (url.startsWith('/')) return window.location.origin + url
return url
}
// The feeds take days=0 to leave out the all-day summary every day with
// untimed places or notes gets (#2602). The choice lives in the link itself,
// so a calendar keeps what it subscribed to and the token stays one per trip.
function withDayEvents(url: string, dayEvents: boolean): string {
if (!url || dayEvents) return url
return `${url}${url.includes('?') ? '&' : '?'}days=0`
}
/** The switch for those summaries, above the links it changes, on both shells. */
export function DayEventsSwitch({ on, onToggle }: { on: boolean; onToggle: () => void }) {
const { t } = useTranslation()
@@ -48,46 +31,6 @@ export function DayEventsSwitch({ on, onToggle }: { on: boolean; onToggle: () =>
)
}
/** Opening reads the token. Creating or changing it always takes an explicit action. */
export function useIcsSubscription(endpoint: string) {
const tokenUrl = `${endpoint}/token`
const [feedUrl, setFeedUrl] = useState<string | null>(null)
const [loadedTokenUrl, setLoadedTokenUrl] = useState<string | null>(null)
const [busy, setBusy] = useState(false)
const [dayEvents, setDayEvents] = useState(true)
const toggleDayEvents = () => setDayEvents(on => !on)
const httpsUrl = feedUrl ? withDayEvents(absolutize(feedUrl), dayEvents) : ''
const webcalUrl = httpsUrl ? httpsUrl.replace(/^https?:\/\//, 'webcal://') : ''
useEffect(() => {
let active = true
void fetch(tokenUrl, { credentials: 'include' })
.then(async res => res.ok ? (await res.json() as { feed_url: string | null }).feed_url : null)
.catch(() => null)
.then(url => {
if (!active) return
setFeedUrl(url)
setLoadedTokenUrl(tokenUrl)
})
return () => { active = false }
}, [tokenUrl])
const mutate = async (method: 'POST' | 'PUT' | 'DELETE') => {
setBusy(true)
try {
const res = await fetch(tokenUrl, { method, credentials: 'include' })
if (res.ok) {
const data = await res.json() as { feed_url: string | null }
setFeedUrl(data.feed_url)
}
} catch { /* ignore */ }
setBusy(false)
}
return { loading: loadedTokenUrl !== tokenUrl, busy, feedUrl, httpsUrl, webcalUrl, mutate, dayEvents, toggleDayEvents }
}
export function IcsSubscribeModal({ endpoint, title, description, onClose }: IcsSubscribeModalProps) {
const titleId = useId()
const { loading, busy, feedUrl, httpsUrl, webcalUrl, mutate, dayEvents, toggleDayEvents } = useIcsSubscription(endpoint)
@@ -89,51 +89,59 @@ export default function PlaceImagePicker({
/>
);
const showUploadRow = mobile && !own?.pendingPreview;
const showTiles = Boolean(current || attached.length || photos.length || (upload && !showUploadRow));
const renderGallery = () => {
const showTiles = Boolean(current || attached.length || photos.length || (upload && !showUploadRow));
return (
<>
{showTiles && (
<div className={`grid grid-cols-3 gap-1.5 ${showUploadRow && upload ? 'mt-2' : ''}`}>
{!showUploadRow && upload}
{current && (
<button
type="button"
onClick={() => (chosen.kind === 'current' ? own?.onRemove() : onPickUrl(current))}
aria-pressed={chosen.kind === 'current'}
aria-label={t('places.image.current')}
onMouseEnter={() => setHovered({ kind: 'own', label: t('places.image.current') })}
onMouseLeave={() => setHovered(null)}
className={`${TILE} ${ring(chosen.kind === 'current', dialog)}`}
>
<img src={current} alt="" className="h-full w-full object-cover" />
{chosen.kind === 'current' && <Picked />}
</button>
)}
{attached.map((file) => (
<AttachedTile
key={file.id}
file={file}
selected={chosen.kind === 'attached' && chosen.fileId === file.id}
onPick={() => own?.onPickAttached(file)}
onHover={(on) => setHovered(on ? { kind: 'own', label: file.original_name } : null)}
dialog={dialog}
/>
))}
{photos.map((photo) => (
<PhotoTile
key={photo.key}
photo={photo}
selected={chosen.kind === 'url' && chosen.url === photo.url}
onPick={onPickUrl}
onHover={(on) => setHovered(on ? { kind: 'photo', photo } : null)}
dialog={dialog}
t={t}
/>
))}
</div>
)}
</>
);
};
return (
<>
{showUploadRow && upload}
{showTiles && (
<div className={`grid grid-cols-3 gap-1.5 ${showUploadRow && upload ? 'mt-2' : ''}`}>
{!showUploadRow && upload}
{current && (
<button
type="button"
onClick={() => (chosen.kind === 'current' ? own?.onRemove() : onPickUrl(current))}
aria-pressed={chosen.kind === 'current'}
aria-label={t('places.image.current')}
onMouseEnter={() => setHovered({ kind: 'own', label: t('places.image.current') })}
onMouseLeave={() => setHovered(null)}
className={`${TILE} ${ring(chosen.kind === 'current', dialog)}`}
>
<img src={current} alt="" className="h-full w-full object-cover" />
{chosen.kind === 'current' && <Picked />}
</button>
)}
{attached.map((file) => (
<AttachedTile
key={file.id}
file={file}
selected={chosen.kind === 'attached' && chosen.fileId === file.id}
onPick={() => own?.onPickAttached(file)}
onHover={(on) => setHovered(on ? { kind: 'own', label: file.original_name } : null)}
dialog={dialog}
/>
))}
{photos.map((photo) => (
<PhotoTile
key={photo.key}
photo={photo}
selected={chosen.kind === 'url' && chosen.url === photo.url}
onPick={onPickUrl}
onHover={(on) => setHovered(on ? { kind: 'photo', photo } : null)}
dialog={dialog}
t={t}
/>
))}
</div>
)}
{renderGallery()}
{(shown || removable) && (
<CreditLine shown={shown} onRemove={removable ? own?.onRemove : undefined} dialog={dialog} t={t} />
)}
@@ -1,4 +1,4 @@
import { useState } from 'react'
import { useSubscribeLinks } from './useSubscribeLinks'
import { Copy, Check, CalendarPlus, Calendar } from 'lucide-react'
import { useTranslation } from '../../i18n'
@@ -7,45 +7,6 @@ interface SubscribeLinksProps {
webcalUrl: string
}
/**
* The provider links and clipboard behavior shared by both subscription dialogs.
*/
export function useSubscribeLinks(httpsUrl: string, webcalUrl: string) {
const { t } = useTranslation()
const [copied, setCopied] = useState<'https' | 'webcal' | null>(null)
// Google Calendar's add-by-URL deep link. The cid must carry the webcal://
// scheme (not https), URL-encoded, and the feed must be served over HTTPS.
const googleUrl = `https://www.google.com/calendar/render?cid=${encodeURIComponent(webcalUrl)}`
const copy = async (url: string, which: 'https' | 'webcal') => {
try {
if (navigator.clipboard && window.isSecureContext) {
await navigator.clipboard.writeText(url)
} else {
// Fallback for non-secure contexts (plain HTTP) where navigator.clipboard is unavailable
const ta = document.createElement('textarea')
ta.value = url
ta.style.position = 'fixed'
ta.style.left = '-9999px'
document.body.appendChild(ta)
ta.focus()
ta.select()
document.execCommand('copy')
document.body.removeChild(ta)
}
setCopied(which)
setTimeout(() => setCopied(null), 2000)
} catch { /* ignore */ }
}
const manualLinks = [
{ label: 'Google Calendar', hint: t('dashboard.ics.pasteFromUrl'), url: httpsUrl, copied: copied === 'https', onCopy: () => void copy(httpsUrl, 'https') },
{ label: 'Apple Calendar / Outlook', hint: 'webcal://', url: webcalUrl, copied: copied === 'webcal', onCopy: () => void copy(webcalUrl, 'webcal') },
]
return { googleUrl, manualLinks }
}
export function SubscribeLinks({ httpsUrl, webcalUrl }: SubscribeLinksProps) {
const { t } = useTranslation()
const { googleUrl, manualLinks } = useSubscribeLinks(httpsUrl, webcalUrl)
@@ -483,6 +483,36 @@ function ItineraryCard({ it, tzFrom, tzTo, is12h, expanded, onToggle, onAdd, add
// the TransportModal (and could embed anywhere else). The host owns the modal
// chrome and closes itself once onAdd resolves.
function TransitStopFields({ mobile, isMobile, from, to, setFrom, setTo, quickPicks, near }: {
mobile: boolean
isMobile: boolean
from: PickedPlace | null
to: PickedPlace | null
setFrom: (place: PickedPlace | null) => void
setTo: (place: PickedPlace | null) => void
quickPicks: PickedPlace[]
near: string | null
}) {
const { t } = useTranslation()
return (
<div className={mobile ? 'flex flex-col gap-2.5 rounded-[14px] bg-m-ic p-3' : `flex gap-2 ${isMobile ? 'flex-col' : 'items-end'}`}>
<StopPicker mobile={mobile} label={t('transit.from')} value={from} onPick={setFrom} quickPicks={quickPicks} near={near} placeholder={t('transit.searchStop')} />
{!mobile && !isMobile && (
<button type="button"
onClick={() => { const f = from; setFrom(to); setTo(f) }}
aria-label={t('transit.swap')}
title={t('transit.swap')}
className="bg-surface-secondary text-content-muted"
style={{ border: 'none', borderRadius: 10, width: 38, height: 38, display: 'grid', placeItems: 'center', cursor: 'pointer', flexShrink: 0 }}
>
<ArrowLeftRight size={15} />
</button>
)}
<StopPicker mobile={mobile} label={t('transit.to')} value={to} onPick={setTo} quickPicks={quickPicks} near={near} placeholder={t('transit.searchStop')} />
</div>
)
}
interface TransitSearchPanelProps {
day: Day
days: Day[]
@@ -688,22 +718,8 @@ export default function TransitSearchPanel({ day, days, places, accommodations =
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: 16, fontFamily: 'var(--font-system)' }}>
<WalkTransitNote walk={walkHere} />
{/* from / to — stacked tight on mobile, swap button on desktop only */}
<div className={mobile ? 'flex flex-col gap-2.5 rounded-[14px] bg-m-ic p-3' : `flex gap-2 ${isMobile ? 'flex-col' : 'items-end'}`}>
<StopPicker mobile={mobile} label={t('transit.from')} value={from} onPick={setFrom} quickPicks={quickPicks} near={near} placeholder={t('transit.searchStop')} />
{!mobile && !isMobile && (
<button type="button"
onClick={() => { const f = from; setFrom(to); setTo(f) }}
aria-label={t('transit.swap')}
title={t('transit.swap')}
className="bg-surface-secondary text-content-muted"
style={{ border: 'none', borderRadius: 10, width: 38, height: 38, display: 'grid', placeItems: 'center', cursor: 'pointer', flexShrink: 0 }}
>
<ArrowLeftRight size={15} />
</button>
)}
<StopPicker mobile={mobile} label={t('transit.to')} value={to} onPick={setTo} quickPicks={quickPicks} near={near} placeholder={t('transit.searchStop')} />
</div>
<TransitStopFields mobile={mobile} isMobile={isMobile} from={from} to={to}
setFrom={setFrom} setTo={setTo} quickPicks={quickPicks} near={near} />
{mobile ? (
<>
@@ -0,0 +1,72 @@
import { useEffect, useState } from 'react';
// A server that has no APP_URL configured hands back a host-relative path; the
// webcal:// handoff and Google deep link need an absolute URL, so resolve it
// against the current origin as a fallback.
function absolutize(url: string): string {
if (!url) return '';
if (/^https?:\/\//i.test(url)) return url;
if (url.startsWith('/')) return window.location.origin + url;
return url;
}
// The feeds take days=0 to leave out the all-day summary every day with
// untimed places or notes gets (#2602). The choice lives in the link itself,
// so a calendar keeps what it subscribed to and the token stays one per trip.
function withDayEvents(url: string, dayEvents: boolean): string {
if (!url || dayEvents) return url;
return `${url}${url.includes('?') ? '&' : '?'}days=0`;
}
/** Opening reads the token. Creating or changing it always takes an explicit action. */
export function useIcsSubscription(endpoint: string) {
const tokenUrl = `${endpoint}/token`;
const [feedUrl, setFeedUrl] = useState<string | null>(null);
const [loadedTokenUrl, setLoadedTokenUrl] = useState<string | null>(null);
const [busy, setBusy] = useState(false);
const [dayEvents, setDayEvents] = useState(true);
const toggleDayEvents = () => setDayEvents((on) => !on);
const httpsUrl = feedUrl ? withDayEvents(absolutize(feedUrl), dayEvents) : '';
const webcalUrl = httpsUrl ? httpsUrl.replace(/^https?:\/\//, 'webcal://') : '';
useEffect(() => {
let active = true;
void fetch(tokenUrl, { credentials: 'include' })
.then(async (res) => (res.ok ? ((await res.json()) as { feed_url: string | null }).feed_url : null))
.catch(() => null)
.then((url) => {
if (!active) return;
setFeedUrl(url);
setLoadedTokenUrl(tokenUrl);
});
return () => {
active = false;
};
}, [tokenUrl]);
const mutate = async (method: 'POST' | 'PUT' | 'DELETE') => {
setBusy(true);
try {
const res = await fetch(tokenUrl, { method, credentials: 'include' });
if (res.ok) {
const data = (await res.json()) as { feed_url: string | null };
setFeedUrl(data.feed_url);
}
} catch {
/* ignore */
}
setBusy(false);
};
return {
loading: loadedTokenUrl !== tokenUrl,
busy,
feedUrl,
httpsUrl,
webcalUrl,
mutate,
dayEvents,
toggleDayEvents,
};
}
@@ -0,0 +1,55 @@
import { useState } from 'react';
import { useTranslation } from '../../i18n';
/**
* The provider links and clipboard behavior shared by both subscription dialogs.
*/
export function useSubscribeLinks(httpsUrl: string, webcalUrl: string) {
const { t } = useTranslation();
const [copied, setCopied] = useState<'https' | 'webcal' | null>(null);
// Google Calendar's add-by-URL deep link. The cid must carry the webcal://
// scheme (not https), URL-encoded, and the feed must be served over HTTPS.
const googleUrl = `https://www.google.com/calendar/render?cid=${encodeURIComponent(webcalUrl)}`;
const copy = async (url: string, which: 'https' | 'webcal') => {
try {
if (navigator.clipboard && window.isSecureContext) {
await navigator.clipboard.writeText(url);
} else {
// Fallback for non-secure contexts (plain HTTP) where navigator.clipboard is unavailable
const ta = document.createElement('textarea');
ta.value = url;
ta.style.position = 'fixed';
ta.style.left = '-9999px';
document.body.appendChild(ta);
ta.focus();
ta.select();
document.execCommand('copy');
document.body.removeChild(ta);
}
setCopied(which);
setTimeout(() => setCopied(null), 2000);
} catch {
/* ignore */
}
};
const manualLinks = [
{
label: 'Google Calendar',
hint: t('dashboard.ics.pasteFromUrl'),
url: httpsUrl,
copied: copied === 'https',
onCopy: () => void copy(httpsUrl, 'https'),
},
{
label: 'Apple Calendar / Outlook',
hint: 'webcal://',
url: webcalUrl,
copied: copied === 'webcal',
onCopy: () => void copy(webcalUrl, 'webcal'),
},
];
return { googleUrl, manualLinks };
}