mirror of
https://github.com/fromchat-messenger/web.git
synced 2026-09-22 19:15:08 +03:00
Fix auth page
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { AuthContainer } from "./Auth";
|
import { AuthContainer } from "./Auth";
|
||||||
import { useState, useEffect, useRef, useLayoutEffect, useCallback, type RefObject } from "react";
|
import { useState, useRef, useLayoutEffect, useCallback, type RefObject } from "react";
|
||||||
import { useNavigate, useSearchParams, Navigate } from "react-router-dom";
|
import { useNavigate, useSearchParams, Navigate } from "react-router-dom";
|
||||||
import { motion, AnimatePresence } from "motion/react";
|
import { motion, AnimatePresence } from "motion/react";
|
||||||
import useDownloadAppScreen from "@/core/hooks/useDownloadAppScreen";
|
import useDownloadAppScreen from "@/core/hooks/useDownloadAppScreen";
|
||||||
@@ -50,12 +50,33 @@ export default function AuthPage() {
|
|||||||
const currentMode = searchParams.get("mode") || "login";
|
const currentMode = searchParams.get("mode") || "login";
|
||||||
const enteringElementRef = useRef<"login" | "register" | null>(null);
|
const enteringElementRef = useRef<"login" | "register" | null>(null);
|
||||||
const [effectActivated, setEffectActivated] = useState(false);
|
const [effectActivated, setEffectActivated] = useState(false);
|
||||||
|
const [isTransitioning, setIsTransitioning] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (prevMode.current !== currentMode) {
|
if (prevMode.current !== currentMode) {
|
||||||
setDirection(currentMode === "register" ? 1 : -1);
|
const previousMode = prevMode.current;
|
||||||
|
|
||||||
|
// Measure the exiting form's height BEFORE changing anything
|
||||||
|
// This works whether it's relative or absolute
|
||||||
|
const exitingComponent = previousMode === "login" ? loginFormRef.current : registerFormRef.current;
|
||||||
|
let measuredHeight: number | null = null;
|
||||||
|
if (exitingComponent) {
|
||||||
|
const height = exitingComponent.scrollHeight;
|
||||||
|
if (height > 0) {
|
||||||
|
measuredHeight = height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update mode and direction first
|
||||||
prevMode.current = currentMode;
|
prevMode.current = currentMode;
|
||||||
|
setDirection(currentMode === "register" ? 1 : -1);
|
||||||
enteringElementRef.current = currentMode as "login" | "register";
|
enteringElementRef.current = currentMode as "login" | "register";
|
||||||
|
|
||||||
|
// Set height and transition state together
|
||||||
|
if (measuredHeight !== null) {
|
||||||
|
setContainerHeight(measuredHeight);
|
||||||
|
}
|
||||||
|
setIsTransitioning(true);
|
||||||
}
|
}
|
||||||
}, [currentMode]);
|
}, [currentMode]);
|
||||||
|
|
||||||
@@ -112,6 +133,7 @@ export default function AuthPage() {
|
|||||||
return () => {
|
return () => {
|
||||||
if (currentMode === mode && enteringElementRef.current === mode) {
|
if (currentMode === mode && enteringElementRef.current === mode) {
|
||||||
enteringElementRef.current = null;
|
enteringElementRef.current = null;
|
||||||
|
setIsTransitioning(false);
|
||||||
|
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
@@ -136,9 +158,6 @@ export default function AuthPage() {
|
|||||||
width: "100%",
|
width: "100%",
|
||||||
height: containerHeight === "auto" ? "auto" : `${containerHeight}px`,
|
height: containerHeight === "auto" ? "auto" : `${containerHeight}px`,
|
||||||
transition: "height 0.3s ease"
|
transition: "height 0.3s ease"
|
||||||
}}
|
|
||||||
onAnimationStart={() => {
|
|
||||||
|
|
||||||
}}
|
}}
|
||||||
onAnimationEnd={() => {
|
onAnimationEnd={() => {
|
||||||
setContainerHeight("auto");
|
setContainerHeight("auto");
|
||||||
@@ -158,7 +177,7 @@ export default function AuthPage() {
|
|||||||
onAnimationComplete={handleAnimationComplete("login", "login", enteringElementRef, loginFormRef, setContainerHeight)}
|
onAnimationComplete={handleAnimationComplete("login", "login", enteringElementRef, loginFormRef, setContainerHeight)}
|
||||||
className={styles.formWrapper}
|
className={styles.formWrapper}
|
||||||
style={{
|
style={{
|
||||||
position: containerHeight === "auto" ? "relative" : "absolute"
|
position: (containerHeight === "auto" && !isTransitioning) ? "relative" : "absolute"
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<LoginForm onSwitchMode={() => switchMode("register")} />
|
<LoginForm onSwitchMode={() => switchMode("register")} />
|
||||||
@@ -175,6 +194,9 @@ export default function AuthPage() {
|
|||||||
transition={slideTransition}
|
transition={slideTransition}
|
||||||
onAnimationComplete={handleAnimationComplete("register", "register", enteringElementRef, registerFormRef, setContainerHeight)}
|
onAnimationComplete={handleAnimationComplete("register", "register", enteringElementRef, registerFormRef, setContainerHeight)}
|
||||||
className={styles.formWrapper}
|
className={styles.formWrapper}
|
||||||
|
style={{
|
||||||
|
position: (containerHeight === "auto" && !isTransitioning) ? "relative" : "absolute"
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<RegisterForm onSwitchMode={() => switchMode("login")} />
|
<RegisterForm onSwitchMode={() => switchMode("login")} />
|
||||||
</motion.div>
|
</motion.div>
|
||||||
|
|||||||
Reference in New Issue
Block a user