Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

feat(app): split the auth card with a branded panel and backdrop

Hampuse06c96c36c2c
diff --git a/fluxer_app/src/features/app/components/layout/AuthLayout.module.css b/fluxer_app/src/features/app/components/layout/AuthLayout.module.css
index 2ccfa52b4..4e0f0ac26 100644
--- a/fluxer_app/src/features/app/components/layout/AuthLayout.module.css
+++ b/fluxer_app/src/features/app/components/layout/AuthLayout.module.css
@@ -3,8 +3,8 @@
.topDragRegion {
position: fixed;
top: 0;
- left: 0;
- right: 0;
+ inset-inline-start: 0;
+ inset-inline-end: 0;
height: var(--layout-header-height);
z-index: var(--z-index-titlebar);
pointer-events: none;
@@ -17,8 +17,8 @@
.nagbarHost {
position: fixed;
top: 0;
- left: 0;
- right: 0;
+ inset-inline-start: 0;
+ inset-inline-end: 0;
z-index: var(--z-index-titlebar);
}
@@ -26,9 +26,7 @@
position: fixed;
inset: 0;
display: flex;
- background:
- radial-gradient(ellipse 54rem 30rem at 50% -8%, rgb(138 98 209 / 0.18), transparent 68%),
- linear-gradient(145deg, #05040d 0%, #080616 48%, #0d0a1c 100%);
+ background: linear-gradient(145deg, #05040d 0%, #080616 48%, #0d0a1c 100%);
}
.container {
@@ -129,15 +127,47 @@
inset: 0;
}
-.patternHost {
- position: fixed;
+.operatorBackdrop {
+ z-index: 1;
+}
+
+.backdropLayer {
+ position: absolute;
inset: 0;
- opacity: 0.06;
- pointer-events: none;
- z-index: 0;
- background-repeat: repeat;
- background-size: 16.25rem 16.25rem;
- filter: invert(1);
+ opacity: 0;
+ transition: opacity 240ms ease;
+}
+
+.backdropLayerReady {
+ opacity: 1;
+}
+
+.backdropImage {
+ position: absolute;
+ inset: 0;
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+}
+
+.backdropScrim {
+ position: absolute;
+ inset: 0;
+ background-color: rgb(5 4 13 / 0.55);
+}
+
+.backdropScrimMobile {
+ background-color: rgb(5 4 13 / 0.75);
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .backdropLayer {
+ transition: none;
+ }
+}
+
+:global(html.reduced-motion) .backdropLayer {
+ transition: none;
}
.cardContainer {
@@ -157,11 +187,12 @@
flex: 0 1 auto;
min-height: 0;
padding: 0;
- width: min(100%, 38rem);
+ width: min(100%, 50rem);
max-width: 100%;
}
.card {
+ --auth-card-padding: clamp(2rem, 4vw, 2.75rem);
position: relative;
margin: 0;
display: flex;
@@ -180,28 +211,56 @@
}
.cardStandard {
+ --auth-card-padding: 2.5rem;
max-width: 32rem;
}
.cardCompact {
+ --auth-card-padding: 2rem;
max-width: 27rem;
}
+.cardBranded {
+ flex-direction: column;
+}
+
.formSide {
display: flex;
width: 100%;
+ min-width: 0;
+ flex: 1 1 auto;
flex-direction: column;
justify-content: center;
- padding: clamp(2rem, 4vw, 2.75rem);
+ padding: var(--auth-card-padding);
background: var(--background-secondary);
}
-.formSideStandard {
- padding: 2.5rem;
+.cardBranded .formSide {
+ padding-block-start: 1.25rem;
+}
+
+@media (min-width: 55rem) {
+ .cardSplit {
+ flex-direction: row;
+ max-width: 50rem;
+ min-height: 28rem;
+ }
+
+ .cardSplit.cardCompact {
+ max-width: 45rem;
+ }
+
+ .cardSplit .formSide {
+ position: relative;
+ width: auto;
+ padding-block-start: var(--auth-card-padding);
+ }
}
-.formSideCompact {
- padding: 2rem;
+@media (min-width: 55rem) and (max-height: 40rem) {
+ .cardSplit {
+ min-height: auto;
+ }
}
@media (prefers-reduced-motion: reduce) {
@@ -219,13 +278,8 @@
padding: 1rem;
}
- .formSide {
- padding: 1.5rem;
- }
-
- .formSideStandard,
- .formSideCompact {
- padding: 1.5rem;
+ .card {
+ --auth-card-padding: 1.5rem;
}
}
@@ -233,10 +287,7 @@
composes: starfield from '@app/features/ui/space_background/SpaceBackground.module.css';
--starfield-position: fixed;
min-height: 100dvh;
- background:
- radial-gradient(ellipse 28rem 18rem at 32% 0%, rgb(122 87 191 / 0.16), transparent 74%),
- radial-gradient(ellipse 22rem 18rem at 88% 92%, rgb(91 65 151 / 0.12), transparent 72%),
- linear-gradient(145deg, #05040d 0%, #080616 46%, #0d0a1c 100%);
+ background: linear-gradient(145deg, #05040d 0%, #080616 46%, #0d0a1c 100%);
padding: calc(2rem + env(safe-area-inset-top, 0px)) 1.5rem calc(2.5rem + env(safe-area-inset-bottom, 0px));
overflow-y: auto;
overflow-x: hidden;
@@ -246,8 +297,8 @@
.mobileContent {
position: relative;
z-index: 1;
- margin-left: auto;
- margin-right: auto;
+ margin-inline-start: auto;
+ margin-inline-end: auto;
width: 100%;
max-width: 28rem;
}
@@ -284,6 +335,26 @@
.alignRight .cardContainer {
justify-content: flex-end;
}
+
+ :global(html[dir='rtl']) .leftSplit.alignLeft {
+ align-items: flex-end;
+ }
+
+ :global(html[dir='rtl']) .alignLeft .leftSplitWrapper,
+ :global(html[dir='rtl']) .alignLeft .leftSplitAnimated,
+ :global(html[dir='rtl']) .alignLeft .cardContainer {
+ justify-content: flex-end;
+ }
+
+ :global(html[dir='rtl']) .leftSplit.alignRight {
+ align-items: flex-start;
+ }
+
+ :global(html[dir='rtl']) .alignRight .leftSplitWrapper,
+ :global(html[dir='rtl']) .alignRight .leftSplitAnimated,
+ :global(html[dir='rtl']) .alignRight .cardContainer {
+ justify-content: flex-start;
+ }
}
:global(html:not(.auth-page) body),
diff --git a/fluxer_app/src/features/app/components/layout/AuthLayout.tsx b/fluxer_app/src/features/app/components/layout/AuthLayout.tsx
index 29be9e228..26f097425 100644
--- a/fluxer_app/src/features/app/components/layout/AuthLayout.tsx
+++ b/fluxer_app/src/features/app/components/layout/AuthLayout.tsx
@@ -2,14 +2,12 @@
import i18n, {initI18n, isI18nInitialized} from '@app/app/I18n';
import styles from '@app/features/app/components/layout/AuthLayout.module.css';
-import {CorruptedInstallationNagbar} from '@app/features/app/components/layout/app_layout/nagbars/CorruptedInstallationNagbar';
-import {NativeDragRegion} from '@app/features/app/components/layout/NativeDragRegion';
-import {NativeTitlebar} from '@app/features/app/components/layout/NativeTitlebar';
+import {AuthShell, resolveLayoutAuthBrand, useAuthLayoutVariant} from '@app/features/app/components/layout/AuthShell';
import {AuthShellHintKind, useAuthShellHintCapture} from '@app/features/app/components/skeleton/AuthShellHint';
-import {useNativePlatform} from '@app/features/app/hooks/useNativePlatform';
-import {useSetLayoutVariant} from '@app/features/app/state/LayoutVariantContext';
+import RuntimeConfig from '@app/features/app/state/RuntimeConfig';
+import type {RuntimeConfigSnapshot} from '@app/features/app/state/RuntimeConfigSnapshot';
+import {AuthBrandLayout, AuthBrandPanel, useAuthBrandLogo} from '@app/features/auth/components/AuthBrandPanel';
import {AccountRestrictionGate} from '@app/features/auth/flow/AccountRestrictionScreen';
-import {AuthBackground} from '@app/features/auth/flow/AuthBackground';
import {AuthCardContainer} from '@app/features/auth/flow/AuthCardContainer';
import {AuthRuntimeTargetBoundary} from '@app/features/auth/flow/AuthRuntimeTargetBoundary';
import {AuthSurfaceMotionKind, AuthSurfaceTransition} from '@app/features/auth/flow/AuthSurfaceTransition';
@@ -23,11 +21,8 @@ import {
import {AuthRegisterDraftContext, useAuthRegisterDraft} from '@app/features/auth/state/AuthRegisterDraftContext';
import {AppI18nProvider} from '@app/features/i18n/components/AppI18nProvider';
import {useLocation} from '@app/features/platform/components/router/RouterReact';
-import {Scroller, type ScrollerHandle} from '@app/features/ui/components/Scroller';
+import type {ScrollerHandle} from '@app/features/ui/components/Scroller';
import {isMobileExperienceEnabled} from '@app/features/ui/utils/MobileExperience';
-import {hasUnavailableElectronNativeContext} from '@app/features/ui/utils/NativeUtils';
-import {useNativeTitleBar} from '@app/features/window/hooks/useNativeTitleBar';
-import {flxElementClassName} from '@app/lib/react';
import type {GuildSplashCardAlignmentValue} from '@fluxer/constants/src/GuildConstants';
import {GuildSplashCardAlignment} from '@fluxer/constants/src/GuildConstants';
import clsx from 'clsx';
@@ -44,6 +39,8 @@ import {
useState,
} from 'react';
+const SPLIT_CARD_MEDIA_QUERY = '(min-width: 55rem)';
+
interface ResolveAuthLayoutContentModeRequest {
current: AuthLayoutContentMode | null;
value: SetStateAction<AuthLayoutContentMode>;
@@ -64,15 +61,20 @@ function resolveAuthLayoutContentMode({current, value}: ResolveAuthLayoutContent
return value;
}
+function isWideAuthViewport(): boolean {
+ return typeof window.matchMedia === 'function' && window.matchMedia(SPLIT_CARD_MEDIA_QUERY).matches;
+}
+
const AuthLayoutContent = observer(function AuthLayoutContent({children}: {children?: ReactNode}) {
const [splashUrl, setSplashUrl] = useState<string | null>(null);
+ const [brandSnapshot, setBrandSnapshot] = useState<RuntimeConfigSnapshot | null>(() =>
+ RuntimeConfig.getSnapshotOrNull(),
+ );
const [cardVariant, setCardVariant] = useState<AuthCardVariant>('default');
const [contentMode, setContentMode] = useState<AuthLayoutContentMode | null>(null);
const [splashAlignment, setSplashAlignment] = useState<GuildSplashCardAlignmentValue>(
GuildSplashCardAlignment.CENTER,
);
- const {isNative, platform} = useNativePlatform();
- const useSystemTitleBar = useNativeTitleBar();
const splashUrlRef = useRef<string | null>(null);
const scrollerRef = useRef<ScrollerHandle>(null);
const mainRef = useRef<HTMLElement>(null);
@@ -89,12 +91,6 @@ const AuthLayoutContent = observer(function AuthLayoutContent({children}: {child
},
[setSplashAlignment],
);
- useEffect(() => {
- document.documentElement.classList.add('auth-page');
- return () => {
- document.documentElement.classList.remove('auth-page');
- };
- }, []);
useEffect(() => {
scrollerRef.current?.jumpToStartEdge();
}, [location.pathname]);
@@ -107,6 +103,7 @@ const AuthLayoutContent = observer(function AuthLayoutContent({children}: {child
const authLayoutContextValue = useMemo<AuthLayoutContextType>(
() => ({
setSplashUrl: handleSetSplashUrl,
+ setBrandSnapshot,
setCardVariant,
setContentMode: handleSetContentMode,
setSplashCardAlignment: setSplashAlignment,
@@ -115,11 +112,12 @@ const AuthLayoutContent = observer(function AuthLayoutContent({children}: {child
);
const authRegisterDraftContextValue = useAuthRegisterDraft();
const isMobileExperience = isMobileExperienceEnabled();
- const showCorruptedInstallationNagbar = hasUnavailableElectronNativeContext();
const isProbing = contentMode == null;
const resolvedMode = contentMode ?? AuthLayoutContentMode.CARD;
const surfaceKey = `${resolvedMode}:${location.pathname}`;
const isFullscreen = resolvedMode === AuthLayoutContentMode.FULL;
+ const brand = useMemo(() => resolveLayoutAuthBrand(brandSnapshot), [brandSnapshot]);
+ const {logo: brandLogo, onLogoError: handleBrandLogoError} = useAuthBrandLogo(brand);
const resolveAuthShellHintTarget = useCallback((): HTMLElement | null => {
const main = mainRef.current;
if (main == null || isMobileExperience || isFullscreen) {
@@ -132,167 +130,89 @@ const AuthLayoutContent = observer(function AuthLayoutContent({children}: {child
pathname: location.pathname,
mobile: isMobileExperience,
kind: isFullscreen ? AuthShellHintKind.FULL : AuthShellHintKind.CARD,
+ split: !isMobileExperience && !isFullscreen && brandLogo != null && isWideAuthViewport(),
resolveTarget: resolveAuthShellHintTarget,
});
- if (isMobileExperience) {
- return (
- <AuthRegisterDraftContext.Provider value={authRegisterDraftContextValue}>
- <AuthLayoutContext.Provider value={authLayoutContextValue}>
- <NativeDragRegion
- className={styles.topDragRegion}
- data-flx="app.auth-layout.auth-layout-content.top-drag-region"
- />
- {showCorruptedInstallationNagbar && (
- <flx-app-auth-layout-nagbar-host
- className={flxElementClassName(styles.nagbarHost)}
- data-flx="app.auth-layout.auth-layout-content.nagbar-host"
- >
- <CorruptedInstallationNagbar
- isMobile={true}
- data-flx="app.auth-layout.auth-layout-content.corrupted-installation-nagbar"
- />
- </flx-app-auth-layout-nagbar-host>
- )}
- <flx-app-auth-layout-scroller
- className={flxElementClassName(styles.scrollerWrapper)}
- data-flx="app.auth-layout.auth-layout-content.scroller-wrapper"
- >
- <Scroller
- ref={scrollerRef}
- className={styles.mobileContainer}
- fade={false}
- key="auth-layout-mobile-scroller"
- data-flx="app.auth-layout.auth-layout-content.mobile-container"
- >
- <flx-app-auth-layout-mobile-main
- ref={mainRef}
- id="main-content"
- className={flxElementClassName(styles.mobileContent)}
- tabIndex={-1}
- data-flx="app.auth-layout.auth-layout-content.main-content"
- >
- <AuthSurfaceTransition
- surfaceKey={surfaceKey}
- motionKind={authSurfaceMotionKind(resolvedMode)}
- suppressed={isProbing}
- anchorsContentOnInteraction={false}
- className={clsx(
- isProbing && styles.presentationProbe,
- !isProbing && isFullscreen && styles.mobileFullscreenContent,
- )}
- data-flx="app.auth-layout.auth-layout-content.auth-surface-transition"
- >
- {children}
- </AuthSurfaceTransition>
- </flx-app-auth-layout-mobile-main>
- </Scroller>
- </flx-app-auth-layout-scroller>
- </AuthLayoutContext.Provider>
- </AuthRegisterDraftContext.Provider>
- );
- }
return (
<AuthRegisterDraftContext.Provider value={authRegisterDraftContextValue}>
<AuthLayoutContext.Provider value={authLayoutContextValue}>
- <NativeDragRegion
- className={styles.topDragRegion}
- data-flx="app.auth-layout.auth-layout-content.top-drag-region--2"
- />
- {showCorruptedInstallationNagbar && (
- <flx-app-auth-layout-nagbar-host
- className={flxElementClassName(styles.nagbarHost)}
- data-flx="app.auth-layout.auth-layout-content.nagbar-host--2"
- >
- <CorruptedInstallationNagbar
- isMobile={false}
- data-flx="app.auth-layout.auth-layout-content.corrupted-installation-nagbar--2"
- />
- </flx-app-auth-layout-nagbar-host>
- )}
- <flx-app-auth-layout-scroller
- className={flxElementClassName(styles.scrollerWrapper)}
- data-flx="app.auth-layout.auth-layout-content.scroller-wrapper--2"
+ <AuthShell
+ mobile={isMobileExperience}
+ backdropUrl={brand?.backdropUrl ?? null}
+ splashUrl={splashUrl}
+ splashDimensions={isMobileExperience ? null : splashDimensions}
+ splashAlignment={splashAlignment}
+ scrollerRef={scrollerRef}
+ mainRef={mainRef}
+ data-flx="app.auth-layout.auth-layout-content.auth-shell"
>
- <Scroller
- ref={scrollerRef}
- className={styles.container}
- key="auth-layout-scroller"
- data-flx="app.auth-layout.auth-layout-content.container"
- >
- {isNative && !useSystemTitleBar && (
- <NativeTitlebar platform={platform} data-flx="app.auth-layout.auth-layout-content.native-titlebar" />
- )}
- <flx-app-auth-layout-backdrop
- className={flxElementClassName(styles.characterBackground)}
- data-flx="app.auth-layout.auth-layout-content.character-background"
- >
- <AuthBackground
- className={styles.splashBackdrop}
- splashUrl={splashUrl}
- splashDimensions={splashDimensions}
- splashAlignment={splashAlignment}
- data-flx="app.auth-layout.auth-layout-content.auth-background"
- />
- <flx-app-auth-layout-split
- className={flxElementClassName(
- styles.leftSplit,
- splashAlignment === GuildSplashCardAlignment.LEFT && styles.alignLeft,
- splashAlignment === GuildSplashCardAlignment.RIGHT && styles.alignRight,
+ {isMobileExperience ? (
+ <>
+ {brand == null || isFullscreen ? null : (
+ <AuthBrandPanel
+ brand={brand}
+ logo={brandLogo}
+ onLogoError={handleBrandLogoError}
+ layout={AuthBrandLayout.MOBILE}
+ data-flx="app.auth-layout.auth-layout-content.mobile-brand"
+ />
+ )}
+ <AuthSurfaceTransition
+ surfaceKey={surfaceKey}
+ motionKind={authSurfaceMotionKind(resolvedMode)}
+ suppressed={isProbing}
+ className={clsx(
+ isProbing && styles.presentationProbe,
+ !isProbing && isFullscreen && styles.mobileFullscreenContent,
)}
- data-flx="app.auth-layout.auth-layout-content.left-split"
+ data-flx="app.auth-layout.auth-layout-content.auth-surface-transition"
>
- <flx-app-auth-layout-split-column
- className={flxElementClassName(styles.leftSplitWrapper)}
- data-flx="app.auth-layout.auth-layout-content.left-split-wrapper"
- >
- <flx-app-auth-layout-main
- ref={mainRef}
- id="main-content"
- className={flxElementClassName(styles.leftSplitAnimated)}
- tabIndex={-1}
- data-flx="app.auth-layout.auth-layout-content.main-content--2"
- >
- <AuthSurfaceTransition
- surfaceKey={surfaceKey}
- motionKind={authSurfaceMotionKind(resolvedMode)}
- suppressed={isProbing}
- anchorsContentOnInteraction={!isFullscreen}
- className={clsx(
- isProbing && styles.presentationProbe,
- !isProbing && isFullscreen && styles.fullscreenContent,
- !isProbing && !isFullscreen && styles.cardMotionWrap,
- )}
- data-flx="app.auth-layout.auth-layout-content.auth-surface-transition--2"
- >
- <AuthCardContainer
- variant={cardVariant}
- presentation={resolvedMode}
- isInert={false}
- className={clsx(!isFullscreen && styles.cardContainerInMotion)}
- data-flx="app.auth-layout.auth-layout-content.auth-card-container"
- >
- {children}
- </AuthCardContainer>
- </AuthSurfaceTransition>
- </flx-app-auth-layout-main>
- </flx-app-auth-layout-split-column>
- </flx-app-auth-layout-split>
- </flx-app-auth-layout-backdrop>
- </Scroller>
- </flx-app-auth-layout-scroller>
+ {children}
+ </AuthSurfaceTransition>
+ </>
+ ) : (
+ <AuthSurfaceTransition
+ surfaceKey={surfaceKey}
+ motionKind={authSurfaceMotionKind(resolvedMode)}
+ suppressed={isProbing}
+ className={clsx(
+ isProbing && styles.presentationProbe,
+ !isProbing && isFullscreen && styles.fullscreenContent,
+ !isProbing && !isFullscreen && styles.cardMotionWrap,
+ )}
+ data-flx="app.auth-layout.auth-layout-content.auth-surface-transition--2"
+ >
+ <AuthCardContainer
+ variant={cardVariant}
+ presentation={resolvedMode}
+ isInert={false}
+ className={clsx(!isFullscreen && styles.cardContainerInMotion)}
+ isSplit={brandLogo != null}
+ brandPanel={
+ brand == null ? null : (
+ <AuthBrandPanel
+ brand={brand}
+ logo={brandLogo}
+ onLogoError={handleBrandLogoError}
+ layout={AuthBrandLayout.CARD}
+ data-flx="app.auth-layout.auth-layout-content.card-brand"
+ />
+ )
+ }
+ data-flx="app.auth-layout.auth-layout-content.auth-card-container"
+ >
+ {children}
+ </AuthCardContainer>
+ </AuthSurfaceTransition>
+ )}
+ </AuthShell>
</AuthLayoutContext.Provider>
</AuthRegisterDraftContext.Provider>
);
});
export const AuthLayout = observer(function AuthLayout({children}: {children?: ReactNode}) {
const [i18nReady, setI18nReady] = useState(isI18nInitialized);
- const setLayoutVariant = useSetLayoutVariant();
- useEffect(() => {
- setLayoutVariant('auth');
- return () => {
- setLayoutVariant('app');
- };
- }, [setLayoutVariant]);
+ useAuthLayoutVariant();
useEffect(() => {
if (i18nReady) {
return;
diff --git a/fluxer_app/src/features/app/components/layout/AuthShell.tsx b/fluxer_app/src/features/app/components/layout/AuthShell.tsx
new file mode 100644
index 000000000..3cf6751a4
--- /dev/null
+++ b/fluxer_app/src/features/app/components/layout/AuthShell.tsx
@@ -0,0 +1,181 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import styles from '@app/features/app/components/layout/AuthLayout.module.css';
+import {CorruptedInstallationNagbar} from '@app/features/app/components/layout/app_layout/nagbars/CorruptedInstallationNagbar';
+import {NativeDragRegion} from '@app/features/app/components/layout/NativeDragRegion';
+import {NativeTitlebar} from '@app/features/app/components/layout/NativeTitlebar';
+import {useNativePlatform} from '@app/features/app/hooks/useNativePlatform';
+import {runtimeConfigSnapshotsAreSameInstance} from '@app/features/app/state/InstanceSnapshotStore';
+import {useSetLayoutVariant} from '@app/features/app/state/LayoutVariantContext';
+import RuntimeConfig from '@app/features/app/state/RuntimeConfig';
+import type {RuntimeConfigSnapshot} from '@app/features/app/state/RuntimeConfigSnapshot';
+import {AuthBackdropScrim, AuthBackground} from '@app/features/auth/flow/AuthBackground';
+import {type AuthBrand, resolveAuthBrand} from '@app/features/auth/InstanceBranding';
+import {Scroller, type ScrollerHandle} from '@app/features/ui/components/Scroller';
+import {hasUnavailableElectronNativeContext, isDesktop} from '@app/features/ui/utils/NativeUtils';
+import {useNativeTitleBar} from '@app/features/window/hooks/useNativeTitleBar';
+import {flxElementClassName} from '@app/lib/react';
+import type {GuildSplashCardAlignmentValue} from '@fluxer/constants/src/GuildConstants';
+import {GuildSplashCardAlignment} from '@fluxer/constants/src/GuildConstants';
+import type {ReactNode, Ref} from 'react';
+import {useEffect, useLayoutEffect} from 'react';
+
+export function resolveLayoutAuthBrand(snapshot: RuntimeConfigSnapshot | null): AuthBrand | null {
+ if (snapshot == null) {
+ return null;
+ }
+ if (!isDesktop()) {
+ return resolveAuthBrand(snapshot, {isDocumentInstance: true, documentHost: window.location.host});
+ }
+ return resolveAuthBrand(snapshot, {
+ isDocumentInstance: runtimeConfigSnapshotsAreSameInstance(snapshot, RuntimeConfig.getSnapshotOrNull()),
+ documentHost: null,
+ });
+}
+
+export function useAuthLayoutVariant(): void {
+ const setLayoutVariant = useSetLayoutVariant();
+ useLayoutEffect(() => {
+ setLayoutVariant('auth');
+ return () => {
+ setLayoutVariant('app');
+ };
+ }, [setLayoutVariant]);
+}
+
+interface AuthShellProps {
+ mobile: boolean;
+ backdropUrl: string | null;
+ splashUrl?: string | null;
+ splashDimensions?: {width: number; height: number} | null;
+ splashAlignment?: GuildSplashCardAlignmentValue;
+ scrollerRef?: Ref<ScrollerHandle>;
+ mainRef?: Ref<HTMLElement>;
+ children?: ReactNode;
+}
+
+export function AuthShell({
+ mobile,
+ backdropUrl,
+ splashUrl = null,
+ splashDimensions = null,
+ splashAlignment = GuildSplashCardAlignment.CENTER,
+ scrollerRef,
+ mainRef,
+ children,
+}: AuthShellProps) {
+ const {isNative, platform} = useNativePlatform();
+ const useSystemTitleBar = useNativeTitleBar();
+ const showCorruptedInstallationNagbar = hasUnavailableElectronNativeContext();
+ useEffect(() => {
+ document.documentElement.classList.add('auth-page');
+ return () => {
+ document.documentElement.classList.remove('auth-page');
+ };
+ }, []);
+ const chrome = (
+ <>
+ <NativeDragRegion className={styles.topDragRegion} data-flx="app.auth-shell.top-drag-region" />
+ {showCorruptedInstallationNagbar && (
+ <flx-app-auth-layout-nagbar-host
+ className={flxElementClassName(styles.nagbarHost)}
+ data-flx="app.auth-shell.nagbar-host"
+ >
+ <CorruptedInstallationNagbar isMobile={mobile} data-flx="app.auth-shell.corrupted-installation-nagbar" />
+ </flx-app-auth-layout-nagbar-host>
+ )}
+ </>
+ );
+ if (mobile) {
+ return (
+ <>
+ {chrome}
+ <flx-app-auth-layout-scroller
+ className={flxElementClassName(styles.scrollerWrapper)}
+ data-flx="app.auth-shell.scroller-wrapper"
+ >
+ <Scroller
+ ref={scrollerRef}
+ className={styles.mobileContainer}
+ fade={false}
+ key="auth-layout-mobile-scroller"
+ data-flx="app.auth-shell.mobile-container"
+ >
+ <AuthBackground
+ className={styles.splashBackdrop}
+ splashUrl={splashUrl}
+ backdropUrl={backdropUrl}
+ backdropScrim={AuthBackdropScrim.MOBILE}
+ data-flx="app.auth-shell.mobile-auth-background"
+ />
+ <flx-app-auth-layout-mobile-main
+ ref={mainRef}
+ id="main-content"
+ className={flxElementClassName(styles.mobileContent)}
+ tabIndex={-1}
+ data-flx="app.auth-shell.mobile-main"
+ >
+ {children}
+ </flx-app-auth-layout-mobile-main>
+ </Scroller>
+ </flx-app-auth-layout-scroller>
+ </>
+ );
+ }
+ return (
+ <>
+ {chrome}
+ <flx-app-auth-layout-scroller
+ className={flxElementClassName(styles.scrollerWrapper)}
+ data-flx="app.auth-shell.scroller-wrapper--2"
+ >
+ <Scroller
+ ref={scrollerRef}
+ className={styles.container}
+ key="auth-layout-scroller"
+ data-flx="app.auth-shell.container"
+ >
+ {isNative && !useSystemTitleBar && (
+ <NativeTitlebar platform={platform} data-flx="app.auth-shell.native-titlebar" />
+ )}
+ <flx-app-auth-layout-backdrop
+ className={flxElementClassName(styles.characterBackground)}
+ data-flx="app.auth-shell.character-background"
+ >
+ <AuthBackground
+ className={styles.splashBackdrop}
+ splashUrl={splashUrl}
+ splashDimensions={splashDimensions}
+ splashAlignment={splashAlignment}
+ backdropUrl={backdropUrl}
+ data-flx="app.auth-shell.auth-background"
+ />
+ <flx-app-auth-layout-split
+ className={flxElementClassName(
+ styles.leftSplit,
+ splashAlignment === GuildSplashCardAlignment.LEFT && styles.alignLeft,
+ splashAlignment === GuildSplashCardAlignment.RIGHT && styles.alignRight,
+ )}
+ data-flx="app.auth-shell.left-split"
+ >
+ <flx-app-auth-layout-split-column
+ className={flxElementClassName(styles.leftSplitWrapper)}
+ data-flx="app.auth-shell.left-split-wrapper"
+ >
+ <flx-app-auth-layout-main
+ ref={mainRef}
+ id="main-content"
+ className={flxElementClassName(styles.leftSplitAnimated)}
+ tabIndex={-1}
+ data-flx="app.auth-shell.main-content"
+ >
+ {children}
+ </flx-app-auth-layout-main>
+ </flx-app-auth-layout-split-column>
+ </flx-app-auth-layout-split>
+ </flx-app-auth-layout-backdrop>
+ </Scroller>
+ </flx-app-auth-layout-scroller>
+ </>
+ );
+}
diff --git a/fluxer_app/src/features/app/components/skeleton/AuthShellHint.ts b/fluxer_app/src/features/app/components/skeleton/AuthShellHint.ts
index 9f3e39ec5..fbee69ae8 100644
--- a/fluxer_app/src/features/app/components/skeleton/AuthShellHint.ts
+++ b/fluxer_app/src/features/app/components/skeleton/AuthShellHint.ts
@@ -5,10 +5,13 @@ import {
readRawStorageItem,
writeRawStorageItem,
} from '@app/features/platform/state/PrebootMirror';
+import {Logger} from '@app/features/platform/utils/AppLogger';
import {getRemScaleForDocument} from '@app/features/theme/layout/RemFromPx';
+import {isObjectLike} from '@fluxer/record_utils/src/RecordGuards';
import {useEffect} from 'react';
-export const AUTH_SHELL_HINT_VERSION = 1;
+const logger = new Logger('AuthShellHint');
+const AUTH_SHELL_HINT_VERSION = 2;
export const AuthShellHintKind = Object.freeze({
CARD: 'card',
@@ -17,20 +20,22 @@ export const AuthShellHintKind = Object.freeze({
export type AuthShellHintKind = (typeof AuthShellHintKind)[keyof typeof AuthShellHintKind];
-export interface AuthShellHintEntry {
+interface AuthShellHintEntry {
readonly t: number;
readonly mo: number;
readonly k: AuthShellHintKind;
readonly h: number;
readonly w: number;
+ readonly s: 0 | 1;
}
-export interface AuthShellHintMeasurement {
+interface AuthShellHintMeasurement {
readonly pathname: string;
readonly mobile: boolean;
readonly kind: AuthShellHintKind;
readonly heightPx: number;
readonly widthPx: number;
+ readonly split: boolean;
}
const MAX_CATEGORIES = 12;
@@ -38,15 +43,20 @@ const MAX_MEASURED_PX = 4000;
const SETTLE_MS = 400;
const LOADING_SELECTOR =
'[data-flx="auth.flow.auth-loading-state.loading-container"],[data-flx^="auth.flow.auth-shell-loading-state."]';
+const NARROW_BRAND_META_SELECTOR = 'meta[name="fluxer-auth-card"][content="narrow"]';
const LOGIN_PATHS = new Set(['/', '/app', '/login', '/bookmarks', '/mentions', '/notifications', '/you']);
const LINK_PAGE_PATTERN = /^\/(invite|gift|theme)\/[^/]+(\/login)?\/?$/u;
const ACCOUNT_PAGE_PATTERN = /^\/(forgot|reset|verify|authorize-ip|wasntme)(\/|$)/u;
+const HANDOFF_PAGE_PATTERN = /^\/channels\/@(start|checkout)(\/|$)/u;
const capturedCategories = new Set<string>();
export function resolveAuthShellCategory(pathname: string): string | null {
if (pathname === '/register') {
return 'register';
}
+ if (HANDOFF_PAGE_PATTERN.test(pathname)) {
+ return null;
+ }
if (LOGIN_PATHS.has(pathname) || pathname.startsWith('/channels/')) {
return 'login';
}
@@ -58,32 +68,31 @@ export function resolveAuthShellCategory(pathname: string): string | null {
return accountPage == null ? null : accountPage[1];
}
-function isEntry(value: unknown): value is AuthShellHintEntry {
- if (value == null || typeof value !== 'object') {
+function isEntry(entry: unknown): entry is AuthShellHintEntry {
+ if (!isObjectLike(entry)) {
return false;
}
- const entry = value as Record<string, unknown>;
return (
typeof entry.t === 'number' &&
typeof entry.h === 'number' &&
typeof entry.w === 'number' &&
(entry.mo === 0 || entry.mo === 1) &&
+ (entry.s === 0 || entry.s === 1) &&
(entry.k === AuthShellHintKind.CARD || entry.k === AuthShellHintKind.FULL)
);
}
-export function readAuthShellHintEntries(): Map<string, AuthShellHintEntry> {
+function readAuthShellHintEntries(): Map<string, AuthShellHintEntry> {
const entries = new Map<string, AuthShellHintEntry>();
const raw = readRawStorageItem(AUTH_SHELL_HINT_STORAGE_KEY);
if (raw == null) {
return entries;
}
try {
- const parsed: unknown = JSON.parse(raw);
- if (parsed == null || typeof parsed !== 'object') {
+ const record: unknown = JSON.parse(raw);
+ if (!isObjectLike(record)) {
return entries;
}
- const record = parsed as {v?: unknown; c?: unknown};
if (record.v !== AUTH_SHELL_HINT_VERSION || record.c == null || typeof record.c !== 'object') {
return entries;
}
@@ -92,7 +101,10 @@ export function readAuthShellHintEntries(): Map<string, AuthShellHintEntry> {
entries.set(category, entry);
}
}
- } catch {
+ } catch (error) {
+ if (!(error instanceof SyntaxError)) {
+ logger.warn('Failed to read auth shell hints', error);
+ }
return entries;
}
return entries;
@@ -104,13 +116,16 @@ export interface AuthShellPlaceholder {
readonly heightPx: number;
readonly widthPx: number;
readonly rows: number;
+ readonly split: boolean;
readonly source: 'hint' | 'default';
}
-export interface AuthShellPlaceholderEnvironment {
+interface AuthShellPlaceholderEnvironment {
readonly mobile: boolean;
readonly native: boolean;
readonly passkeyLikely: boolean;
+ readonly wide: boolean;
+ readonly narrowBrand: boolean;
}
const LOGIN_CARD_HEIGHT_PX = 214;
@@ -120,37 +135,62 @@ const REGISTER_CARD_HEIGHT_PX = 674;
const REGISTER_MOBILE_HEIGHT_PX = 592;
const GENERIC_CARD_HEIGHT_PX = 402;
const GENERIC_MOBILE_HEIGHT_PX = 320;
+const SPLIT_CARD_MIN_HEIGHT_PX = 448;
+export const BRAND_ROW_CARD_PX = 44;
+export const BRAND_ROW_MOBILE_PX = 64;
const MIN_HINT_HEIGHT_PX = 48;
const MAX_HINT_WIDTH_PX = 1200;
-export function resolveDefaultAuthShellPlaceholder(
+function resolveDefaultAuthShellPlaceholder(
category: string,
environment: AuthShellPlaceholderEnvironment,
): AuthShellPlaceholder {
const {mobile} = environment;
if (category === 'login' && !mobile && environment.native) {
- return {category, kind: AuthShellHintKind.FULL, heightPx: 0, widthPx: 0, rows: -1, source: 'default'};
+ return {
+ category,
+ kind: AuthShellHintKind.FULL,
+ heightPx: 0,
+ widthPx: 0,
+ rows: -1,
+ split: false,
+ source: 'default',
+ };
}
+ const split = !mobile && environment.wide && !environment.narrowBrand;
+ const brandedHeightPx = (contentHeightPx: number): number => {
+ if (mobile) {
+ return contentHeightPx + BRAND_ROW_MOBILE_PX;
+ }
+ return split ? Math.max(contentHeightPx, SPLIT_CARD_MIN_HEIGHT_PX) : contentHeightPx + BRAND_ROW_CARD_PX;
+ };
if (category === 'login') {
const passkeyRow = environment.passkeyLikely ? LOGIN_PASSKEY_ROW_PX : 0;
return {
category,
kind: AuthShellHintKind.CARD,
- heightPx: (mobile ? LOGIN_MOBILE_HEIGHT_PX : LOGIN_CARD_HEIGHT_PX) + passkeyRow,
+ heightPx: brandedHeightPx((mobile ? LOGIN_MOBILE_HEIGHT_PX : LOGIN_CARD_HEIGHT_PX) + passkeyRow),
widthPx: 0,
rows: environment.passkeyLikely ? 3 : 2,
+ split,
source: 'default',
};
}
- const heightPx =
- category === 'register'
- ? mobile
- ? REGISTER_MOBILE_HEIGHT_PX
- : REGISTER_CARD_HEIGHT_PX
- : mobile
- ? GENERIC_MOBILE_HEIGHT_PX
- : GENERIC_CARD_HEIGHT_PX;
- return {category, kind: AuthShellHintKind.CARD, heightPx, widthPx: 0, rows: -1, source: 'default'};
+ let heightPx = GENERIC_CARD_HEIGHT_PX;
+ if (category === 'register') {
+ heightPx = mobile ? REGISTER_MOBILE_HEIGHT_PX : REGISTER_CARD_HEIGHT_PX;
+ } else if (mobile) {
+ heightPx = GENERIC_MOBILE_HEIGHT_PX;
+ }
+ return {
+ category,
+ kind: AuthShellHintKind.CARD,
+ heightPx: brandedHeightPx(heightPx),
+ widthPx: 0,
+ rows: -1,
+ split,
+ source: 'default',
+ };
}
function clampPlaceholderPx(value: number, min: number, max: number): number {
@@ -167,28 +207,38 @@ export function resolveAuthShellPlaceholder(
}
const entry = readAuthShellHintEntries().get(category);
if (entry != null && entry.mo === (environment.mobile ? 1 : 0) && entry.h > 0) {
+ const kind = entry.k;
+ const heightPx = clampPlaceholderPx(entry.h, MIN_HINT_HEIGHT_PX, MAX_MEASURED_PX);
+ const widthPx = clampPlaceholderPx(entry.w, 0, MAX_HINT_WIDTH_PX);
+ let rows = -1;
+ if (category === 'login') {
+ rows = environment.passkeyLikely ? 3 : 2;
+ }
return {
category,
- kind: entry.k,
- heightPx: clampPlaceholderPx(entry.h, MIN_HINT_HEIGHT_PX, MAX_MEASURED_PX),
- widthPx: clampPlaceholderPx(entry.w, 0, MAX_HINT_WIDTH_PX),
- rows: -1,
+ kind,
+ heightPx,
+ widthPx,
+ rows,
+ split: entry.s === 1 && !environment.mobile && environment.wide,
source: 'hint',
};
}
return resolveDefaultAuthShellPlaceholder(category, environment);
}
-export function isPasskeyLikelyForDocumentHost(host: string, publicKeyCredentialAvailable: boolean): boolean {
+function isPasskeyLikelyForDocumentHost(host: string, publicKeyCredentialAvailable: boolean): boolean {
return publicKeyCredentialAvailable && host.split('.').length >= 2 && !/^[\d.]+$/u.test(host) && !host.includes(':');
}
export function readAuthShellPlaceholderEnvironment(mobile: boolean): AuthShellPlaceholderEnvironment {
- const publicKeyCredential = (window as {PublicKeyCredential?: unknown}).PublicKeyCredential;
+ const publicKeyCredential = window.PublicKeyCredential;
return {
mobile,
native: document.documentElement.classList.contains('platform-native'),
passkeyLikely: isPasskeyLikelyForDocumentHost(window.location.hostname, typeof publicKeyCredential === 'function'),
+ wide: typeof window.matchMedia === 'function' && window.matchMedia('(min-width: 55rem)').matches,
+ narrowBrand: document.querySelector(NARROW_BRAND_META_SELECTOR) !== null,
};
}
@@ -199,7 +249,8 @@ function clampMeasuredPx(value: number): number {
return Math.min(MAX_MEASURED_PX, Math.max(0, Math.round(value)));
}
-export function recordAuthShellHint(measurement: AuthShellHintMeasurement, now = Date.now()): void {
+function recordAuthShellHint(measurement: AuthShellHintMeasurement): void {
+ const now = Date.now();
const category = resolveAuthShellCategory(measurement.pathname);
const heightPx = clampMeasuredPx(measurement.heightPx);
if (category == null || heightPx <= 0) {
@@ -213,6 +264,7 @@ export function recordAuthShellHint(measurement: AuthShellHintMeasurement, now =
k: measurement.kind,
h: heightPx,
w: clampMeasuredPx(measurement.widthPx),
+ s: measurement.split ? 1 : 0,
});
const kept = Array.from(entries.entries())
.sort(([, left], [, right]) => right.t - left.t)
@@ -228,6 +280,7 @@ interface AuthShellHintCaptureOptions {
readonly pathname: string;
readonly mobile: boolean;
readonly kind: AuthShellHintKind;
+ readonly split: boolean;
readonly resolveTarget: () => HTMLElement | null;
}
@@ -236,6 +289,7 @@ export function useAuthShellHintCapture({
pathname,
mobile,
kind,
+ split,
resolveTarget,
}: AuthShellHintCaptureOptions): void {
useEffect(() => {
@@ -258,7 +312,7 @@ export function useAuthShellHintCapture({
if (!(heightPx > 0)) {
return;
}
- recordAuthShellHint({pathname, mobile, kind, heightPx, widthPx: target.offsetWidth / remScale});
+ recordAuthShellHint({pathname, mobile, kind, heightPx, widthPx: target.offsetWidth / remScale, split});
capturedCategories.add(category);
stop();
};
@@ -282,7 +336,7 @@ export function useAuthShellHintCapture({
mutationObserver.observe(target, {childList: true, subtree: true});
schedule();
return stop;
- }, [enabled, pathname, mobile, kind, resolveTarget]);
+ }, [enabled, pathname, mobile, kind, split, resolveTarget]);
}
const CARD_PADDING_MIN_REM = 32;
@@ -302,15 +356,18 @@ export function resolveAuthShellRowCount(
if (placeholder.rows > 0) {
return placeholder.rows;
}
- const paddingPx = mobile
- ? 0
- : (Math.max(
+ let paddingPx = BRAND_ROW_MOBILE_PX;
+ if (!mobile) {
+ paddingPx =
+ (Math.max(
CARD_PADDING_MIN_REM * remScale,
Math.min(CARD_PADDING_VIEWPORT_RATIO * viewportWidthPx, CARD_PADDING_MAX_REM * remScale),
) *
2) /
remScale +
- CARD_BORDER_PX;
+ CARD_BORDER_PX +
+ (placeholder.split ? 0 : BRAND_ROW_CARD_PX);
+ }
return Math.max(
1,
Math.min(MAX_ROWS, Math.floor((placeholder.heightPx - paddingPx - TITLE_BLOCK_PX) / ROW_PITCH_PX)),