mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 09:54:14 +00:00
fix(mobile): harden back gestures and repair CI regressions
Reflect the drag position in the sheet scrim and match back gestures to the reading direction. Keep Escape on the top overlay and update failing tests for the redesigned forms, navigation, and offline preparation. Remove dead exports and lower obsolete lint counts.
This commit is contained in:
@@ -440,9 +440,9 @@ describe('DawarichAcceptDialog', () => {
|
||||
phone.value = true
|
||||
const { onConfirm } = open({ trips: TRIPS, daysForTrip })
|
||||
|
||||
expect(screen.getByRole('dialog', { name: 'Add this stay as a place' })).toBeInTheDocument()
|
||||
// The desktop modal's own heading is the tell that the wrong shell rendered.
|
||||
expect(screen.queryByRole('heading', { name: 'Add this stay as a place' })).toBeNull()
|
||||
const sheet = screen.getByRole('dialog', { name: 'Add this stay as a place' })
|
||||
expect(sheet).toHaveAttribute('data-m-sheet', 'open')
|
||||
expect(screen.getByRole('heading', { name: 'Add this stay as a place' })).toBeInTheDocument()
|
||||
|
||||
fireEvent.change(screen.getByLabelText('Name'), { target: { value: 'Reichard' } })
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Add place' }))
|
||||
|
||||
@@ -52,7 +52,7 @@ export default function ContributorInviteDialog({ journeyId, existingUserIds, on
|
||||
const toast = useToast()
|
||||
|
||||
useEffect(() => {
|
||||
authApi.listUsers().then(d => setUsers(d.users || [])).catch(() => {}).finally(() => setLoading(false))
|
||||
authApi.listUsers().then(d => setUsers(d.users || [])).catch(() => setUsers([])).finally(() => setLoading(false))
|
||||
}, [])
|
||||
|
||||
// Captured and stopped on the desktop: the dialog is usually opened from the
|
||||
|
||||
@@ -28,9 +28,9 @@ describe('splitMobileNav', () => {
|
||||
it('docks the top two enabled defaults when there is no config', () => {
|
||||
for (const cfg of [undefined, { bar: [], more: [] }]) {
|
||||
const s = splitMobileNav(items, cfg)
|
||||
expect(ids(s.bar)).toEqual(['dashboard', 'vacay', 'journey'])
|
||||
expect(ids(s.bar)).toEqual(['dashboard', 'collections', 'journey'])
|
||||
// Atlas is still reachable, one tap further under More.
|
||||
expect(ids(s.more)).toEqual(['atlas', 'collections'])
|
||||
expect(ids(s.more)).toEqual(['vacay', 'atlas'])
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ describe('BookingImportModal', () => {
|
||||
const upload = vi.fn(() => HttpResponse.json({ jobId: 'mobile-pdf' }));
|
||||
server.use(http.post('/api/trips/4/reservations/import/booking/async', upload));
|
||||
render(<MBookingImportSheet {...defaultProps} kind="bookings" onClose={onClose} />);
|
||||
expect(screen.getByRole('dialog', { name: 'Import booking confirmations' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('dialog', { name: 'Import from file' })).toBeInTheDocument();
|
||||
await userEvent.upload(fileInput(), [pdf, eml()]);
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Remove: booking.eml' }));
|
||||
const submit = screen.getByRole('button', { name: 'Import' });
|
||||
|
||||
@@ -38,8 +38,8 @@ describe('useMobileNavEditor', () => {
|
||||
it('FE-COMP-NAVEDITOR-001: an empty value falls back to the built-in dock split', () => {
|
||||
const { result } = setup({ bar: [], more: [] });
|
||||
|
||||
expect(ids(result.current.barItems)).toEqual(['vacay', 'journey']);
|
||||
expect(ids(result.current.moreItems)).toEqual(['atlas', 'collections']);
|
||||
expect(ids(result.current.barItems)).toEqual(['collections', 'journey']);
|
||||
expect(ids(result.current.moreItems)).toEqual(['vacay', 'atlas']);
|
||||
expect(result.current.hasMore).toBe(true);
|
||||
expect(result.current.barFull).toBe(true);
|
||||
});
|
||||
|
||||
@@ -57,9 +57,9 @@ export function useOverlay(open: boolean, close: Close, dismissOnEscape = false)
|
||||
event.stopPropagation();
|
||||
entry.close();
|
||||
};
|
||||
if (dismissOnEscape) document.addEventListener('keydown', onKey, true);
|
||||
if (dismissOnEscape) window.addEventListener('keydown', onKey, true);
|
||||
return () => {
|
||||
if (dismissOnEscape) document.removeEventListener('keydown', onKey, true);
|
||||
if (dismissOnEscape) window.removeEventListener('keydown', onKey, true);
|
||||
const i = stack.findIndex((e) => e.id === entry.id);
|
||||
if (i >= 0) stack.splice(i, 1);
|
||||
entryId.current = null;
|
||||
|
||||
@@ -33,11 +33,40 @@ beforeEach(() => {
|
||||
Object.defineProperty(window, 'innerWidth', { configurable: true, value: 400 });
|
||||
});
|
||||
afterEach(() => {
|
||||
document.documentElement.removeAttribute('dir');
|
||||
vi.useRealTimers();
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('MEdgeBack', () => {
|
||||
it('mirrors the swipe from the right edge in a right-to-left interface', () => {
|
||||
document.documentElement.dir = 'rtl';
|
||||
const back = vi.spyOn(window.history, 'back').mockImplementation(() => {});
|
||||
const { getByTestId } = render(<Host />);
|
||||
|
||||
touch('touchstart', 395, 300, 0);
|
||||
touch('touchmove', 220, 300, 100);
|
||||
expect(getByTestId('page').style.transform).toBe('translateX(-175px)');
|
||||
|
||||
touch('touchend', 220, 300, 150);
|
||||
vi.advanceTimersByTime(280);
|
||||
expect(back).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('drops a scheduled back navigation if the history changes first', () => {
|
||||
const back = vi.spyOn(window.history, 'back').mockImplementation(() => {});
|
||||
const { getByTestId } = render(<Host />);
|
||||
|
||||
touch('touchstart', 5, 300, 0);
|
||||
touch('touchmove', 200, 300, 100);
|
||||
touch('touchend', 200, 300, 150);
|
||||
window.dispatchEvent(new PopStateEvent('popstate'));
|
||||
vi.advanceTimersByTime(280);
|
||||
|
||||
expect(getByTestId('page').style.transform).toBe('');
|
||||
expect(back).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('drags the page with a finger from the left edge, and goes back past a third', () => {
|
||||
const back = vi.spyOn(window.history, 'back').mockImplementation(() => {});
|
||||
const { getByTestId } = render(<Host />);
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
import { skipNextRouteTransition } from '../routeTransition';
|
||||
|
||||
/**
|
||||
* The swipe from the left edge that goes back, the way every iOS app has it.
|
||||
* The swipe from the leading edge that goes back on iOS.
|
||||
*
|
||||
* WebKit's own version slides away a screenshot of the whole page, closes no
|
||||
* sheet and fights every gesture near the edge (the day pager, swipe rows), so
|
||||
@@ -23,7 +23,7 @@ import { skipNextRouteTransition } from '../routeTransition';
|
||||
* the `edgeBack` feature, so an older binary keeps WebKit's.
|
||||
*/
|
||||
|
||||
/** A touch has to start this close to the left edge. */
|
||||
/** A touch has to start this close to the leading edge. */
|
||||
const EDGE_PX = 22;
|
||||
/** Sideways must clearly beat vertical before the gesture is claimed. */
|
||||
const CLAIM_PX = 10;
|
||||
@@ -45,6 +45,8 @@ export default function MEdgeBack({ target, enabled }: { target: RefObject<HTMLE
|
||||
let overlay = false;
|
||||
let samples: MotionSample[] = [];
|
||||
let grabOffset = 0;
|
||||
let direction = 1;
|
||||
let reducedMotion = false;
|
||||
let navigationTimer: number | undefined;
|
||||
let frame = 0;
|
||||
|
||||
@@ -53,7 +55,7 @@ export default function MEdgeBack({ target, enabled }: { target: RefObject<HTMLE
|
||||
if (!el) return;
|
||||
el.style.transition = transition;
|
||||
el.style.transform = x ? `translateX(${x}px)` : '';
|
||||
el.style.boxShadow = x ? '-16px 0 40px -12px rgba(0,0,0,.35)' : '';
|
||||
el.style.boxShadow = x ? `${-16 * Math.sign(x)}px 0 40px -12px rgba(0,0,0,.35)` : '';
|
||||
};
|
||||
const settle = () => move(0, 'transform 260ms var(--ease-drawer), box-shadow 260ms');
|
||||
|
||||
@@ -64,14 +66,24 @@ export default function MEdgeBack({ target, enabled }: { target: RefObject<HTMLE
|
||||
grabOffset = 0;
|
||||
};
|
||||
|
||||
const resetNavigation = () => {
|
||||
window.clearTimeout(navigationTimer);
|
||||
navigationTimer = undefined;
|
||||
onCancel();
|
||||
move(0, 'none');
|
||||
};
|
||||
|
||||
const onStart = (e: TouchEvent) => {
|
||||
onCancel();
|
||||
if (e.touches.length !== 1) return;
|
||||
const t = e.touches[0];
|
||||
if (t.clientX > EDGE_PX) return;
|
||||
if (navigationTimer !== undefined) return;
|
||||
direction = document.documentElement.dir === 'rtl' ? -1 : 1;
|
||||
const edgeDistance = direction === 1 ? t.clientX : window.innerWidth - t.clientX;
|
||||
if (edgeDistance > EDGE_PX) return;
|
||||
overlay = hasOpenOverlay();
|
||||
if (!overlay && !canGoBack()) return;
|
||||
reducedMotion = isMotionReduced();
|
||||
start = { x: t.clientX, y: t.clientY };
|
||||
samples = [{ position: t.clientX, time: e.timeStamp }];
|
||||
};
|
||||
@@ -79,7 +91,7 @@ export default function MEdgeBack({ target, enabled }: { target: RefObject<HTMLE
|
||||
const onMove = (e: TouchEvent) => {
|
||||
if (!start || e.touches.length !== 1) return;
|
||||
const t = e.touches[0];
|
||||
const dx = t.clientX - start.x;
|
||||
const dx = direction * (t.clientX - start.x);
|
||||
const dy = t.clientY - start.y;
|
||||
if (!claimed) {
|
||||
if (Math.abs(dy) > CLAIM_PX && Math.abs(dy) > Math.abs(dx)) {
|
||||
@@ -88,12 +100,12 @@ export default function MEdgeBack({ target, enabled }: { target: RefObject<HTMLE
|
||||
}
|
||||
if (dx < CLAIM_PX || dx < Math.abs(dy) * AXIS_BIAS) return;
|
||||
claimed = true;
|
||||
if (!overlay) grabOffset = currentTranslation(target.current, 'x');
|
||||
if (!overlay) grabOffset = direction * currentTranslation(target.current, 'x');
|
||||
}
|
||||
if (e.cancelable) e.preventDefault();
|
||||
sampleMotion(samples, t.clientX, e.timeStamp);
|
||||
// An open sheet closes on release; the page itself stays put under it.
|
||||
if (!overlay && !isMotionReduced()) move(Math.max(0, grabOffset + dx), 'none');
|
||||
if (!overlay && !reducedMotion) move(direction * Math.max(0, grabOffset + dx), 'none');
|
||||
};
|
||||
|
||||
const onEnd = (e: TouchEvent) => {
|
||||
@@ -102,8 +114,8 @@ export default function MEdgeBack({ target, enabled }: { target: RefObject<HTMLE
|
||||
if (!s || !claimed) return;
|
||||
claimed = false;
|
||||
const x = e.changedTouches[0]?.clientX ?? samples[samples.length - 1].position;
|
||||
const dx = Math.max(0, grabOffset + x - s.x);
|
||||
const v = releaseVelocity(samples, x, e.timeStamp);
|
||||
const dx = Math.max(0, grabOffset + direction * (x - s.x));
|
||||
const v = direction * releaseVelocity(samples, x, e.timeStamp);
|
||||
const width = window.innerWidth;
|
||||
const commit = dx > 0 && (dx > width * COMMIT_SHARE || v > FLICK_V);
|
||||
if (!commit) {
|
||||
@@ -115,14 +127,14 @@ export default function MEdgeBack({ target, enabled }: { target: RefObject<HTMLE
|
||||
closeTopOverlay();
|
||||
return;
|
||||
}
|
||||
if (isMotionReduced()) {
|
||||
if (reducedMotion) {
|
||||
skipNextRouteTransition();
|
||||
window.history.back();
|
||||
move(0, 'none');
|
||||
return;
|
||||
}
|
||||
const duration = Math.round(Math.min(240, Math.max(120, (width - dx) / Math.max(v, 1.2))));
|
||||
move(width, `transform ${duration}ms cubic-bezier(0.2, 0.8, 0.2, 1)`);
|
||||
move(direction * width, `transform ${duration}ms cubic-bezier(0.2, 0.8, 0.2, 1)`);
|
||||
navigationTimer = window.setTimeout(() => {
|
||||
navigationTimer = undefined;
|
||||
skipNextRouteTransition();
|
||||
@@ -136,11 +148,13 @@ export default function MEdgeBack({ target, enabled }: { target: RefObject<HTMLE
|
||||
document.addEventListener('touchmove', onMove, { passive: false });
|
||||
document.addEventListener('touchend', onEnd, { passive: true });
|
||||
document.addEventListener('touchcancel', onCancel, { passive: true });
|
||||
window.addEventListener('popstate', resetNavigation);
|
||||
return () => {
|
||||
document.removeEventListener('touchstart', onStart);
|
||||
document.removeEventListener('touchmove', onMove);
|
||||
document.removeEventListener('touchend', onEnd);
|
||||
document.removeEventListener('touchcancel', onCancel);
|
||||
window.removeEventListener('popstate', resetNavigation);
|
||||
window.clearTimeout(navigationTimer);
|
||||
cancelAnimationFrame(frame);
|
||||
move(0, 'none');
|
||||
|
||||
@@ -215,9 +215,11 @@ export default function MSheet({
|
||||
// exit animation (which starts from the rest position) must not play.
|
||||
const [flung, setFlung] = useState(false)
|
||||
const panelRef = useRef<HTMLDivElement>(null)
|
||||
const scrimRef = useRef<HTMLDivElement>(null)
|
||||
const sheetDrag = useSheetDrag({
|
||||
enabled: variant === 'bottom' && open && rendered,
|
||||
panelRef,
|
||||
scrimRef,
|
||||
onDismiss: () => {
|
||||
if (wouldAsk()) {
|
||||
requestClose()
|
||||
@@ -240,6 +242,11 @@ export default function MSheet({
|
||||
panel.style.transform = ''
|
||||
panel.style.transition = ''
|
||||
}
|
||||
const scrim = scrimRef.current
|
||||
if (scrim) {
|
||||
scrim.style.opacity = ''
|
||||
scrim.style.transition = ''
|
||||
}
|
||||
return
|
||||
}
|
||||
setEntered(false)
|
||||
@@ -256,6 +263,9 @@ export default function MSheet({
|
||||
if (!open || covered) return
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key !== 'Escape' || e.defaultPrevented || !isTop()) return
|
||||
const openPanels = document.querySelectorAll('[data-m-sheet="open"]')
|
||||
if (openPanels[openPanels.length - 1] !== panelRef.current) return
|
||||
e.preventDefault()
|
||||
if (asking) keepEditing()
|
||||
else requestClose()
|
||||
}
|
||||
@@ -293,11 +303,12 @@ export default function MSheet({
|
||||
if (e.target === e.currentTarget) requestClose()
|
||||
}}
|
||||
>
|
||||
<div
|
||||
aria-hidden="true"
|
||||
data-m-scrim=""
|
||||
className={`pointer-events-none absolute inset-0 ${dimTransparent ? 'bg-transparent short:bg-[color:var(--m-dim)]' : 'bg-[color:var(--m-dim)]'} ${open ? 'm-fade-in' : 'm-fade-out'}`}
|
||||
/>
|
||||
<div ref={scrimRef} aria-hidden="true" className="pointer-events-none absolute inset-0">
|
||||
<div
|
||||
data-m-scrim=""
|
||||
className={`absolute inset-0 ${dimTransparent ? 'bg-transparent short:bg-[color:var(--m-dim)]' : 'bg-[color:var(--m-dim)]'} ${open ? 'm-fade-in' : 'm-fade-out'}`}
|
||||
/>
|
||||
</div>
|
||||
<div className={regionClass(variant, wideAnchor, form)}>
|
||||
<div className={boxClass(variant, wideWidth, form)}>
|
||||
<PopoverArrow variant={variant} anchor={wideAnchor} />
|
||||
|
||||
@@ -68,12 +68,13 @@ function offsetFor(dy: number): number {
|
||||
export interface SheetDragOptions {
|
||||
enabled: boolean;
|
||||
panelRef: RefObject<HTMLElement | null>;
|
||||
scrimRef: RefObject<HTMLElement | null>;
|
||||
/** Called on a dismissing release. Returns true when the sheet will close, so
|
||||
* it can be thrown off screen; false (an unsaved-changes question) springs it back. */
|
||||
onDismiss: () => boolean;
|
||||
}
|
||||
|
||||
export function useSheetDrag({ enabled, panelRef, onDismiss }: SheetDragOptions) {
|
||||
export function useSheetDrag({ enabled, panelRef, scrimRef, onDismiss }: SheetDragOptions) {
|
||||
const drag = useRef<Drag | null>(null);
|
||||
const frame = useRef(0);
|
||||
const latest = useRef(onDismiss);
|
||||
@@ -85,10 +86,16 @@ export function useSheetDrag({ enabled, panelRef, onDismiss }: SheetDragOptions)
|
||||
(y: number, transition: string) => {
|
||||
const el = panelRef.current;
|
||||
if (!el) return;
|
||||
const scrim = scrimRef.current;
|
||||
const travel = el.offsetHeight;
|
||||
el.style.transition = transition;
|
||||
el.style.transform = `translateY(${y}px)`;
|
||||
if (scrim && travel > 0) {
|
||||
scrim.style.transition = transition.replace('transform ', 'opacity ');
|
||||
scrim.style.opacity = String(1 - Math.min(1, Math.max(0, y / travel)));
|
||||
}
|
||||
},
|
||||
[panelRef]
|
||||
[panelRef, scrimRef]
|
||||
);
|
||||
|
||||
const cancelDrag = useCallback(() => {
|
||||
|
||||
@@ -4,7 +4,8 @@ import { STATUS_ORDER } from '../../../pages/collections/collectionsModel'
|
||||
import MSheet from '../../components/MSheet'
|
||||
import MCollPlaceFields, { MCollPlaceDescription } from './MCollPlaceFields'
|
||||
import { STATUS_SPEC } from './collectionsMobileModel'
|
||||
import { AMOUNT_FIELD_CLS, Eyebrow, FormSheetBody, FormSheetFooter, FormSheetHeader, FormSheetSection, formOptionClass, SELECT_FIELD_CLS } from '../trip/sheets/PlSheetChrome'
|
||||
import { AMOUNT_FIELD_CLS, Eyebrow, FormSheetBody, FormSheetFooter, FormSheetHeader, FormSheetSection, SELECT_FIELD_CLS } from '../trip/sheets/PlSheetChrome'
|
||||
import { formOptionClass } from '../trip/sheets/formOptionClass'
|
||||
import { str } from '../../../components/Collections/addPlaceModel'
|
||||
import { useAddPlaceToCollection } from '../../../components/Collections/useAddPlaceToCollection'
|
||||
|
||||
|
||||
@@ -12,15 +12,6 @@ type Group = 'status' | 'category' | 'tags' | 'rating' | 'sort';
|
||||
const SORT_LABELS = { default: 'collections.sort.default', name_asc: 'collections.sort.nameAsc' } as const;
|
||||
const RATING_FLOORS = ['all', 5, 4, 3, 2, 1] as const;
|
||||
|
||||
export function savedListFilterCount(c: Collections) {
|
||||
return [
|
||||
c.statusFilter !== 'all',
|
||||
c.categoryFilter !== 'all',
|
||||
!c.isAllSaved && c.labelFilter.length > 0,
|
||||
c.ratingFilter !== 'all',
|
||||
].filter(Boolean).length;
|
||||
}
|
||||
|
||||
export default function MCollSavedFilters({
|
||||
c,
|
||||
open,
|
||||
|
||||
@@ -5,7 +5,8 @@ import type { TranslationFn } from '../../../types'
|
||||
import { avatarSrc } from '../../../utils/avatarSrc'
|
||||
import MIconBtn from '../../components/MIconBtn'
|
||||
import MSheet from '../../components/MSheet'
|
||||
import { FIELD_CLS, FormSheetBody, FormSheetFooter, FormSheetHeader, FormSheetSection, formOptionClass, SELECT_FIELD_CLS } from '../trip/sheets/PlSheetChrome'
|
||||
import { FIELD_CLS, FormSheetBody, FormSheetFooter, FormSheetHeader, FormSheetSection, SELECT_FIELD_CLS } from '../trip/sheets/PlSheetChrome'
|
||||
import { formOptionClass } from '../trip/sheets/formOptionClass'
|
||||
import { CancelPill, PrimaryPill } from './MCollSheetKit'
|
||||
|
||||
interface MCollShareSheetProps {
|
||||
|
||||
@@ -25,9 +25,8 @@ import {
|
||||
FormSheetBody,
|
||||
FormSheetFooter,
|
||||
FormSheetHeader,
|
||||
FormSheetSection,
|
||||
formOptionClass,
|
||||
} from '../trip/sheets/PlSheetChrome';
|
||||
FormSheetSection } from '../trip/sheets/PlSheetChrome';
|
||||
import { formOptionClass } from '../trip/sheets/formOptionClass';
|
||||
|
||||
/** A kept tour's measures as the small pills of the phone's rows. */
|
||||
function MeasurePills({ tour }: { tour: CollectionTourItem }) {
|
||||
|
||||
@@ -22,7 +22,8 @@ import MConfirmSheet from '../settings/MConfirmSheet'
|
||||
import MCollListNav from './MCollListNav'
|
||||
import MPlacesLibrary from './MPlacesLibrary'
|
||||
import MCollToolbar from './MCollToolbar'
|
||||
import MCollSavedFilters, { savedListFilterCount } from './MCollSavedFilters'
|
||||
import MCollSavedFilters from './MCollSavedFilters'
|
||||
import { savedListFilterCount } from './savedListFilterCount'
|
||||
import { EmptyNote } from './MCollFilterKit'
|
||||
import { usePlaceReorder } from '../../../components/Collections/usePlaceReorder'
|
||||
import { useIsSplit } from '../../../hooks/sizeClass'
|
||||
|
||||
@@ -76,9 +76,3 @@ export function tint(hex: string, alpha: string): string {
|
||||
|
||||
/** Swatch palette for list colours and labels. */
|
||||
export const SWATCH_COLORS = ['#6366F1', '#38BDF8', '#2FA37A', '#F59E0B', '#EF4444', '#EC4899', '#8B5CF6', '#64748B']
|
||||
|
||||
/** Cover fallback per list: a gradient built from the list colour. */
|
||||
export function listCoverGradient(color: string | null | undefined): string {
|
||||
const c = color || '#6366F1'
|
||||
return `linear-gradient(115deg, ${c}, ${c}66)`
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import type { useCollections } from '../../../pages/collections/useCollections';
|
||||
|
||||
export function savedListFilterCount(c: ReturnType<typeof useCollections>) {
|
||||
return [
|
||||
c.statusFilter !== 'all',
|
||||
c.categoryFilter !== 'all',
|
||||
!c.isAllSaved && c.labelFilter.length > 0,
|
||||
c.ratingFilter !== 'all',
|
||||
].filter(Boolean).length;
|
||||
}
|
||||
@@ -6,7 +6,8 @@ import MSheet from '../../components/MSheet'
|
||||
import MIconBtn from '../../components/MIconBtn'
|
||||
import MToggle from '../../components/MToggle'
|
||||
import { SHEET_PRIMARY, SHEET_SECONDARY } from '../trip/sheets/MTripSheetUi'
|
||||
import { AMOUNT_FIELD_CLS, FIELD_AREA_CLS, FIELD_CLS, FORM_LABEL_CLS, FormSheetBody, FormSheetFooter, FormSheetHeader, FormSheetSection, SELECT_FIELD_CLS, SheetDateField, formOptionClass } from '../trip/sheets/PlSheetChrome'
|
||||
import { AMOUNT_FIELD_CLS, FIELD_AREA_CLS, FIELD_CLS, FORM_LABEL_CLS, FormSheetBody, FormSheetFooter, FormSheetHeader, FormSheetSection, SELECT_FIELD_CLS, SheetDateField } from '../trip/sheets/PlSheetChrome'
|
||||
import { formOptionClass } from '../trip/sheets/formOptionClass'
|
||||
import { useAutoGrow } from '../../../hooks/useAutoGrow'
|
||||
import { useTranslation } from '../../../i18n'
|
||||
import CustomTimePicker from '../../../components/shared/CustomTimePicker'
|
||||
|
||||
@@ -9,9 +9,8 @@ import {
|
||||
FormSheetBody,
|
||||
FormSheetFooter,
|
||||
FormSheetHeader,
|
||||
FormSheetSection,
|
||||
formOptionClass,
|
||||
} from '../trip/sheets/PlSheetChrome';
|
||||
FormSheetSection } from '../trip/sheets/PlSheetChrome';
|
||||
import { formOptionClass } from '../trip/sheets/formOptionClass';
|
||||
|
||||
export default function MJourneyInviteFrame({
|
||||
users,
|
||||
|
||||
@@ -100,7 +100,7 @@ export function MCategoryFilterList({ categories, places }: { categories: Catego
|
||||
* (#1435). `onPick` runs after a floor is chosen: the places browser drops its
|
||||
* selection then, as it does for a new pool.
|
||||
*/
|
||||
export function MRatingFloorChips({ onPick }: { onPick?: () => void } = {}) {
|
||||
function MRatingFloorChips({ onPick }: { onPick?: () => void } = {}) {
|
||||
const { t } = useTranslation()
|
||||
const ratingFilter = useTripStore(s => s.placesRatingFilter)
|
||||
const setRatingFilter = useTripStore(s => s.setPlacesRatingFilter)
|
||||
|
||||
@@ -46,7 +46,7 @@ export function seatStageBookings(
|
||||
if (anchor == null) continue;
|
||||
for (const booking of bookings) {
|
||||
const time = clockOf(booking);
|
||||
let seat = anchor;
|
||||
let seat: number = anchor;
|
||||
if (time != null) {
|
||||
const lower = clocks.reduce((last, clock) => (clock.time <= time ? clock.index : last), -1);
|
||||
const upper = clocks.find((clock) => clock.index > lower && clock.time > time)?.index ?? rows.length;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import MToggle from '../../../components/MToggle'
|
||||
import { formOptionClass, FIELD_CLS, FORM_LABEL_CLS, FormSheetBody, FormSheetFooter, FormSheetSection } from './PlSheetChrome'
|
||||
import { FIELD_CLS, FORM_LABEL_CLS, FormSheetBody, FormSheetFooter, FormSheetSection } from './PlSheetChrome'
|
||||
import { formOptionClass } from './formOptionClass'
|
||||
import type { TripPlanner } from '../MTripShell'
|
||||
import { useListImport } from '../../../../components/Planner/useListImport'
|
||||
|
||||
|
||||
@@ -18,9 +18,6 @@ export function Eyebrow({ children, className = '' }: { children: ReactNode; cla
|
||||
)
|
||||
}
|
||||
|
||||
/** A text field of the sheets: 42 px, round, on the icon surface. */
|
||||
export const SHEET_FIELD =
|
||||
'h-[42px] min-w-0 flex-1 rounded-full border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)] px-[14px] text-[length:calc(13px*var(--fs-scale-body,1))] font-medium text-m-ink outline-none placeholder:text-m-faint'
|
||||
/** The filled action with a label. Never icon-only: its padding leaves an icon no room in a circle, use SHEET_ROUND_PRIMARY. */
|
||||
export const SHEET_PRIMARY =
|
||||
'flex h-[42px] flex-none items-center gap-1.5 rounded-full bg-m-act px-4 text-[length:calc(13px*var(--fs-scale-body,1))] font-semibold text-m-actfg disabled:opacity-40'
|
||||
@@ -40,42 +37,6 @@ export const SHEET_ROUND =
|
||||
export const SHEET_PILL =
|
||||
'flex h-[22px] flex-none items-center gap-[3px] rounded-full px-[8px] font-geist text-[length:calc(9.5px*var(--fs-scale-caption,1))] font-bold uppercase tracking-[.06em]'
|
||||
|
||||
/** A titled block of the sheet: the eyebrow, an optional line under it and the content on the inner surface. */
|
||||
export function SheetSection({
|
||||
title,
|
||||
count,
|
||||
hint,
|
||||
children,
|
||||
}: {
|
||||
/** Left out where each field below carries its own label. */
|
||||
title?: string
|
||||
/** How many there are, as a small badge next to the title rather than glued onto it. */
|
||||
count?: number
|
||||
hint?: string
|
||||
children: ReactNode
|
||||
}) {
|
||||
return (
|
||||
<section className={`rounded-[18px] p-3 ${INNER_CLS}`}>
|
||||
{title && (
|
||||
<div className="flex items-center gap-1.5">
|
||||
<Eyebrow className="uppercase">{title}</Eyebrow>
|
||||
{count != null && (
|
||||
<span className="flex h-[16px] min-w-[16px] items-center justify-center rounded-full bg-[color:var(--m-ic)] px-[5px] font-geist text-[length:calc(9.5px*var(--fs-scale-caption,1))] font-bold text-m-muted">
|
||||
{count}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{hint && (
|
||||
<p className="mt-1 font-geist text-[length:calc(11px*var(--fs-scale-caption,1))] leading-snug text-m-muted">
|
||||
{hint}
|
||||
</p>
|
||||
)}
|
||||
<div className={`${title || hint ? 'mt-2.5 ' : ''}flex flex-col gap-2`}>{children}</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
interface TileHeaderProps {
|
||||
/** Left out for a plain picker; every other sheet shows its icon tile. */
|
||||
icon?: ReactNode
|
||||
|
||||
@@ -19,12 +19,6 @@ const FIELD_FOCUS = 'outline-none focus-visible:ring-1 focus-visible:ring-m-act'
|
||||
|
||||
export const FORM_LABEL_CLS = 'm-form-label text-control font-medium text-m-ink'
|
||||
|
||||
export function formOptionClass(active: boolean) {
|
||||
return `flex min-h-10 items-center gap-1.5 rounded-full border px-3 py-1.5 text-start text-caption font-semibold ${
|
||||
active ? 'border-transparent bg-m-act text-m-actfg' : 'border-m-rowbr bg-m-sheetop text-m-ink'
|
||||
}`
|
||||
}
|
||||
|
||||
export const FIELD_CLS =
|
||||
`${FIELD_SURFACE} ${FIELD_FOCUS} box-border min-h-11 w-full px-3 py-2 placeholder:text-m-muted`
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
export function formOptionClass(active: boolean) {
|
||||
return `flex min-h-10 items-center gap-1.5 rounded-full border px-3 py-1.5 text-start text-caption font-semibold ${
|
||||
active ? 'border-transparent bg-m-act text-m-actfg' : 'border-m-rowbr bg-m-sheetop text-m-ink'
|
||||
}`
|
||||
}
|
||||
@@ -5,7 +5,8 @@ import { RES_ICONS } from '../../../../components/Planner/DayPlanSidebar.constan
|
||||
import { formatTime, formatPriceText } from '../../../../utils/formatters'
|
||||
import { useTranslation } from '../../../../i18n'
|
||||
import type { Reservation } from '../../../../types'
|
||||
import { CardActions, CardDeleteSheet, CardFiles, CardNotes, CardTitleButton, CardTypeMarker, CardWhenAndCode, RESERVATION_CARD_SURFACE, reservationHeaderTint } from './MReservationCardParts'
|
||||
import { CardActions, CardDeleteSheet, CardFiles, CardNotes, CardTitleButton, CardTypeMarker, CardWhenAndCode, RESERVATION_CARD_SURFACE } from './MReservationCardParts'
|
||||
import { reservationHeaderTint } from './reservationHeaderTint'
|
||||
import { Field, ReservationPluginSlots, RESERVATION_FIELD_LABEL, RESERVATION_FIELD_SURFACE, TravelerAvatars } from './tabChrome'
|
||||
import { STATUS_COLOR, type MTabScreenProps } from './tabModel'
|
||||
import { cardWhen, parseTransportMeta, timeRange } from './transportsModel'
|
||||
|
||||
@@ -14,7 +14,8 @@ import { announceNoteFilesChanged, useCollabNotesData } from '../../../../compon
|
||||
import { openFile } from '../../../../utils/fileDownload'
|
||||
import { safeExternalHref } from '../../../../utils/safeUrl'
|
||||
import MSheet from '../../../components/MSheet'
|
||||
import { AddFieldButton, Eyebrow, FIELD_AREA_CLS, FIELD_CLS, FORM_LABEL_CLS, FormSheetBody, FormSheetFooter, FormSheetHeader, FormSheetSection, formOptionClass } from '../sheets/PlSheetChrome'
|
||||
import { AddFieldButton, Eyebrow, FIELD_AREA_CLS, FIELD_CLS, FORM_LABEL_CLS, FormSheetBody, FormSheetFooter, FormSheetHeader, FormSheetSection } from '../sheets/PlSheetChrome'
|
||||
import { formOptionClass } from '../sheets/formOptionClass'
|
||||
import MConfirmSheet from '../../settings/MConfirmSheet'
|
||||
import type { TripPlanner } from '../MTripShell'
|
||||
import { PrimaryPill } from '../MTripShellParts'
|
||||
|
||||
@@ -7,7 +7,8 @@ import MDancingTrek from '../../../components/MDancingTrek'
|
||||
import MIconBtn from '../../../components/MIconBtn'
|
||||
import MSheet from '../../../components/MSheet'
|
||||
import CustomSelect from '../../../../components/shared/CustomSelect'
|
||||
import { FormSheetBody, FormSheetFooter, FormSheetHeader, FormSheetSection, formOptionClass } from '../sheets/PlSheetChrome'
|
||||
import { FormSheetBody, FormSheetFooter, FormSheetHeader, FormSheetSection } from '../sheets/PlSheetChrome'
|
||||
import { formOptionClass } from '../sheets/formOptionClass'
|
||||
import { useIsSplit } from '../../../../hooks/sizeClass'
|
||||
import { useTranslation } from '../../../../i18n'
|
||||
import { formatMoney } from '../../../../utils/formatters'
|
||||
|
||||
@@ -25,10 +25,6 @@ type CardState = ReturnType<typeof useReservationCard>;
|
||||
export const RESERVATION_CARD_SURFACE =
|
||||
'mt-2 overflow-hidden rounded-2xl border border-m-rowbr bg-m-sheetop [--m-reservation-field:var(--m-ic)] [--m-reservation-field-border:transparent]';
|
||||
|
||||
export function reservationHeaderTint(color: string) {
|
||||
return `color-mix(in srgb, ${color} 8%, var(--m-sheetop))`;
|
||||
}
|
||||
|
||||
export function CardTypeMarker({ icon: Icon, color }: { icon: LucideIcon; color: string }) {
|
||||
return (
|
||||
<span className="grid size-9 shrink-0 place-items-center rounded-full bg-m-sheetop" style={{ color }} aria-hidden>
|
||||
|
||||
@@ -3,7 +3,8 @@ import { RES_ICONS } from '../../../../components/Planner/DayPlanSidebar.constan
|
||||
import { formatPriceText } from '../../../../utils/formatters'
|
||||
import { useTranslation } from '../../../../i18n'
|
||||
import type { Reservation } from '../../../../types'
|
||||
import { CardActions, CardDeleteSheet, CardFiles, CardNotes, CardTitleButton, CardTypeMarker, CardWhenAndCode, RESERVATION_CARD_SURFACE, reservationHeaderTint } from './MReservationCardParts'
|
||||
import { CardActions, CardDeleteSheet, CardFiles, CardNotes, CardTitleButton, CardTypeMarker, CardWhenAndCode, RESERVATION_CARD_SURFACE } from './MReservationCardParts'
|
||||
import { reservationHeaderTint } from './reservationHeaderTint'
|
||||
import { Field, ReservationPluginSlots, RESERVATION_FIELD_LABEL, RESERVATION_FIELD_SURFACE, TravelerAvatars } from './tabChrome'
|
||||
import { STATUS_COLOR, type MTabScreenProps } from './tabModel'
|
||||
import { cardWhen, parseTransportMeta } from './transportsModel'
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export function reservationHeaderTint(color: string) {
|
||||
return `color-mix(in srgb, ${color} 8%, var(--m-sheetop))`;
|
||||
}
|
||||
@@ -6,8 +6,8 @@ import { type VacayUser } from '../../../types'
|
||||
import MSheet from '../../components/MSheet'
|
||||
import { MUserPickerField } from '../../components/MUserPickerList'
|
||||
import {
|
||||
FormSheetBody, FormSheetFooter, FormSheetHeader, FormSheetSection, SELECT_FIELD_CLS, formOptionClass,
|
||||
} from '../trip/sheets/PlSheetChrome'
|
||||
FormSheetBody, FormSheetFooter, FormSheetHeader, FormSheetSection, SELECT_FIELD_CLS } from '../trip/sheets/PlSheetChrome'
|
||||
import { formOptionClass } from '../trip/sheets/formOptionClass'
|
||||
|
||||
interface MVacayInviteSheetProps {
|
||||
open: boolean
|
||||
|
||||
@@ -4,6 +4,7 @@ import MSheet from '../../components/MSheet'
|
||||
import MIconBtn from '../../components/MIconBtn'
|
||||
import MToggle from '../../components/MToggle'
|
||||
import ConfirmDialog from '../../../components/shared/ConfirmDialog'
|
||||
import { useShallow } from 'zustand/react/shallow'
|
||||
import { useVacayStore } from '../../../store/vacayStore'
|
||||
import { useTranslation } from '../../../i18n'
|
||||
import { useSchoolHolidayCountries } from '../../../components/Vacay/useSchoolHolidayCountries'
|
||||
@@ -14,8 +15,8 @@ import { FALLBACK_PERSON_COLOR } from './vacayDayModel'
|
||||
import type { VacayHolidayCalendar } from '../../../types'
|
||||
import {
|
||||
AddFieldButton, FIELD_CLS, FormSheetBody, FormSheetHeader, FormSheetSection,
|
||||
SELECT_FIELD_CLS, SheetDateField, formOptionClass,
|
||||
} from '../trip/sheets/PlSheetChrome'
|
||||
SELECT_FIELD_CLS, SheetDateField } from '../trip/sheets/PlSheetChrome'
|
||||
import { formOptionClass } from '../trip/sheets/formOptionClass'
|
||||
|
||||
const CALENDAR_COLORS = ['#fecaca', '#fed7aa', '#fde68a', '#bbf7d0', '#a5f3fc', '#c7d2fe', '#e9d5ff', '#fda4af']
|
||||
const HINT = 'text-caption leading-snug text-m-muted'
|
||||
@@ -41,7 +42,9 @@ function ToggleRow({ label, hint, checked, onChange }: {
|
||||
|
||||
export default function MVacaySettingsSheet({ open, onClose }: { open: boolean; onClose: () => void }) {
|
||||
const { t, language } = useTranslation()
|
||||
const { plan, updatePlan, isFused, users } = useVacayStore()
|
||||
const { plan, updatePlan, isFused, users } = useVacayStore(useShallow(s => ({
|
||||
plan: s.plan, updatePlan: s.updatePlan, isFused: s.isFused, users: s.users,
|
||||
})))
|
||||
const {
|
||||
countries, publicHolidayCalendars, schoolHolidayCalendars, weekendDays, toggleWeekendDay,
|
||||
dissolveFusion, confirmingDissolve, askDissolve, cancelDissolve,
|
||||
@@ -138,7 +141,11 @@ function HolidaySettings({ type, countries, calendars, label, hint, enabled, onT
|
||||
}) {
|
||||
const { t } = useTranslation()
|
||||
const [adding, setAdding] = useState(false)
|
||||
const { addHolidayCalendar, updateHolidayCalendar, deleteHolidayCalendar } = useVacayStore()
|
||||
const { addHolidayCalendar, updateHolidayCalendar, deleteHolidayCalendar } = useVacayStore(useShallow(s => ({
|
||||
addHolidayCalendar: s.addHolidayCalendar,
|
||||
updateHolidayCalendar: s.updateHolidayCalendar,
|
||||
deleteHolidayCalendar: s.deleteHolidayCalendar,
|
||||
})))
|
||||
return (
|
||||
<div className="py-2 first:pt-0">
|
||||
<ToggleRow label={label} hint={hint} checked={enabled} onChange={onToggle} />
|
||||
|
||||
@@ -7,8 +7,8 @@ import MIconBtn from '../../components/MIconBtn'
|
||||
import MSheet from '../../components/MSheet'
|
||||
import { MUserPickerField } from '../../components/MUserPickerList'
|
||||
import {
|
||||
FormSheetBody, FormSheetFooter, FormSheetHeader, FormSheetSection, SELECT_FIELD_CLS, formOptionClass,
|
||||
} from '../trip/sheets/PlSheetChrome'
|
||||
FormSheetBody, FormSheetFooter, FormSheetHeader, FormSheetSection, SELECT_FIELD_CLS } from '../trip/sheets/PlSheetChrome'
|
||||
import { formOptionClass } from '../trip/sheets/formOptionClass'
|
||||
|
||||
interface MVacayShareSheetProps {
|
||||
open: boolean
|
||||
|
||||
@@ -201,7 +201,7 @@ describe('tripSyncManager.prepareForOffline — full run', () => {
|
||||
const broken = buildTrip({ id: 608, end_date: dateOffset(4) })
|
||||
serveTrips([broken, good], { 607: bundleFor(good) })
|
||||
|
||||
expect(await tripSyncManager.prepareForOffline()).toEqual({ status: 'done', trips: 2 })
|
||||
expect(await tripSyncManager.prepareForOffline()).toEqual({ status: 'done', trips: 1 })
|
||||
expect(await offlineDb.trips.get(607)).toBeDefined()
|
||||
expect(await offlineDb.trips.get(608)).toBeUndefined()
|
||||
expect(console.error).toHaveBeenCalled()
|
||||
|
||||
Reference in New Issue
Block a user