refactor(BindContactModal): 绑定联系方式弹窗目录化拆分(180→119行, -34%) (#1183)
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 3m26s
CI/CD Pipeline / Validate - Migration (alembic) (push) Successful in 2m26s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 3m59s
CI/CD Pipeline / Validate - Type Check (mypy) (push) Successful in 4m22s
CI/CD Pipeline / Build Staging Web Image (push) Successful in 5m22s
CI/CD Pipeline / Validate - Code Quality (push) Successful in 6m17s
CI/CD Pipeline / Integration Tests (push) Successful in 2m51s
CI/CD Pipeline / Unit Tests (push) Successful in 11m48s
CI/CD Pipeline / Build Staging API Image (push) Successful in 12m46s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 29s
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 35s
CI/CD Pipeline / Staging E2E Tests (push) Failing after 3m7s
CI/CD Pipeline / Staging API Integration Tests (push) Successful in 5m47s
CI/CD Pipeline / Canary Release to Production (push) Failing after 1147h9m38s
CI/CD Pipeline / Deploy Production (push) Failing after 1147h16m52s
CI/CD Pipeline / CI Gate (push) Failing after 1147h16m53s
CI/CD Pipeline / Build Production API Image (push) Failing after 1147h16m53s
CI/CD Pipeline / PR Build Worker Image (push) Failing after 1147h28m39s
CI/CD Pipeline / PR Build API Image (push) Failing after 1147h28m41s
CI/CD Pipeline / Frontend Lint (push) Failing after 1147h28m42s
CI/CD Pipeline / Build Production Worker Image (push) Failing after 1147h16m53s
CI/CD Pipeline / Check if frontend-only change (push) Failing after 1147h28m44s
CI/CD Pipeline / Production Browser E2E (push) Failing after 1147h50m2s
CI/CD Pipeline / Build Production Web Image (push) Failing after 1147h50m3s
CI/CD Pipeline / PR Build Web Image (push) Failing after 1148h1m50s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 3m26s
CI/CD Pipeline / Validate - Migration (alembic) (push) Successful in 2m26s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 3m59s
CI/CD Pipeline / Validate - Type Check (mypy) (push) Successful in 4m22s
CI/CD Pipeline / Build Staging Web Image (push) Successful in 5m22s
CI/CD Pipeline / Validate - Code Quality (push) Successful in 6m17s
CI/CD Pipeline / Integration Tests (push) Successful in 2m51s
CI/CD Pipeline / Unit Tests (push) Successful in 11m48s
CI/CD Pipeline / Build Staging API Image (push) Successful in 12m46s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 29s
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 35s
CI/CD Pipeline / Staging E2E Tests (push) Failing after 3m7s
CI/CD Pipeline / Staging API Integration Tests (push) Successful in 5m47s
CI/CD Pipeline / Canary Release to Production (push) Failing after 1147h9m38s
CI/CD Pipeline / Deploy Production (push) Failing after 1147h16m52s
CI/CD Pipeline / CI Gate (push) Failing after 1147h16m53s
CI/CD Pipeline / Build Production API Image (push) Failing after 1147h16m53s
CI/CD Pipeline / PR Build Worker Image (push) Failing after 1147h28m39s
CI/CD Pipeline / PR Build API Image (push) Failing after 1147h28m41s
CI/CD Pipeline / Frontend Lint (push) Failing after 1147h28m42s
CI/CD Pipeline / Build Production Worker Image (push) Failing after 1147h16m53s
CI/CD Pipeline / Check if frontend-only change (push) Failing after 1147h28m44s
CI/CD Pipeline / Production Browser E2E (push) Failing after 1147h50m2s
CI/CD Pipeline / Build Production Web Image (push) Failing after 1147h50m3s
CI/CD Pipeline / PR Build Web Image (push) Failing after 1148h1m50s
This commit was merged in pull request #1183.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import { useState, useEffect, useRef, useCallback } from "react"
|
||||
|
||||
/**
|
||||
* 倒计时 Hook
|
||||
* 用于验证码发送等场景的倒计时控制
|
||||
*/
|
||||
export const useCountdown = (initialSeconds = 60) => {
|
||||
const [countdown, setCountdown] = useState(0)
|
||||
const timerRef = useRef<ReturnType<typeof setInterval> | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (countdown > 0) {
|
||||
timerRef.current = setInterval(() => {
|
||||
setCountdown((prev) => prev - 1)
|
||||
}, 1000)
|
||||
} else if (timerRef.current) {
|
||||
clearInterval(timerRef.current)
|
||||
timerRef.current = null
|
||||
}
|
||||
return () => {
|
||||
if (timerRef.current) clearInterval(timerRef.current)
|
||||
}
|
||||
}, [countdown])
|
||||
|
||||
const start = useCallback(() => {
|
||||
setCountdown(initialSeconds)
|
||||
}, [initialSeconds])
|
||||
|
||||
const reset = useCallback(() => {
|
||||
setCountdown(0)
|
||||
}, [])
|
||||
|
||||
return {
|
||||
countdown,
|
||||
isRunning: countdown > 0,
|
||||
start,
|
||||
reset,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user