Pin phone sheets to the visible viewport, and let people correct login and organizer errors.
This commit is contained in:
1 parent
27d74e510c
commit
39807ef452
17 files changed
+236
-16
No files matched your search
@@ -23,8 +23,10 @@ const AskOrganizerInquiryModalContainer = memo<AskOrganizerInquiryModalProps>(
|
||||
description: t("description"),
|
||||
emailLabel: t("emailLabel"),
|
||||
emailPlaceholder: t("emailPlaceholder"),
|
||||
emailInvalid: t("emailInvalid"),
|
||||
questionLabel: t("questionLabel"),
|
||||
questionPlaceholder: t("questionPlaceholder"),
|
||||
questionTooShort: t("questionTooShort"),
|
||||
submitButton: t("submitButton"),
|
||||
closeAfterSuccess: t("closeAfterSuccess"),
|
||||
successTitle: t("successTitle"),
|
||||
@@ -59,6 +61,16 @@ const AskOrganizerInquiryModalContainer = memo<AskOrganizerInquiryModalProps>(
|
||||
}
|
||||
}, [isOpen]);
|
||||
|
||||
const onEmailChange = useCallback((value: string) => {
|
||||
setEmail(value);
|
||||
setEmailError(false);
|
||||
}, []);
|
||||
|
||||
const onMessageChange = useCallback((value: string) => {
|
||||
setMessage(value);
|
||||
setQuestionError(false);
|
||||
}, []);
|
||||
|
||||
const onSubmit = useCallback(
|
||||
async (e: FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
@@ -149,8 +161,8 @@ const AskOrganizerInquiryModalContainer = memo<AskOrganizerInquiryModalProps>(
|
||||
sendFailed={sendFailed}
|
||||
emailError={emailError}
|
||||
questionError={questionError}
|
||||
onEmailChange={setEmail}
|
||||
onMessageChange={setMessage}
|
||||
onEmailChange={onEmailChange}
|
||||
onMessageChange={onMessageChange}
|
||||
onHoneypotChange={setHoneypot}
|
||||
onSubmit={onSubmit}
|
||||
onDismissFailed={() => setSendFailed(false)}
|
||||
|
||||
@@ -8,8 +8,10 @@ export interface AskOrganizerInquiryModalCopy {
|
||||
description: string;
|
||||
emailLabel: string;
|
||||
emailPlaceholder: string;
|
||||
emailInvalid: string;
|
||||
questionLabel: string;
|
||||
questionPlaceholder: string;
|
||||
questionTooShort: string;
|
||||
submitButton: string;
|
||||
closeAfterSuccess: string;
|
||||
successTitle: string;
|
||||
|
||||
@@ -125,6 +125,7 @@ export function AskOrganizerInquiryModalView({
|
||||
value={email}
|
||||
onChange={(e) => onEmailChange(e.target.value)}
|
||||
error={emailError}
|
||||
textHint={emailError ? copy.emailInvalid : false}
|
||||
inputSize="medium"
|
||||
showHelpIcon={false}
|
||||
/>
|
||||
@@ -136,6 +137,7 @@ export function AskOrganizerInquiryModalView({
|
||||
value={message}
|
||||
onChange={(e) => onMessageChange(e.target.value)}
|
||||
error={questionError}
|
||||
textHint={questionError ? copy.questionTooShort : false}
|
||||
size="medium"
|
||||
appearance="embedded"
|
||||
rows={4}
|
||||
|
||||
@@ -48,7 +48,7 @@ const CreateContainer = memo<CreateProps>(
|
||||
}) => {
|
||||
const createRef = useRef<HTMLDivElement>(null);
|
||||
const overlayRef = useRef<HTMLDivElement>(null);
|
||||
const viewportHeight = useVisualViewportHeight(
|
||||
const viewport = useVisualViewportHeight(
|
||||
isOpen && presentation === "sheet",
|
||||
);
|
||||
|
||||
@@ -92,7 +92,8 @@ const CreateContainer = memo<CreateProps>(
|
||||
kebabMenuItems={kebabMenuItems}
|
||||
belowCard={belowCard}
|
||||
presentation={presentation}
|
||||
viewportHeight={viewportHeight}
|
||||
viewportHeight={viewport?.height}
|
||||
viewportOffsetTop={viewport?.offsetTop}
|
||||
/>
|
||||
);
|
||||
},
|
||||
|
||||
@@ -95,4 +95,6 @@ export interface CreateViewProps {
|
||||
belowCard?: React.ReactNode;
|
||||
presentation: CreateModalPresentationValue;
|
||||
viewportHeight?: number;
|
||||
/** `visualViewport.offsetTop`, so a phone sheet tracks the visible region on iOS. */
|
||||
viewportOffsetTop?: number;
|
||||
}
|
||||
@@ -43,6 +43,7 @@ export function CreateView({
|
||||
belowCard,
|
||||
presentation,
|
||||
viewportHeight,
|
||||
viewportOffsetTop,
|
||||
}: CreateViewProps) {
|
||||
return (
|
||||
<CreateModalFrameView
|
||||
@@ -57,6 +58,7 @@ export function CreateView({
|
||||
belowCard={belowCard}
|
||||
presentation={presentation}
|
||||
viewportHeight={viewportHeight}
|
||||
viewportOffsetTop={viewportOffsetTop}
|
||||
>
|
||||
<ModalHeader
|
||||
onClose={onClose}
|
||||
|
||||
@@ -33,6 +33,8 @@ export type CreateModalFrameViewProps = {
|
||||
presentation?: CreateModalPresentationValue;
|
||||
/** Visible viewport height so a phone sheet footer rides above the keyboard. */
|
||||
viewportHeight?: number;
|
||||
/** `visualViewport.offsetTop`, so the sheet tracks the visible region on iOS. */
|
||||
viewportOffsetTop?: number;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -51,6 +53,7 @@ export function CreateModalFrameView({
|
||||
belowCard,
|
||||
presentation = "dialog",
|
||||
viewportHeight,
|
||||
viewportOffsetTop,
|
||||
}: CreateModalFrameViewProps) {
|
||||
if (!isOpen) return null;
|
||||
|
||||
@@ -65,7 +68,12 @@ export function CreateModalFrameView({
|
||||
: "flex min-h-0 max-h-[90vh] w-full max-w-[560px] shrink-0 flex-col overflow-hidden rounded-[var(--radius-500)] bg-[var(--color-surface-default-primary)] shadow-[0px_0px_48px_0px_rgba(0,0,0,0.1)] z-[9999]";
|
||||
const overlayStyle =
|
||||
isSheet && viewportHeight != null
|
||||
? { height: viewportHeight, maxHeight: viewportHeight }
|
||||
? {
|
||||
top: viewportOffsetTop ?? 0,
|
||||
bottom: "auto" as const,
|
||||
height: viewportHeight,
|
||||
maxHeight: viewportHeight,
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const content = (
|
||||
|
||||
@@ -26,7 +26,7 @@ const LoginContainer = memo<LoginProps>(
|
||||
const backdropRef = useRef<HTMLDivElement>(null);
|
||||
const previousActiveElementRef = useRef<HTMLElement | null>(null);
|
||||
const [portalReady, setPortalReady] = useState(() => !usePortal);
|
||||
const viewportHeight = useVisualViewportHeight(isOpen);
|
||||
const viewport = useVisualViewportHeight(isOpen);
|
||||
|
||||
// Defer enabling the portal until after the layout commit so we don’t sync-setState
|
||||
// inside the effect (eslint react-hooks/set-state-in-effect) while still mounting
|
||||
@@ -135,7 +135,8 @@ const LoginContainer = memo<LoginProps>(
|
||||
portalReady={portalReady}
|
||||
usePortal={usePortal}
|
||||
backdropVariant={backdropVariant}
|
||||
viewportHeight={viewportHeight}
|
||||
viewportHeight={viewport?.height}
|
||||
viewportOffsetTop={viewport?.offsetTop}
|
||||
>
|
||||
{children}
|
||||
</LoginView>
|
||||
|
||||
@@ -35,4 +35,6 @@ export interface LoginViewProps {
|
||||
backdropVariant: LoginBackdropVariant;
|
||||
/** Visible viewport height on phones so the footer rides above the keyboard. */
|
||||
viewportHeight?: number;
|
||||
/** `visualViewport.offsetTop`, so the sheet tracks the visible region on iOS. */
|
||||
viewportOffsetTop?: number;
|
||||
}
|
||||
@@ -24,13 +24,19 @@ export function LoginView({
|
||||
usePortal,
|
||||
backdropVariant,
|
||||
viewportHeight,
|
||||
viewportOffsetTop,
|
||||
}: LoginViewProps) {
|
||||
if (!isOpen) return null;
|
||||
if (usePortal && !portalReady) return null;
|
||||
|
||||
const phoneSheetStyle =
|
||||
viewportHeight != null
|
||||
? { height: viewportHeight, maxHeight: viewportHeight }
|
||||
? {
|
||||
top: viewportOffsetTop ?? 0,
|
||||
bottom: "auto" as const,
|
||||
height: viewportHeight,
|
||||
maxHeight: viewportHeight,
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const belowCardLink = belowCard ? (
|
||||
|
||||
@@ -158,6 +158,7 @@ export default function LoginForm({
|
||||
setFormError("");
|
||||
const trimmed = email.trim().toLowerCase();
|
||||
if (!EMAIL_PATTERN.test(trimmed)) {
|
||||
setSent(false);
|
||||
setEmailError(t("errors.emailInvalid"));
|
||||
return;
|
||||
}
|
||||
@@ -173,6 +174,7 @@ export default function LoginForm({
|
||||
: undefined;
|
||||
const result = await requestMagicLink(trimmed, nextPath, draft);
|
||||
if (result.ok === false) {
|
||||
setSent(false);
|
||||
if (result.retryAfterMs != null && result.retryAfterMs > 0) {
|
||||
const seconds = Math.ceil(result.retryAfterMs / 1000);
|
||||
setFormError(
|
||||
@@ -190,6 +192,7 @@ export default function LoginForm({
|
||||
setLinkExpired(false);
|
||||
setSent(true);
|
||||
} catch {
|
||||
setSent(false);
|
||||
setFormError(t("errors.network"));
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
|
||||
@@ -1,22 +1,40 @@
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
/**
|
||||
* Visible viewport height, including the shrink when a phone keyboard opens.
|
||||
* Visible viewport box, including the shrink and offset when a phone keyboard opens.
|
||||
*
|
||||
* iOS Safari reports the keyboard by shrinking `visualViewport.height` and
|
||||
* shifting `offsetTop`. A `fixed` overlay has to use both, or its footer stays
|
||||
* in the layout viewport behind the keyboard.
|
||||
*
|
||||
* @param enabled When false, skip listeners and return `undefined`.
|
||||
* @returns Pixel height of `visualViewport`, or `undefined` when disabled.
|
||||
* @returns Height and top offset of `visualViewport`, or `undefined` when disabled.
|
||||
*
|
||||
* @example
|
||||
* const viewportHeight = useVisualViewportHeight(isOpen);
|
||||
* const viewport = useVisualViewportHeight(isOpen);
|
||||
*/
|
||||
export function useVisualViewportHeight(enabled: boolean): number | undefined {
|
||||
const [height, setHeight] = useState<number | undefined>(undefined);
|
||||
export function useVisualViewportHeight(
|
||||
enabled: boolean,
|
||||
): { height: number; offsetTop: number } | undefined {
|
||||
const [frame, setFrame] = useState<
|
||||
{ height: number; offsetTop: number } | undefined
|
||||
>(undefined);
|
||||
|
||||
useEffect(() => {
|
||||
if (!enabled) return;
|
||||
const vp = window.visualViewport;
|
||||
const sync = () => {
|
||||
setHeight(vp?.height ?? window.innerHeight);
|
||||
const next = {
|
||||
height: vp?.height ?? window.innerHeight,
|
||||
offsetTop: vp?.offsetTop ?? 0,
|
||||
};
|
||||
setFrame((prev) =>
|
||||
prev &&
|
||||
prev.height === next.height &&
|
||||
prev.offsetTop === next.offsetTop
|
||||
? prev
|
||||
: next,
|
||||
);
|
||||
};
|
||||
sync();
|
||||
vp?.addEventListener("resize", sync);
|
||||
@@ -29,5 +47,5 @@ export function useVisualViewportHeight(enabled: boolean): number | undefined {
|
||||
};
|
||||
}, [enabled]);
|
||||
|
||||
return enabled ? height : undefined;
|
||||
return enabled ? frame : undefined;
|
||||
}
|
||||
Reference in new issue
Block a user