Skip to content

Commit 91b3018

Browse files
Update recording countdown (#197)
* Add "Go" after 3, 2, 1 * Make 3, 2, 1 faster * Remove recording description
1 parent 7bfeb18 commit 91b3018

File tree

2 files changed

+35
-25
lines changed

2 files changed

+35
-25
lines changed

src/components/Gesture.svelte

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,35 +57,48 @@
5757
5858
const gesturePlaceholderName = $t('content.data.classPlaceholderNewClass');
5959
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+
];
6171
6272
let isThisRecording = false;
6373
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];
7176
7277
function cancelRecording(): void {
73-
cancelCountdown();
78+
showCountdown = false;
7479
isThisRecording = false;
7580
}
7681
7782
function countdownStart(): void {
78-
countdownValue = countdownInitialValue;
83+
countdownIdx = 0;
7984
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 {
8398
recordData();
8499
showCountdown = false;
85-
} else if (!showCountdown) {
86-
cancelCountdown();
87100
}
88-
}, 1000);
101+
}, config.duration);
89102
}
90103
91104
const nameBind = gesture.bindName();
@@ -280,15 +293,12 @@
280293
</svelte:fragment>
281294
<svelte:fragment slot="body">
282295
<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>
288296
<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}
292302
</p>
293303
{:else}
294304
<p class="text-5xl text-center font-bold text-brand-500">

src/messages/ui.en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"content.data.deleteAction": "Delete action \"{action}\"",
4949
"content.data.deleteRecording": "Delete recording",
5050
"content.data.recordingDialog.title": "Record data for action \"{action}\"",
51+
"content.data.recordingDialog.go": "Go",
5152
"content.data.recordingDialog.recording": "Recording",
5253

5354
"content.data.controlbar.button.menu": "Data actions",
@@ -57,7 +58,6 @@
5758
"content.data.controlbar.button.uploadData": "Import data samples",
5859

5960
"content.data.recording.button.cancel": "Cancel recording",
60-
"content.data.recording.description": "Start action before the countdown finishes",
6161

6262
"content.trainer.header": "Training a model",
6363
"content.trainer.description": "The computer program spots patterns or differences in your data samples, and uses these to build a mathematical model that allows the micro:bit machine learning tool to recognise different actions when you move your micro:bit.",

0 commit comments

Comments
 (0)