|
57 | 57 |
|
58 | 58 | const gesturePlaceholderName = $t('content.data.classPlaceholderNewClass'); |
59 | 59 | const recordingDuration = get(settings).duration; |
60 | | - const countdownInitialValue = 3; |
| 60 | + interface CountdownConfig { |
| 61 | + value: string | number; |
| 62 | + duration: number; |
| 63 | + class?: string; |
| 64 | + } |
| 65 | + const countdownConfigs: CountdownConfig[] = [ |
| 66 | + { value: 3, duration: 500, class: 'text-8xl' }, |
| 67 | + { value: 2, duration: 500, class: 'text-8xl' }, |
| 68 | + { value: 1, duration: 500, class: 'text-8xl' }, |
| 69 | + { value: $t('content.data.recordingDialog.go'), duration: 1000, class: 'text-6xl' }, |
| 70 | + ]; |
61 | 71 |
|
62 | 72 | let isThisRecording = false; |
63 | 73 | let showCountdown = false; |
64 | | - let countdownValue = countdownInitialValue; |
65 | | - let countdownInterval: any; |
66 | | -
|
67 | | - function cancelCountdown(): void { |
68 | | - clearInterval(countdownInterval); |
69 | | - showCountdown = false; |
70 | | - } |
| 74 | + let countdownIdx = 0; |
| 75 | + $: currCountdownConfig = countdownConfigs[countdownIdx]; |
71 | 76 |
|
72 | 77 | function cancelRecording(): void { |
73 | | - cancelCountdown(); |
| 78 | + showCountdown = false; |
74 | 79 | isThisRecording = false; |
75 | 80 | } |
76 | 81 |
|
77 | 82 | function countdownStart(): void { |
78 | | - countdownValue = countdownInitialValue; |
| 83 | + countdownIdx = 0; |
79 | 84 | showCountdown = true; |
80 | | - countdownInterval = setInterval(() => { |
81 | | - countdownValue--; |
82 | | - if (countdownValue === 0 && showCountdown) { |
| 85 | + countdown(countdownConfigs[countdownIdx]); |
| 86 | + } |
| 87 | +
|
| 88 | + function countdown(config: CountdownConfig): void { |
| 89 | + setTimeout(() => { |
| 90 | + countdownIdx++; |
| 91 | + if (!showCountdown) { |
| 92 | + // recording cancelled |
| 93 | + return; |
| 94 | + } |
| 95 | + if (countdownIdx < countdownConfigs.length) { |
| 96 | + countdown(countdownConfigs[countdownIdx]); |
| 97 | + } else { |
83 | 98 | recordData(); |
84 | 99 | showCountdown = false; |
85 | | - } else if (!showCountdown) { |
86 | | - cancelCountdown(); |
87 | 100 | } |
88 | | - }, 1000); |
| 101 | + }, config.duration); |
89 | 102 | } |
90 | 103 |
|
91 | 104 | const nameBind = gesture.bindName(); |
|
280 | 293 | </svelte:fragment> |
281 | 294 | <svelte:fragment slot="body"> |
282 | 295 | <div class="flex flex-col space-y-3 self-center items-center justify-center"> |
283 | | - <div class="flex justify-center"> |
284 | | - <p class="text-lg px-10 text-center"> |
285 | | - {$t('content.data.recording.description')} |
286 | | - </p> |
287 | | - </div> |
288 | 296 | <div class="flex items-center h-100px"> |
289 | | - {#if countdownValue > 0} |
290 | | - <p class="text-8xl text-center font-bold text-brand-500"> |
291 | | - {countdownValue} |
| 297 | + {#if countdownIdx < countdownConfigs.length} |
| 298 | + <p |
| 299 | + class="text-center font-bold text-brand-500 {currCountdownConfig.class || |
| 300 | + ''}"> |
| 301 | + {currCountdownConfig.value} |
292 | 302 | </p> |
293 | 303 | {:else} |
294 | 304 | <p class="text-5xl text-center font-bold text-brand-500"> |
|
0 commit comments