Harden form auth and submission handling
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"use client"
|
||||
|
||||
import { Suspense, useEffect, useState } from "react"
|
||||
import { Suspense, useEffect, useRef, useState } from "react"
|
||||
import { usePathname, useSearchParams } from "next/navigation"
|
||||
import { Progress } from "@/components/ui/progress"
|
||||
|
||||
@@ -9,6 +9,7 @@ function PageProgressContent() {
|
||||
const searchParams = useSearchParams()
|
||||
const [progress, setProgress] = useState(0)
|
||||
const [isVisible, setIsVisible] = useState(false)
|
||||
const intervalRef = useRef<ReturnType<typeof setInterval> | null>(null)
|
||||
|
||||
// Start progress on click
|
||||
useEffect(() => {
|
||||
@@ -39,9 +40,7 @@ function PageProgressContent() {
|
||||
return prev + (95 - prev) * 0.1
|
||||
})
|
||||
}, 100)
|
||||
|
||||
// Store interval so we can clear it on route change
|
||||
;(window as any).__page_progress_interval = interval
|
||||
intervalRef.current = interval
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,17 +50,21 @@ function PageProgressContent() {
|
||||
|
||||
// Finish progress on route change
|
||||
useEffect(() => {
|
||||
if (typeof window !== "undefined" && (window as any).__page_progress_interval) {
|
||||
clearInterval((window as any).__page_progress_interval)
|
||||
if (intervalRef.current) {
|
||||
clearInterval(intervalRef.current)
|
||||
intervalRef.current = null
|
||||
}
|
||||
|
||||
if (isVisible) {
|
||||
setProgress(100)
|
||||
const finishTimeout = setTimeout(() => setProgress(100), 0)
|
||||
const timeout = setTimeout(() => {
|
||||
setIsVisible(false)
|
||||
setTimeout(() => setProgress(0), 300) // Reset after hiding
|
||||
}, 400)
|
||||
return () => clearTimeout(timeout)
|
||||
return () => {
|
||||
clearTimeout(finishTimeout)
|
||||
clearTimeout(timeout)
|
||||
}
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [pathname, searchParams])
|
||||
|
||||
Reference in New Issue
Block a user