-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseLoadingTransition.ts
More file actions
52 lines (48 loc) · 1.54 KB
/
useLoadingTransition.ts
File metadata and controls
52 lines (48 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { useEffect, useState } from 'react'
import config from '@/config'
type UseLoadingTransitionOptions = {
isDataReady: boolean
isDataLoading?: boolean
}
export const useLoadingTransition = ({
isDataReady,
isDataLoading = false,
}: UseLoadingTransitionOptions) => {
const [isLoading, setIsLoading] = useState(true)
const [showContent, setShowContent] = useState(false)
const [isLogoFadingOut, setIsLogoFadingOut] = useState(false)
useEffect(() => {
if (isDataReady) {
if (config.debug) {
// ローディング画面を表示し、ロゴがフェードイン完了後にフェードアウト
const timer = setTimeout(() => {
setIsLogoFadingOut(true)
// ロゴのフェードアウト後にコンテンツを表示
setTimeout(() => {
setShowContent(true)
// その後ローディングを非表示
setTimeout(() => {
setIsLoading(false)
}, 100)
}, 800) // ロゴのフェードアウト時間
}, 1500) // ロゴのフェードイン完了後(1.5秒)
return () => {
clearTimeout(timer)
}
} else {
// debugモードでない場合は即座に切り替え
setIsLoading(false)
setShowContent(true)
}
} else if (!isDataLoading) {
// データがない場合は即座に切り替え
setIsLoading(false)
setShowContent(true)
}
}, [isDataReady, isDataLoading])
return {
isLoading,
showContent,
isLogoFadingOut,
}
}