From a5d2e9cf72322c3f58d852432665569f3c72d854 Mon Sep 17 00:00:00 2001 From: Mahyar Khanbolooki Date: Thu, 3 Jul 2025 18:51:33 +0330 Subject: [PATCH] feat: add loading overlay to between navigations and to auth form events --- src/app/loading.tsx | 10 +++++ src/components/loading/LoadingOverlay.tsx | 37 +++++++++++++++++++ .../loading/animations/PingAnimation.tsx | 16 ++++++++ .../auth/components/AuthFormWrapper.tsx | 6 ++- 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 src/app/loading.tsx create mode 100644 src/components/loading/LoadingOverlay.tsx create mode 100644 src/components/loading/animations/PingAnimation.tsx diff --git a/src/app/loading.tsx b/src/app/loading.tsx new file mode 100644 index 0000000..49906a7 --- /dev/null +++ b/src/app/loading.tsx @@ -0,0 +1,10 @@ +import LoadingOverlay from '@/components/loading/LoadingOverlay' +import React from 'react' + +function Loading() { + return ( + + ) +} + +export default Loading \ No newline at end of file diff --git a/src/components/loading/LoadingOverlay.tsx b/src/components/loading/LoadingOverlay.tsx new file mode 100644 index 0000000..bf4a52e --- /dev/null +++ b/src/components/loading/LoadingOverlay.tsx @@ -0,0 +1,37 @@ +'use client' + +import React, { useEffect, useState } from 'react' +import PingAnimation from './animations/PingAnimation'; + +type Props = { + visible?: boolean; + bgOpacity?: number; + delay?: number; +} & React.DetailedHTMLProps, HTMLDivElement> + +const LoadingOverlay = ({ visible = true, bgOpacity = 30, delay = 0, children = }: Props) => { + const [loaded, setLoaded] = useState(false); + + useEffect(() => { + // Trigger fade-in after mount + const timeout = setTimeout(() => setLoaded(visible), 300); + return () => clearTimeout(timeout); + }, [visible]); + + return ( +
+ {children} +
+ ) +} + +export default LoadingOverlay \ No newline at end of file diff --git a/src/components/loading/animations/PingAnimation.tsx b/src/components/loading/animations/PingAnimation.tsx new file mode 100644 index 0000000..a25c5d1 --- /dev/null +++ b/src/components/loading/animations/PingAnimation.tsx @@ -0,0 +1,16 @@ +import React from 'react' + +type Props = object + +function PingAnimation({ }: Props) { + return ( +
+
+
+
+
+
+ ) +} + +export default PingAnimation \ No newline at end of file diff --git a/src/features/auth/components/AuthFormWrapper.tsx b/src/features/auth/components/AuthFormWrapper.tsx index 4c9373a..33f6539 100644 --- a/src/features/auth/components/AuthFormWrapper.tsx +++ b/src/features/auth/components/AuthFormWrapper.tsx @@ -1,14 +1,16 @@ +import LoadingOverlay from '@/components/loading/LoadingOverlay'; import React from 'react' type Props = { isPending: boolean } & Omit, "id">; -function AuthFormWrapper({ children, ...restProps }: Props) { +function AuthFormWrapper({ children, isPending, ...restProps }: Props) { return (
-
+
{children} +
)