Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

polish(photos):auth

Aswin Asok1611a738023c
diff --git a/web/apps/photos/public/images/auth-frame-curves.svg b/web/apps/photos/public/images/auth-frame-curves.svg
index 99062b6006..34a30f8796 100644
--- a/web/apps/photos/public/images/auth-frame-curves.svg
+++ b/web/apps/photos/public/images/auth-frame-curves.svg
@@ -1,3 +1,3 @@
<svg width="1357" height="715" viewBox="0 0 1357 715" fill="none" xmlns="http://www.w3.org/2000/svg">
-<path d="M170.065 -10.9783C252.3 109.821 131.817 230.62 68.0684 324.18C4.32028 417.74 -36.4785 570.516 47.0315 558.673C130.542 546.83 263.138 -33.4801 602.278 -51.2447C941.418 -69.0093 367.685 49.4213 455.657 242.463C543.63 435.505 778.223 133.51 999.429 4.42031C1220.63 -124.669 833.684 276.811 539.805 546.832C245.926 816.854 404.021 1065.56 608.015 812.117C812.009 558.673 1136.49 390.504 1281.2 728.031C1425.9 1065.56 1567.42 1109.38 1434.83 861.858C1302.23 614.338 1081.66 -18.0815 1272.27 -41.7676C1462.88 -65.4537 1509.41 -103.351 1571.25 480.511C1633.09 1064.37 1484.55 908.045 1420.17 655.788C1355.78 403.531 1490.93 139.431 1523.44 728.031C1555.95 1316.63 10.0578 1117.67 200.027 896.202C389.997 674.737 261.225 273.258 73.8059 728.031" stroke="#54db83" style="stroke:#54db83;stroke-opacity:1;"/>
+<path d="M170.065 -10.9783C252.3 109.821 131.817 230.62 68.0684 324.18C4.32028 417.74 -36.4785 570.516 47.0315 558.673C130.542 546.83 263.138 -33.4801 602.278 -51.2447C941.418 -69.0093 367.685 49.4213 455.657 242.463C543.63 435.505 778.223 133.51 999.429 4.42031C1220.63 -124.669 833.684 276.811 539.805 546.832C245.926 816.854 404.021 1065.56 608.015 812.117C812.009 558.673 1136.49 390.504 1281.2 728.031C1425.9 1065.56 1567.42 1109.38 1434.83 861.858C1302.23 614.338 1081.66 -18.0815 1272.27 -41.7676C1462.88 -65.4537 1509.41 -103.351 1571.25 480.511C1633.09 1064.37 1484.55 908.045 1420.17 655.788C1355.78 403.531 1490.93 139.431 1523.44 728.031C1555.95 1316.63 10.0578 1117.67 200.027 896.202C389.997 674.737 261.225 273.258 73.8059 728.031" stroke="#54db83" style="stroke:#54db83;stroke-opacity:.35;"/>
</svg>
diff --git a/web/apps/photos/src/components/PhotosAuthShell.tsx b/web/apps/photos/src/components/PhotosAuthShell.tsx
index 1a25e90f9a..aa295a13cb 100644
--- a/web/apps/photos/src/components/PhotosAuthShell.tsx
+++ b/web/apps/photos/src/components/PhotosAuthShell.tsx
@@ -1,6 +1,6 @@
import { Tick02Icon } from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
-import { GlobalStyles, styled } from "@mui/material";
+import { GlobalStyles, keyframes, styled } from "@mui/material";
import { EnteLogo } from "ente-base/components/EnteLogo";
import { pt } from "ente-base/i18n";
import type React from "react";
@@ -44,6 +44,52 @@ export const PhotosAuthShell: React.FC<PhotosAuthShellProps> = ({
const authHeadline = pt("Safe home for your photos");
+const shellReveal = keyframes({
+ from: { opacity: 0, transform: "translateY(18px)" },
+ to: { opacity: 1, transform: "translateY(0)" },
+});
+
+const brandCopyReveal = keyframes({
+ from: { opacity: 0, transform: "translateY(12px)" },
+ to: { opacity: 1, transform: "translateY(0)" },
+});
+
+const illustrationReveal = keyframes({
+ from: { opacity: 0, transform: "translateY(18px) scale(0.98)" },
+ to: { opacity: 1, transform: "translateY(0) scale(1)" },
+});
+
+const cameraSparkle = keyframes({
+ from: {
+ opacity: 0,
+ transform: "translate(-50%, -50%) scale(0) rotate(-20deg)",
+ },
+ "35%": {
+ opacity: 1,
+ transform: "translate(-50%, -50%) scale(1) rotate(0)",
+ },
+ "70%": {
+ opacity: 0.85,
+ transform: "translate(-50%, -50%) scale(0.72) rotate(24deg)",
+ },
+ to: {
+ opacity: 0,
+ transform: "translate(-50%, -50%) scale(1.3) rotate(45deg)",
+ },
+});
+
+const brandCurvesDrift = keyframes({
+ "0%, 100%": {
+ backgroundPosition: "0 0, calc(50% - 6px) calc(50% + 4px), 0 0",
+ },
+ "50%": { backgroundPosition: "0 0, calc(50% + 6px) calc(50% - 4px), 0 0" },
+});
+
+const brandCopyAnimation = {
+ animation: `${brandCopyReveal} 520ms cubic-bezier(0.22, 1, 0.36, 1) both`,
+ "@media (prefers-reduced-motion: reduce)": { animation: "none" },
+};
+
interface BrandPanelProps {
headline: string;
size: "desktop" | "tablet" | "mobile";
@@ -131,7 +177,9 @@ const PageCard = styled("div")(({ theme }) => ({
position: "relative",
overflow: "hidden",
backgroundColor: "#fff",
+ animation: `${shellReveal} 620ms cubic-bezier(0.22, 1, 0.36, 1) both`,
...theme.applyStyles("dark", { backgroundColor: "#252525" }),
+ "@media (prefers-reduced-motion: reduce)": { animation: "none" },
[authAboveMobileMediaQuery]: { borderRadius: "24px" },
"@media (min-width: 1024px)": {
width: "1032px",
@@ -179,7 +227,7 @@ const ContentSheet = styled("section")(({ theme }) => ({
flex: 1,
minHeight: 0,
marginTop: "-28px",
- padding: "12px 24px 24px",
+ padding: "40px 24px 24px",
display: "flex",
flexDirection: "column",
gap: "24px",
@@ -212,6 +260,7 @@ const SheetHandle = styled("div")({
alignSelf: "center",
borderRadius: "999px",
backgroundColor: "var(--photos-auth-fill-active)",
+ [authMobileMediaQuery]: { display: "none" },
"@media (min-width: 1024px)": { display: "none" },
});
@@ -256,7 +305,10 @@ const BrandPanelRoot = styled("div", {
backgroundColor: "var(--photos-auth-primary)",
backgroundImage: `url("/images/auth-surface-noise.svg"), url("/images/auth-frame-curves.svg"), url("${greenTileP3}")`,
backgroundRepeat: "repeat, no-repeat, repeat",
+ backgroundPosition: "0 0, center, 0 0",
backgroundSize: "auto, cover, auto",
+ animation: `${brandCurvesDrift} 20s ease-in-out infinite`,
+ "@media (prefers-reduced-motion: reduce)": { animation: "none" },
}));
/* 1x1 Display-P3 PNG tiled so the brand green renders in P3 on capable
@@ -302,6 +354,8 @@ const PanelHeadline = styled("h1", {
size === "desktop" ? "50px" : size === "tablet" ? "42px" : "34px",
letterSpacing: "-0.02em",
textWrap: "pretty",
+ ...brandCopyAnimation,
+ animationDelay: "80ms",
}));
const PanelSubtitle = styled("p", {
@@ -310,9 +364,11 @@ const PanelSubtitle = styled("p", {
margin: 0,
marginTop: size === "desktop" ? "14px" : "10px",
fontSize: size === "desktop" ? "20px" : "17px",
- fontWeight: 400,
+ fontWeight: 500,
lineHeight: size === "desktop" ? "28px" : "24px",
color: "rgba(255, 255, 255, 0.88)",
+ ...brandCopyAnimation,
+ animationDelay: "170ms",
}));
const BulletList = styled("ul")({
@@ -329,8 +385,12 @@ const Bullet = styled("li")({
alignItems: "center",
gap: "12px",
fontSize: "17px",
- fontWeight: 400,
+ fontWeight: 500,
lineHeight: "24px",
+ ...brandCopyAnimation,
+ "&:nth-of-type(1)": { animationDelay: "280ms" },
+ "&:nth-of-type(2)": { animationDelay: "350ms" },
+ "&:nth-of-type(3)": { animationDelay: "420ms" },
});
const CheckCircle = styled("span")({
@@ -351,8 +411,13 @@ const IllustrationClip = styled("div", {
height:
size === "desktop" ? "219px" : size === "tablet" ? "172px" : "127px",
flexShrink: 0,
+ position: "relative",
overflow: "hidden",
zIndex: 0,
+ ...(size !== "tablet" && {
+ animation: `${illustrationReveal} 500ms cubic-bezier(0.22, 1, 0.36, 1) ${size === "desktop" ? "840ms" : "130ms"} both`,
+ "@media (prefers-reduced-motion: reduce)": { animation: "none" },
+ }),
...(size === "desktop"
? {
marginTop: "auto",
@@ -366,6 +431,23 @@ const IllustrationClip = styled("div", {
// bottom edge by 32px (tablet) / 28px (mobile).
bottom: size === "tablet" ? "44px" : "38px",
}),
+ "&::after": {
+ content: '""',
+ width:
+ size === "desktop" ? "34px" : size === "tablet" ? "26px" : "20px",
+ aspectRatio: "1",
+ position: "absolute",
+ left: "67%",
+ top: size === "desktop" ? "59%" : "57%",
+ zIndex: 1,
+ pointerEvents: "none",
+ backgroundColor: "#fff",
+ clipPath:
+ "polygon(50% 0%, 59% 39%, 100% 50%, 59% 61%, 50% 100%, 41% 61%, 0% 50%, 41% 39%)",
+ filter: "drop-shadow(0 0 7px rgba(255, 245, 168, 0.95))",
+ animation: `${cameraSparkle} 520ms ease-out ${size === "desktop" ? "1400ms" : size === "tablet" ? "740ms" : "690ms"} both`,
+ "@media (prefers-reduced-motion: reduce)": { display: "none" },
+ },
"& > img": {
display: "block",
width: "473.694px",
diff --git a/web/apps/photos/src/components/auth/AuthDialog.tsx b/web/apps/photos/src/components/auth/AuthDialog.tsx
new file mode 100644
index 0000000000..3d25aa99ca
--- /dev/null
+++ b/web/apps/photos/src/components/auth/AuthDialog.tsx
@@ -0,0 +1,103 @@
+import { Dialog, GlobalStyles, styled, type ModalProps } from "@mui/material";
+import { SlideUpTransition } from "ente-new/photos/components/mui/SlideUpTransition";
+import type React from "react";
+import {
+ authBodyTypography,
+ authColorVariables,
+ authDisplayFontFamily,
+ authMobileMediaQuery,
+} from "./styles";
+
+interface AuthDialogProps extends React.PropsWithChildren {
+ open: boolean;
+ onClose: ModalProps["onClose"];
+ ariaLabelledby?: string;
+}
+
+/**
+ * The dialog frame shared by the modals of the new Photos auth presentation:
+ * a 456px centered card over a dimmed backdrop on desktop, and a bottom sheet
+ * with a drag handle on mobile widths.
+ */
+export const AuthDialog: React.FC<AuthDialogProps> = ({
+ open,
+ onClose,
+ ariaLabelledby,
+ children,
+}) => (
+ <DialogRoot
+ open={open}
+ onClose={onClose}
+ slots={{ transition: SlideUpTransition }}
+ slotProps={{
+ backdrop: { sx: { backgroundColor: "rgba(0, 0, 0, 0.4)" } },
+ }}
+ maxWidth={false}
+ aria-labelledby={ariaLabelledby}
+ >
+ <GlobalStyles styles={authColorVariables} />
+ <SheetHandle />
+ {children}
+ </DialogRoot>
+);
+
+export const AuthDialogHeader = styled("div")({
+ display: "flex",
+ flexDirection: "column",
+ gap: "6px",
+});
+
+export const AuthDialogTitle = styled("h2")({
+ margin: 0,
+ fontFamily: authDisplayFontFamily,
+ fontSize: "22px",
+ fontWeight: 600,
+ lineHeight: "30px",
+ color: "var(--photos-auth-text)",
+ [authMobileMediaQuery]: { fontSize: "20px", lineHeight: "28px" },
+});
+
+export const AuthDialogText = styled("p")({
+ ...authBodyTypography,
+ margin: 0,
+ color: "var(--photos-auth-text-muted)",
+ textWrap: "pretty",
+});
+
+const DialogRoot = styled(Dialog)(({ theme }) => ({
+ "& .MuiDialog-paper": {
+ width: "456px",
+ maxWidth: "calc(100% - 32px)",
+ margin: "16px",
+ padding: "32px",
+ boxSizing: "border-box",
+ borderRadius: "24px",
+ backgroundColor: "#fff",
+ backgroundImage: "none",
+ boxShadow: "0 4px 16px rgba(0, 0, 0, 0.14)",
+ ...theme.applyStyles("dark", { backgroundColor: "#252525" }),
+ },
+ [authMobileMediaQuery]: {
+ "& .MuiDialog-container": { alignItems: "flex-end" },
+ "& .MuiDialog-paper": {
+ width: "100%",
+ maxWidth: "100%",
+ margin: 0,
+ padding: "12px 24px 28px",
+ borderRadius: "24px 24px 0 0",
+ },
+ },
+}));
+
+const SheetHandle = styled("div")({
+ display: "none",
+ [authMobileMediaQuery]: {
+ display: "block",
+ width: "36px",
+ height: "4px",
+ flexShrink: 0,
+ margin: "0 auto 20px",
+ borderRadius: "999px",
+ backgroundColor: "var(--photos-auth-fill-active)",
+ },
+});
diff --git a/web/apps/photos/src/components/auth/Button.tsx b/web/apps/photos/src/components/auth/Button.tsx
index c93c1fd791..4cfa67cff7 100644
--- a/web/apps/photos/src/components/auth/Button.tsx
+++ b/web/apps/photos/src/components/auth/Button.tsx
@@ -80,20 +80,35 @@ const ButtonRoot = styled(
backgroundColor:
$variant === "primary"
? "var(--photos-auth-primary)"
- : "var(--photos-auth-fill)",
+ : "var(--photos-auth-button-secondary)",
+ boxShadow:
+ $variant === "primary"
+ ? "inset 0 0 0 1px var(--photos-auth-button-primary-stroke)"
+ : "inset 0 0 0 1px var(--photos-auth-button-secondary-stroke)",
cursor: $loading ? "default" : "pointer",
- transition: "background-color 120ms ease",
+ transition:
+ "background-color 160ms ease, box-shadow 160ms ease, transform 180ms cubic-bezier(0.22, 1, 0.36, 1)",
"&:hover:not(:disabled)": {
backgroundColor:
$variant === "primary"
? "var(--photos-auth-primary-hover)"
- : "var(--photos-auth-fill-hover)",
+ : "var(--photos-auth-button-secondary-hover)",
+ boxShadow:
+ $variant === "primary"
+ ? "inset 0 0 0 1px var(--photos-auth-button-primary-stroke-hover)"
+ : "inset 0 0 0 1px var(--photos-auth-button-secondary-stroke-hover)",
+ transform: "translateY(-2px)",
},
"&:active:not(:disabled)": {
backgroundColor:
$variant === "primary"
? "var(--photos-auth-primary-active)"
- : "var(--photos-auth-fill-active)",
+ : "var(--photos-auth-button-secondary-active)",
+ boxShadow:
+ $variant === "primary"
+ ? "inset 0 0 0 1px var(--photos-auth-button-primary-stroke-active)"
+ : "inset 0 0 0 1px var(--photos-auth-button-secondary-stroke-active)",
+ transform: "translateY(0) scale(0.985)",
},
"&:focus-visible": authFocusRing,
"&:disabled": $loading
@@ -101,9 +116,16 @@ const ButtonRoot = styled(
: {
color: "var(--photos-auth-text-disabled)",
backgroundColor: "var(--photos-auth-fill-hover)",
+ boxShadow: "none",
cursor: "not-allowed",
},
"& > .MuiCircularProgress-root": { position: "absolute" },
+ "@media (prefers-reduced-motion: reduce)": {
+ transition: "background-color 120ms ease",
+ "&:hover:not(:disabled), &:active:not(:disabled)": {
+ transform: "none",
+ },
+ },
}));
const ButtonLabel = styled(
diff --git a/web/apps/photos/src/components/auth/DevSettingsDialog.tsx b/web/apps/photos/src/components/auth/DevSettingsDialog.tsx
new file mode 100644
index 0000000000..38c5105004
--- /dev/null
+++ b/web/apps/photos/src/components/auth/DevSettingsDialog.tsx
@@ -0,0 +1,140 @@
+import { InformationCircleIcon } from "@hugeicons/core-free-icons";
+import { HugeiconsIcon } from "@hugeicons/react";
+import { CircularProgress, styled } from "@mui/material";
+import { pt } from "ente-base/i18n";
+import type { DevSettingsPresentationProps } from "ente-new/photos/components/DevSettings";
+import { t } from "i18next";
+import type React from "react";
+import {
+ AuthDialog,
+ AuthDialogHeader,
+ AuthDialogText,
+ AuthDialogTitle,
+} from "./AuthDialog";
+import { Button } from "./Button";
+import {
+ authBodyTypography,
+ authDialogContentLayout,
+ authFocusRing,
+} from "./styles";
+import { TextField } from "./TextField";
+
+/** Photos styling for the shared developer-settings controller. */
+export function DevSettingsDialog({
+ open,
+ onDialogClose,
+ value,
+ onChange,
+ onBlur,
+ error,
+ isChecking,
+ canSave,
+ onSubmit,
+ onClose,
+}: DevSettingsPresentationProps): React.JSX.Element {
+ return (
+ <AuthDialog
+ open={open}
+ onClose={onDialogClose}
+ ariaLabelledby="developer-settings-title"
+ >
+ <FormRoot onSubmit={onSubmit}>
+ <AuthDialogHeader>
+ <AuthDialogTitle id="developer-settings-title">
+ {t("developer_settings")}
+ </AuthDialogTitle>
+ <AuthDialogText>
+ {pt(
+ "Point this app at your own Ente server. Leave it blank to use api.ente.io.",
+ )}
+ </AuthDialogText>
+ </AuthDialogHeader>
+ <TextField
+ name="apiOrigin"
+ label={t("server_endpoint")}
+ value={value}
+ onChange={onChange}
+ onBlur={onBlur}
+ placeholder="https://api.example.org"
+ autoFocus
+ disabled={isChecking}
+ error={Boolean(error)}
+ helperText={
+ error == "Invalid endpoint"
+ ? pt("Enter a full URL, including https://")
+ : error
+ ? pt("Could not reach this endpoint")
+ : undefined
+ }
+ trailing={
+ <InfoLink
+ href="https://ente.com/help/self-hosting/installation/post-install/#step-6-configure-apps-to-use-your-server"
+ target="_blank"
+ rel="noopener"
+ aria-label={t("more_information")}
+ >
+ <HugeiconsIcon
+ icon={InformationCircleIcon}
+ size={20}
+ strokeWidth={2}
+ aria-hidden="true"
+ />
+ </InfoLink>
+ }
+ />
+ {isChecking && (
+ <StatusPill role="status">
+ <CircularProgress
+ size={18}
+ sx={{ color: "var(--photos-auth-primary)" }}
+ />
+ <span>{pt("Checking the endpoint is reachable")}</span>
+ </StatusPill>
+ )}
+ <ButtonRow>
+ <Button
+ type="submit"
+ variant="primary"
+ fullWidth
+ disabled={!canSave}
+ >
+ {t("save")}
+ </Button>
+ <Button variant="secondary" fullWidth onClick={onClose}>
+ {t("cancel")}
+ </Button>
+ </ButtonRow>
+ </FormRoot>
+ </AuthDialog>
+ );
+}
+
+const FormRoot = styled("form")(authDialogContentLayout);
+
+const InfoLink = styled("a")({
+ width: "20px",
+ height: "20px",
+ flex: "0 0 20px",
+ display: "inline-flex",
+ alignItems: "center",
+ justifyContent: "center",
+ borderRadius: "4px",
+ color: "var(--photos-auth-text-faint)",
+ "&:hover": { color: "var(--photos-auth-text-muted)" },
+ "&:focus-visible": authFocusRing,
+});
+
+const StatusPill = styled("div")({
+ ...authBodyTypography,
+ display: "flex",
+ alignItems: "center",
+ gap: "10px",
+ padding: "12px 14px",
+ borderRadius: "20px",
+ backgroundColor: "var(--photos-auth-button-secondary)",
+ boxShadow: "inset 0 0 0 1px var(--photos-auth-stroke)",
+ color: "var(--photos-auth-text-muted)",
+ "& > svg, & > .MuiCircularProgress-root": { flexShrink: 0 },
+});
+
+const ButtonRow = styled("div")({ display: "flex", gap: "12px" });
diff --git a/web/apps/photos/src/components/auth/FormFields.tsx b/web/apps/photos/src/components/auth/FormFields.tsx
index bd1d915924..266b2dc80f 100644
--- a/web/apps/photos/src/components/auth/FormFields.tsx
+++ b/web/apps/photos/src/components/auth/FormFields.tsx
@@ -8,6 +8,7 @@ export function FormFields({
}
const FormFieldsRoot = styled("div")({
+ "--photos-auth-message-gap": "16px",
width: "100%",
display: "flex",
flexDirection: "column",
diff --git a/web/apps/photos/src/components/auth/Message.tsx b/web/apps/photos/src/components/auth/Message.tsx
index aa5b03ec90..858d871d26 100644
--- a/web/apps/photos/src/components/auth/Message.tsx
+++ b/web/apps/photos/src/components/auth/Message.tsx
@@ -7,6 +7,7 @@ import {
import { HugeiconsIcon } from "@hugeicons/react";
import { styled } from "@mui/material";
import type React from "react";
+import { useEffect, useRef } from "react";
import { authMiniTypography, authTransientProps } from "./styles";
export type MessageKind = "error" | "warning" | "success" | "info";
@@ -15,6 +16,7 @@ export interface MessageProps {
children: React.ReactNode;
kind?: MessageKind;
note?: boolean;
+ visible?: boolean;
id?: string;
}
@@ -22,24 +24,37 @@ export function Message({
children,
kind = "info",
note = false,
+ visible,
id,
}: MessageProps): React.JSX.Element {
- const icon = messageIcons[kind];
+ const isVisible = visible ?? true;
+ const lastVisibleContent = useRef({ children, kind });
+ const displayedContent = isVisible
+ ? { children, kind }
+ : lastVisibleContent.current;
+
+ useEffect(() => {
+ if (isVisible) lastVisibleContent.current = { children, kind };
+ }, [children, isVisible, kind]);
return (
<MessageRoot
id={id}
- role={kind === "error" ? "alert" : "status"}
- $kind={kind}
- $note={note}
+ role={displayedContent.kind === "error" ? "alert" : "status"}
+ aria-hidden={!isVisible || undefined}
+ $kind={displayedContent.kind}
+ $animated={visible !== undefined}
+ $visible={isVisible}
>
- <HugeiconsIcon
- icon={icon}
- size={14}
- strokeWidth={2}
- aria-hidden="true"
- />
- <span>{children}</span>
+ <MessageContent $note={note}>
+ <HugeiconsIcon
+ icon={messageIcons[displayedContent.kind]}
+ size={14}
+ strokeWidth={2}
+ aria-hidden="true"
+ />
+ <span>{displayedContent.children}</span>
+ </MessageContent>
</MessageRoot>
);
}
@@ -54,18 +69,53 @@ const messageIcons = {
const MessageRoot = styled(
"span",
authTransientProps,
-)<{ $kind: MessageKind; $note: boolean }>(({ $kind, $note }) => ({
- ...authMiniTypography,
+)<{ $kind: MessageKind; $animated: boolean; $visible: boolean }>(({
+ $kind,
+ $animated,
+ $visible,
+}) => {
+ const delay = $visible ? "40ms" : "0ms";
+
+ return {
+ ...authMiniTypography,
+ display: "inline-grid",
+ gridTemplateRows: $visible ? "1fr" : "0fr",
+ marginTop:
+ $animated && !$visible
+ ? "calc(-1 * var(--photos-auth-message-gap, 8px))"
+ : 0,
+ opacity: $visible ? 1 : 0,
+ transform: $visible ? "translateY(0)" : "translateY(-4px)",
+ visibility: $visible ? "visible" : "hidden",
+ color:
+ $kind === "error"
+ ? "var(--photos-auth-warning)"
+ : $kind === "warning"
+ ? "var(--photos-auth-caution)"
+ : $kind === "success"
+ ? "var(--photos-auth-success)"
+ : "var(--photos-auth-text-muted)",
+ ...($animated && {
+ overflow: "hidden",
+ transition: [
+ `grid-template-rows 360ms cubic-bezier(0.22, 1, 0.36, 1) ${delay}`,
+ `margin-top 360ms cubic-bezier(0.22, 1, 0.36, 1) ${delay}`,
+ `opacity 360ms cubic-bezier(0.22, 1, 0.36, 1) ${delay}`,
+ `transform 360ms cubic-bezier(0.22, 1, 0.36, 1) ${delay}`,
+ `visibility 0s linear ${$visible ? "0ms" : "360ms"}`,
+ ].join(", "),
+ "@media (prefers-reduced-motion: reduce)": { transition: "none" },
+ }),
+ };
+});
+
+const MessageContent = styled(
+ "span",
+ authTransientProps,
+)<{ $note: boolean }>(({ $note }) => ({
+ minHeight: 0,
display: "inline-flex",
alignItems: $note ? "flex-start" : "center",
gap: $note ? "8px" : "4px",
- color:
- $kind === "error"
- ? "var(--photos-auth-warning)"
- : $kind === "warning"
- ? "var(--photos-auth-caution)"
- : $kind === "success"
- ? "var(--photos-auth-success)"
- : "var(--photos-auth-text-muted)",
"& > svg": { flexShrink: 0 },
}));
diff --git a/web/apps/photos/src/components/auth/OTPField.tsx b/web/apps/photos/src/components/auth/OTPField.tsx
index 0fcb0e6a1b..c6e9f8e718 100644
--- a/web/apps/photos/src/components/auth/OTPField.tsx
+++ b/web/apps/photos/src/components/auth/OTPField.tsx
@@ -2,11 +2,16 @@ import { styled } from "@mui/material";
import { t } from "i18next";
import type React from "react";
import { useEffect, useRef } from "react";
-import { authDisplayFontFamily, authTransientProps } from "./styles";
+import {
+ authDisplayFontFamily,
+ authMiniTypography,
+ authTransientProps,
+} from "./styles";
export interface OTPFieldProps {
id?: string;
name?: string;
+ label?: React.ReactNode;
value: string;
onChange: (value: string) => void;
length?: number;
@@ -20,6 +25,7 @@ export interface OTPFieldProps {
export function OTPField({
id,
name,
+ label,
value,
onChange,
length = 6,
@@ -30,6 +36,8 @@ export function OTPField({
ariaDescribedBy,
}: OTPFieldProps): React.JSX.Element {
const inputRefs = useRef<(HTMLInputElement | null)[]>([]);
+ const wasDisabled = useRef(disabled);
+ const hadError = useRef(error);
useEffect(() => {
if (autoFocus && value.length === 0) inputRefs.current[0]?.focus();
@@ -48,6 +56,24 @@ export function OTPField({
}
}
+ useEffect(() => {
+ const shouldRestoreFocus =
+ error && !disabled && (wasDisabled.current || !hadError.current);
+
+ wasDisabled.current = disabled;
+ hadError.current = error;
+
+ if (shouldRestoreFocus) {
+ const index = Math.max(
+ Math.min(value.trimEnd().length - 1, length - 1),
+ 0,
+ );
+ const input = inputRefs.current[index];
+ input?.focus();
+ input?.select();
+ }
+ }, [disabled, error, length, value]);
+
function updateDigit(index: number, digit: string) {
const otp = value.padEnd(length, " ").slice(0, length).split("");
otp[index] = digit || " ";
@@ -145,37 +171,55 @@ export function OTPField({
const inputAriaLabel = ariaLabel ?? t("verification_code");
return (
- <OTPRoot $disabled={disabled}>
- {Array.from({ length }, (_, index) => (
- <OTPInput
- key={index}
- ref={(element) => {
- inputRefs.current[index] = element;
- }}
- id={index === 0 ? id : undefined}
- name={index === 0 ? name : undefined}
- type="tel"
- value={value[index]?.trim() ?? ""}
- onChange={(event) => handleChange(index, event)}
- onFocus={(event) => event.currentTarget.select()}
- onInput={(event) => handleInput(index, event)}
- onKeyDown={(event) => handleKeyDown(index, event)}
- onPaste={(event) => handlePaste(index, event)}
- disabled={disabled}
- autoFocus={autoFocus && index === 0}
- inputMode="numeric"
- pattern="[0-9]*"
- autoComplete={index === 0 ? "one-time-code" : "off"}
- aria-label={`${inputAriaLabel} ${index + 1}`}
- aria-describedby={ariaDescribedBy}
- aria-invalid={error || undefined}
- $error={error}
- />
- ))}
- </OTPRoot>
+ <OTPFieldRoot>
+ {label && <OTPLabel>{label}</OTPLabel>}
+ <OTPRoot $disabled={disabled}>
+ {Array.from({ length }, (_, index) => (
+ <OTPInput
+ key={index}
+ ref={(element) => {
+ inputRefs.current[index] = element;
+ }}
+ id={index === 0 ? id : undefined}
+ name={index === 0 ? name : undefined}
+ type="tel"
+ value={value[index]?.trim() ?? ""}
+ onChange={(event) => handleChange(index, event)}
+ onFocus={(event) => event.currentTarget.select()}
+ onInput={(event) => handleInput(index, event)}
+ onKeyDown={(event) => handleKeyDown(index, event)}
+ onPaste={(event) => handlePaste(index, event)}
+ disabled={disabled}
+ autoFocus={autoFocus && index === 0}
+ inputMode="numeric"
+ pattern="[0-9]*"
+ autoComplete={index === 0 ? "one-time-code" : "off"}
+ aria-label={`${inputAriaLabel} ${index + 1}`}
+ aria-describedby={ariaDescribedBy}
+ aria-invalid={error || undefined}
+ $error={error}
+ />
+ ))}
+ </OTPRoot>
+ </OTPFieldRoot>
);
}
+const OTPFieldRoot = styled("div")({
+ width: "100%",
+ display: "flex",
+ flexDirection: "column",
+ gap: "16px",
+ "&:focus-within > span": { color: "var(--photos-auth-text)" },
+});
+
+const OTPLabel = styled("span")({
+ ...authMiniTypography,
+ color: "var(--photos-auth-text-muted)",
+ transition: "color 100ms ease-in",
+ "@media (prefers-reduced-motion: reduce)": { transition: "none" },
+});
+
const OTPRoot = styled(
"div",
authTransientProps,
diff --git a/web/apps/photos/src/components/auth/PasswordStrengthMessage.tsx b/web/apps/photos/src/components/auth/PasswordStrengthMessage.tsx
new file mode 100644
index 0000000000..c4eb537f5e
--- /dev/null
+++ b/web/apps/photos/src/components/auth/PasswordStrengthMessage.tsx
@@ -0,0 +1,29 @@
+import type { PasswordStrength } from "ente-accounts/utils/password";
+import { t } from "i18next";
+import type React from "react";
+import { Message, type MessageKind } from "./Message";
+
+interface PasswordStrengthMessageProps {
+ strength?: PasswordStrength;
+ visible: boolean;
+}
+
+export function PasswordStrengthMessage({
+ strength,
+ visible,
+}: PasswordStrengthMessageProps): React.JSX.Element {
+ const displayedStrength = strength ?? "weak";
+
+ const kind: MessageKind =
+ displayedStrength === "weak"
+ ? "error"
+ : displayedStrength === "moderate"
+ ? "warning"
+ : "success";
+
+ return (
+ <Message kind={kind} visible={visible}>
+ {t("password_strength", { context: displayedStrength })}
+ </Message>
+ );
+}
diff --git a/web/apps/photos/src/components/auth/RecoveryForm.tsx b/web/apps/photos/src/components/auth/RecoveryForm.tsx
index be2f3a812b..ae994d858d 100644
--- a/web/apps/photos/src/components/auth/RecoveryForm.tsx
+++ b/web/apps/photos/src/components/auth/RecoveryForm.tsx
@@ -5,29 +5,69 @@ import { pt } from "ente-base/i18n";
import log from "ente-base/log";
import { useFormik } from "formik";
import { t } from "i18next";
-import type React from "react";
+import React, { useState } from "react";
+import {
+ AuthDialog,
+ AuthDialogHeader,
+ AuthDialogText,
+ AuthDialogTitle,
+} from "./AuthDialog";
import { Button } from "./Button";
import { Form } from "./Form";
import { FormFields } from "./FormFields";
import { FormFooter } from "./FormFooter";
import { ScreenHeader } from "./ScreenHeader";
+import { authDialogContentLayout } from "./styles";
import { TextField } from "./TextField";
import { TextLink } from "./TextLink";
export function RecoverAccountForm(
props: RecoverAccountPresentationProps,
): React.JSX.Element {
+ // Present the no-recovery-key notice in the styled auth dialog instead of
+ // the shared MiniDialog the page supplies via onNoRecoveryKey.
+ const [showNoRecoveryKey, setShowNoRecoveryKey] = useState(false);
+
return (
- <RecoveryForm
- {...props}
- title={t("recover_account")}
- subtitle={pt(
- "Enter the recovery key you saved when you created your account.",
- )}
- />
+ <>
+ <RecoveryForm
+ {...props}
+ onNoRecoveryKey={() => setShowNoRecoveryKey(true)}
+ title={t("recover_account")}
+ subtitle={pt(
+ "Enter the recovery key you saved when you created your account.",
+ )}
+ />
+ <AuthDialog
+ open={showNoRecoveryKey}
+ onClose={() => setShowNoRecoveryKey(false)}
+ ariaLabelledby="no-recovery-key-title"
+ >
+ <DialogContent>
+ <AuthDialogHeader>
+ <AuthDialogTitle id="no-recovery-key-title">
+ {t("sorry")}
+ </AuthDialogTitle>
+ <AuthDialogText>
+ {t("no_recovery_key_message")}
+ </AuthDialogText>
+ </AuthDialogHeader>
+ <Button
+ variant="secondary"
+ fullWidth
+ autoFocus
+ onClick={() => setShowNoRecoveryKey(false)}
+ >
+ {t("ok")}
+ </Button>
+ </DialogContent>
+ </AuthDialog>
+ </>
);
}
+const DialogContent = styled("div")(authDialogContentLayout);
+
export function RecoverTwoFactorForm(
props: TwoFactorRecoverPresentationProps,
): React.JSX.Element {
diff --git a/web/apps/photos/src/components/auth/SetPasswordForm.tsx b/web/apps/photos/src/components/auth/SetPasswordForm.tsx
index 7cfcbdedd8..409d4fe874 100644
--- a/web/apps/photos/src/components/auth/SetPasswordForm.tsx
+++ b/web/apps/photos/src/components/auth/SetPasswordForm.tsx
@@ -7,7 +7,8 @@ import { Button } from "./Button";
import { Form } from "./Form";
import { FormFields } from "./FormFields";
import { FormFooter } from "./FormFooter";
-import { Message, type MessageKind } from "./Message";
+import { Message } from "./Message";
+import { PasswordStrengthMessage } from "./PasswordStrengthMessage";
import { ScreenHeader } from "./ScreenHeader";
import { TextField } from "./TextField";
import { TextLink } from "./TextLink";
@@ -27,13 +28,6 @@ export function SetPasswordForm({
onConfirmPasswordChange,
onSubmit,
}: NewPasswordPresentationProps): React.JSX.Element {
- const passwordStrengthKind: MessageKind =
- passwordStrength === "weak"
- ? "error"
- : passwordStrength === "moderate"
- ? "warning"
- : "success";
-
return (
<>
<ScreenHeader
@@ -66,13 +60,10 @@ export function SetPasswordForm({
disabled={isSubmitting}
autoFocus
/>
- {password ? (
- <Message kind={passwordStrengthKind}>
- {t("password_strength", {
- context: passwordStrength,
- })}
- </Message>
- ) : null}
+ <PasswordStrengthMessage
+ strength={passwordStrength}
+ visible={Boolean(password)}
+ />
</PasswordField>
<TextField
name="confirmPassword"
@@ -117,6 +108,7 @@ export function SetPasswordForm({
const HiddenEmail = styled("input")({ display: "none" });
const PasswordField = styled("div")({
+ "--photos-auth-message-gap": "8px",
display: "flex",
flexDirection: "column",
gap: "8px",
diff --git a/web/apps/photos/src/components/auth/SignUpForm.tsx b/web/apps/photos/src/components/auth/SignUpForm.tsx
index 09c3114c54..63c0689d4c 100644
--- a/web/apps/photos/src/components/auth/SignUpForm.tsx
+++ b/web/apps/photos/src/components/auth/SignUpForm.tsx
@@ -10,7 +10,7 @@ import { Checkbox } from "./Checkbox";
import { Form } from "./Form";
import { FormFields } from "./FormFields";
import { FormFooter } from "./FormFooter";
-import { Message, type MessageKind } from "./Message";
+import { PasswordStrengthMessage } from "./PasswordStrengthMessage";
import { ScreenHeader } from "./ScreenHeader";
import { TextField } from "./TextField";
import { TextLink } from "./TextLink";
@@ -37,14 +37,6 @@ export function SignUpForm({
onSubmit,
onLogin,
}: SignUpPresentationProps): React.JSX.Element {
- const passwordStrengthKind: MessageKind | undefined = passwordStrength
- ? passwordStrength === "weak"
- ? "error"
- : passwordStrength === "moderate"
- ? "warning"
- : "success"
- : undefined;
-
return (
<>
<ScreenHeader
@@ -83,13 +75,10 @@ export function SignUpForm({
helperText={passwordError}
disabled={isSubmitting}
/>
- {passwordStrength && passwordStrengthKind ? (
- <Message kind={passwordStrengthKind}>
- {t("password_strength", {
- context: passwordStrength,
- })}
- </Message>
- ) : null}
+ <PasswordStrengthMessage
+ strength={passwordStrength}
+ visible={Boolean(passwordStrength)}
+ />
</PasswordField>
<TextField
name="confirmPassword"
@@ -174,6 +163,7 @@ export function SignUpForm({
}
const PasswordField = styled("div")({
+ "--photos-auth-message-gap": "8px",
display: "flex",
flexDirection: "column",
gap: "8px",
diff --git a/web/apps/photos/src/components/auth/TextField.tsx b/web/apps/photos/src/components/auth/TextField.tsx
index c41ba238cc..c963b015c0 100644
--- a/web/apps/photos/src/components/auth/TextField.tsx
+++ b/web/apps/photos/src/components/auth/TextField.tsx
@@ -22,6 +22,9 @@ export interface TextFieldProps {
onKeyDown?: (
event: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>,
) => void;
+ onBlur?: (
+ event: React.FocusEvent<HTMLInputElement | HTMLTextAreaElement>,
+ ) => void;
type?: React.HTMLInputTypeAttribute;
placeholder?: string;
required?: boolean;
@@ -36,6 +39,7 @@ export interface TextFieldProps {
rows?: number;
inputMode?: React.HTMLAttributes<HTMLInputElement>["inputMode"];
ariaLabel?: string;
+ trailing?: React.ReactNode;
}
export function TextField({
@@ -44,6 +48,7 @@ export function TextField({
value,
onChange,
onKeyDown,
+ onBlur,
type = "text",
placeholder,
required,
@@ -58,10 +63,12 @@ export function TextField({
rows = 5,
inputMode,
ariaLabel,
+ trailing,
}: TextFieldProps): React.JSX.Element {
const generatedID = useId();
const inputID = id ?? generatedID;
- const helperID = helperText ? `${inputID}-helper` : undefined;
+ const helperID = `${inputID}-helper`;
+ const hasHelper = Boolean(helperText);
const [isPasswordVisible, setIsPasswordVisible] = useState(false);
const inputType = showPasswordToggle
? isPasswordVisible
@@ -98,9 +105,10 @@ export function TextField({
autoFocus,
autoComplete,
name,
+ onBlur,
"aria-label": ariaLabel,
"aria-invalid": error || undefined,
- "aria-describedby": helperID,
+ "aria-describedby": hasHelper ? helperID : undefined,
};
return (
@@ -137,6 +145,7 @@ export function TextField({
{showPasswordToggle && !multiline && (
<PasswordToggle
type="button"
+ tabIndex={-1}
aria-label={t("show_or_hide_password")}
aria-controls={inputID}
aria-pressed={isPasswordVisible}
@@ -154,26 +163,33 @@ export function TextField({
/>
</PasswordToggle>
)}
+ {trailing}
</FieldBox>
- {helperText && (
- <Message id={helperID} kind={error ? "error" : "info"}>
- {helperText}
- </Message>
- )}
+ <Message
+ id={helperID}
+ kind={error ? "error" : "info"}
+ visible={hasHelper}
+ >
+ {helperText}
+ </Message>
</FieldRoot>
);
}
const FieldRoot = styled("div")({
+ "--photos-auth-message-gap": "9px",
width: "100%",
display: "flex",
flexDirection: "column",
gap: "9px",
+ "&:focus-within > label": { color: "var(--photos-auth-text)" },
});
const FieldLabel = styled("label")({
...authMiniTypography,
color: "var(--photos-auth-text-muted)",
+ transition: "color 100ms ease-in",
+ "@media (prefers-reduced-motion: reduce)": { transition: "none" },
});
const RequiredMark = styled("span")({ color: "var(--photos-auth-warning)" });
@@ -198,7 +214,7 @@ const FieldBox = styled(
gap: "8px",
boxSizing: "border-box",
backgroundColor: $disabled
- ? "var(--photos-auth-fill)"
+ ? "var(--photos-auth-fill-hover)"
: "var(--photos-auth-field)",
boxShadow: $disabled
? "none"
@@ -259,5 +275,8 @@ const PasswordToggle = styled("button")({
color: "var(--photos-auth-text-faint)",
cursor: "pointer",
"&:focus-visible": authFocusRing,
- "&:disabled": { cursor: "not-allowed" },
+ "&:disabled": {
+ color: "var(--photos-auth-text-disabled)",
+ cursor: "not-allowed",
+ },
});
diff --git a/web/apps/photos/src/components/auth/TextLink.tsx b/web/apps/photos/src/components/auth/TextLink.tsx
index ca0caa8ec7..cfe5983eb8 100644
--- a/web/apps/photos/src/components/auth/TextLink.tsx
+++ b/web/apps/photos/src/components/auth/TextLink.tsx
@@ -43,6 +43,10 @@ const TextLinkRoot = styled(
color: "var(--photos-auth-primary)",
textDecoration: "none",
cursor: "pointer",
+ "&:hover:not(:disabled)": {
+ textDecoration: "underline",
+ textUnderlineOffset: "3px",
+ },
"&:focus-visible": { ...authFocusRing, borderRadius: "4px" },
"&:disabled": {
color: "var(--photos-auth-text-disabled)",
diff --git a/web/apps/photos/src/components/auth/TwoFactorForm.tsx b/web/apps/photos/src/components/auth/TwoFactorForm.tsx
index a0b73dcae3..caec794e12 100644
--- a/web/apps/photos/src/components/auth/TwoFactorForm.tsx
+++ b/web/apps/photos/src/components/auth/TwoFactorForm.tsx
@@ -75,9 +75,9 @@ export function TwoFactorForm({
disabled={formik.isSubmitting}
autoFocus
/>
- {formik.errors.otp ? (
- <Message kind="error">{formik.errors.otp}</Message>
- ) : null}
+ <Message kind="error" visible={Boolean(formik.errors.otp)}>
+ {formik.errors.otp}
+ </Message>
</FormFields>
<FormFooter>
<Button
diff --git a/web/apps/photos/src/components/auth/VerifyEmailForm.tsx b/web/apps/photos/src/components/auth/VerifyEmailForm.tsx
index 7cf5078993..b07f46296f 100644
--- a/web/apps/photos/src/components/auth/VerifyEmailForm.tsx
+++ b/web/apps/photos/src/components/auth/VerifyEmailForm.tsx
@@ -76,18 +76,18 @@ export function VerifyEmailForm({
/>
<Form onSubmit={formik.handleSubmit}>
<FormFields>
- <FieldLabel>{t("verification_code")}</FieldLabel>
<OTPField
name="code"
+ label={t("verification_code")}
value={formik.values.code}
onChange={handleCodeChange}
error={Boolean(formik.errors.code)}
disabled={formik.isSubmitting}
autoFocus
/>
- {formik.errors.code ? (
- <Message kind="error">{formik.errors.code}</Message>
- ) : null}
+ <Message kind="error" visible={Boolean(formik.errors.code)}>
+ {formik.errors.code}
+ </Message>
</FormFields>
<FormFooter>
<Button
@@ -119,13 +119,6 @@ const Email = styled("strong")({
wordBreak: "break-word",
});
-const FieldLabel = styled("span")({
- fontSize: "12px",
- fontWeight: 500,
- lineHeight: "16px",
- color: "var(--photos-auth-text-muted)",
-});
-
const FooterLinks = styled("div")({
display: "flex",
justifyContent: "space-between",
diff --git a/web/apps/photos/src/components/auth/styles.ts b/web/apps/photos/src/components/auth/styles.ts
index b2d4fe190c..9e490a6dbe 100644
--- a/web/apps/photos/src/components/auth/styles.ts
+++ b/web/apps/photos/src/components/auth/styles.ts
@@ -15,6 +15,17 @@ export const authColorVariables = {
"--photos-auth-fill-hover": "#dedede",
"--photos-auth-fill-active": "#d2d2d2",
"--photos-auth-stroke": "#e0e0e0",
+ "--photos-auth-button-secondary": "#eaeaea",
+ "--photos-auth-button-secondary-hover": "#dedede",
+ "--photos-auth-button-secondary-active": "#d2d2d2",
+ "--photos-auth-button-secondary-stroke": "transparent",
+ "--photos-auth-button-secondary-stroke-hover": "transparent",
+ "--photos-auth-button-secondary-stroke-active": "transparent",
+ "--photos-auth-button-primary-stroke": "rgba(255, 255, 255, 0.14)",
+ "--photos-auth-button-primary-stroke-hover":
+ "rgba(255, 255, 255, 0.32)",
+ "--photos-auth-button-primary-stroke-active":
+ "rgba(255, 255, 255, 0.2)",
},
"*:where(.dark)": {
"--photos-auth-success": "#08c225",
@@ -26,6 +37,14 @@ export const authColorVariables = {
"--photos-auth-fill-hover": "#1a1a1a",
"--photos-auth-fill-active": "#292929",
"--photos-auth-stroke": "#3e3e3e",
+ "--photos-auth-button-secondary": "#1e1e1e",
+ "--photos-auth-button-secondary-hover": "#1a1a1a",
+ "--photos-auth-button-secondary-active": "#161616",
+ "--photos-auth-button-secondary-stroke": "rgba(255, 255, 255, 0.07)",
+ "--photos-auth-button-secondary-stroke-hover":
+ "rgba(255, 255, 255, 0.18)",
+ "--photos-auth-button-secondary-stroke-active":
+ "rgba(255, 255, 255, 0.12)",
},
};
@@ -55,3 +74,14 @@ export const authMiniTypography = {
fontWeight: 500,
lineHeight: "16px",
};
+
+/**
+ * The column layout for an {@link AuthDialog}'s content. Apply to the direct
+ * child that holds the dialog's sections (header, fields, buttons).
+ */
+export const authDialogContentLayout = {
+ display: "flex",
+ flexDirection: "column",
+ gap: "24px",
+ [authMobileMediaQuery]: { gap: "20px" },
+} as const;
diff --git a/web/apps/photos/src/pages/index.tsx b/web/apps/photos/src/pages/index.tsx
index c769f87b47..7fb6abfa20 100644
--- a/web/apps/photos/src/pages/index.tsx
+++ b/web/apps/photos/src/pages/index.tsx
@@ -1,3 +1,4 @@
+import { DevSettingsDialog } from "@/components/auth/DevSettingsDialog";
import { LoginForm } from "@/components/auth/LoginForm";
import { SignUpForm } from "@/components/auth/SignUpForm";
import { PhotosAuthShell } from "@/components/PhotosAuthShell";
@@ -233,7 +234,15 @@ const TappableContainer: React.FC<
]}
onClick={handleClick}
>
- <DevSettings open={showDevSettings} onClose={handleClose} />
+ <DevSettings
+ open={showDevSettings}
+ onClose={handleClose}
+ presentation={
+ featureFlags.enableNewPhotosAuthFlow
+ ? DevSettingsDialog
+ : undefined
+ }
+ />
{children}
</CenteredFill>
);
diff --git a/web/packages/new/photos/components/DevSettings.tsx b/web/packages/new/photos/components/DevSettings.tsx
index 6ea667b219..0f8eae9ea2 100644
--- a/web/packages/new/photos/components/DevSettings.tsx
+++ b/web/packages/new/photos/components/DevSettings.tsx
@@ -24,16 +24,39 @@ import { SlideUpTransition } from "./mui/SlideUpTransition";
interface DevSettingsProps {
open: boolean;
onClose: () => void;
+ presentation?: React.ComponentType<DevSettingsPresentationProps>;
}
-export const DevSettings: React.FC<DevSettingsProps> = ({ open, onClose }) => {
+export interface DevSettingsPresentationProps {
+ open: boolean;
+ onDialogClose: ModalProps["onClose"];
+ value: string;
+ onChange: React.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>;
+ onBlur: React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
+ error?: string;
+ isChecking: boolean;
+ canSave: boolean;
+ onSubmit: React.SubmitEventHandler<HTMLFormElement>;
+ onClose: () => void;
+}
+
+export const DevSettings: React.FC<DevSettingsProps> = ({
+ open,
+ onClose,
+ presentation,
+}) => {
const fullScreen = useIsSmallWidth();
const handleDialogClose: ModalProps["onClose"] = (_, reason: string) => {
if (reason != "backdropClick") onClose();
};
- return (
+ return presentation ? (
+ <Contents
+ {...{ open, onClose, presentation }}
+ onDialogClose={handleDialogClose}
+ />
+ ) : (
<Dialog
{...{ open, fullScreen }}
onClose={handleDialogClose}
@@ -41,12 +64,15 @@ export const DevSettings: React.FC<DevSettingsProps> = ({ open, onClose }) => {
maxWidth="xs"
fullWidth
>
- <Contents {...{ onClose }} />
+ <Contents {...{ open, onClose }} />
</Dialog>
);
};
-type ContentsProps = Pick<DevSettingsProps, "onClose">;
+type ContentsProps = Pick<
+ DevSettingsProps,
+ "open" | "onClose" | "presentation"
+> & { onDialogClose?: ModalProps["onClose"] };
const Contents: React.FC<ContentsProps> = (props) => {
// This boundary reloads the stored origin on every dialog open.
@@ -55,11 +81,20 @@ const Contents: React.FC<ContentsProps> = (props) => {
string | undefined
>();
- useEffect(
- () =>
- void getKVS("apiOrigin").then((o) => setInitialAPIOrigin(o ?? "")),
- [],
- );
+ useEffect(() => {
+ if (!props.open) {
+ setInitialAPIOrigin(undefined);
+ return;
+ }
+
+ let cancelled = false;
+ void getKVS("apiOrigin").then((origin) => {
+ if (!cancelled) setInitialAPIOrigin(origin ?? "");
+ });
+ return () => {
+ cancelled = true;
+ };
+ }, [props.open]);
if (initialAPIOrigin === undefined) return <></>;
@@ -68,22 +103,27 @@ const Contents: React.FC<ContentsProps> = (props) => {
type FormProps = ContentsProps & { initialAPIOrigin: string };
-const Form: React.FC<FormProps> = ({ initialAPIOrigin, onClose }) => {
+const Form: React.FC<FormProps> = ({
+ open,
+ initialAPIOrigin,
+ onClose,
+ onDialogClose,
+ presentation: Presentation,
+}) => {
const formik = useFormik({
initialValues: { apiOrigin: initialAPIOrigin },
validate: ({ apiOrigin }) => {
- try {
- // Constructing the URL performs validation.
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
- apiOrigin && new URL(apiOrigin);
- } catch {
+ if (apiOrigin && !isValidEndpoint(apiOrigin, !!Presentation)) {
return { apiOrigin: "Invalid endpoint" };
}
return {};
},
onSubmit: async (values, { setSubmitting, setErrors }) => {
+ const apiOrigin = Presentation
+ ? values.apiOrigin.trim()
+ : values.apiOrigin;
try {
- await updateAPIOrigin(values.apiOrigin);
+ await updateAPIOrigin(apiOrigin);
} catch (e) {
setErrors({
apiOrigin: e instanceof Error ? e.message : String(e),
@@ -97,10 +137,32 @@ const Form: React.FC<FormProps> = ({ initialAPIOrigin, onClose }) => {
});
// Auto-focus marks this field touched before submission.
- const hasError =
- formik.submitCount > 0 &&
+ const hasError = Boolean(
+ (Presentation || formik.submitCount > 0) &&
formik.touched.apiOrigin &&
- !!formik.errors.apiOrigin;
+ formik.errors.apiOrigin,
+ );
+
+ if (Presentation) {
+ const trimmedValue = formik.values.apiOrigin.trim();
+ const canSave =
+ !formik.isSubmitting &&
+ (!trimmedValue || isValidEndpoint(trimmedValue, true)) &&
+ !(trimmedValue == "" && initialAPIOrigin == "");
+
+ return (
+ <Presentation
+ {...{ open, canSave, onClose }}
+ onDialogClose={onDialogClose}
+ value={formik.values.apiOrigin}
+ onChange={formik.handleChange}
+ onBlur={formik.handleBlur}
+ error={hasError ? String(formik.errors.apiOrigin) : undefined}
+ isChecking={formik.isSubmitting}
+ onSubmit={formik.handleSubmit}
+ />
+ );
+ }
return (
<form onSubmit={formik.handleSubmit}>
@@ -163,6 +225,15 @@ const Form: React.FC<FormProps> = ({ initialAPIOrigin, onClose }) => {
);
};
+const isValidEndpoint = (origin: string, httpOnly: boolean) => {
+ try {
+ const { protocol } = new URL(origin);
+ return !httpOnly || protocol == "http:" || protocol == "https:";
+ } catch {
+ return false;
+ }
+};
+
const updateAPIOrigin = async (origin: string) => {
if (!origin) {
await removeKV("apiOrigin");