Skip to content

Commit 9390714

Browse files
Single click to select + record (#199)
Additionally fixes a recently introduced issue with the countdown. Co-authored-by: Grace <[email protected]>
1 parent e48839a commit 9390714

File tree

3 files changed

+34
-58
lines changed

3 files changed

+34
-58
lines changed

src/components/Gesture.svelte

Lines changed: 32 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import CloseIcon from 'virtual:icons/ri/close-line';
5252
import StandardDialog from './dialogs/StandardDialog.svelte';
5353
54-
export let onNoMicrobitSelect: () => void;
5554
export let gesture: Gesture;
5655
export let showWalkThrough: Boolean = false;
5756
@@ -72,33 +71,35 @@
7271
let isThisRecording = false;
7372
let showCountdown = false;
7473
let countdownIdx = 0;
75-
$: currCountdownConfig = countdownConfigs[countdownIdx];
7674
7775
function cancelRecording(): void {
7876
showCountdown = false;
7977
isThisRecording = false;
8078
}
8179
8280
function countdownStart(): void {
81+
selectGesture();
82+
8383
countdownIdx = 0;
8484
showCountdown = true;
85-
countdown(countdownConfigs[countdownIdx]);
86-
}
8785
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 {
98-
recordData();
99-
showCountdown = false;
100-
}
101-
}, config.duration);
86+
function countdown(config: CountdownConfig): void {
87+
setTimeout(() => {
88+
countdownIdx++;
89+
if (!showCountdown) {
90+
// recording cancelled
91+
return;
92+
}
93+
if (countdownIdx < countdownConfigs.length) {
94+
countdown(countdownConfigs[countdownIdx]);
95+
} else {
96+
recordData();
97+
showCountdown = false;
98+
}
99+
}, config.duration);
100+
}
101+
102+
countdown(countdownConfigs[countdownIdx]);
102103
}
103104
104105
const nameBind = gesture.bindName();
@@ -169,26 +170,8 @@
169170
removeRecording(gesture.getId(), recording.ID);
170171
}
171172
172-
// Selecting this gesture for recording. Updates settings accordingly
173-
// If gesture is already selected, the selection is removed.
174-
// If bluetooth is not connected, open connection prompt by calling callback
175-
function selectClicked(): void {
176-
if (!$state.isInputConnected) {
177-
chosenGesture.update(gesture => {
178-
gesture = null;
179-
return gesture;
180-
});
181-
onNoMicrobitSelect();
182-
return;
183-
}
184-
chosenGesture.update(chosen => {
185-
if (chosen === gesture) {
186-
chosen = null;
187-
} else {
188-
chosen = gesture;
189-
}
190-
return chosen;
191-
});
173+
function selectGesture(): void {
174+
$chosenGesture = gesture;
192175
}
193176
194177
$: isChosenGesture = $chosenGesture === gesture;
@@ -253,18 +236,6 @@
253236
}
254237
}
255238
256-
function selectGesture() {
257-
chosenGesture.update(chosen => {
258-
chosen = gesture;
259-
return chosen;
260-
});
261-
}
262-
263-
// Select gesture when gesture is renamed
264-
$: if ($nameBind.trim()) {
265-
selectGesture();
266-
}
267-
268239
// Make function depend on buttonsPressed store.
269240
let declaring = true;
270241
$: {
@@ -296,9 +267,9 @@
296267
<div class="flex items-center h-100px">
297268
{#if countdownIdx < countdownConfigs.length}
298269
<p
299-
class="text-center font-bold text-brand-500 {currCountdownConfig.class ||
300-
''}">
301-
{currCountdownConfig.value}
270+
class="text-center font-bold text-brand-500 {countdownConfigs[countdownIdx]
271+
.class || ''}">
272+
{countdownConfigs[countdownIdx].value}
302273
</p>
303274
{:else}
304275
<p class="text-5xl text-center font-bold text-brand-500">
@@ -318,6 +289,8 @@
318289
</StandardDialog>
319290

320291
<!-- Title of gesture-->
292+
<!-- svelte-ignore a11y-no-static-element-interactions
293+
You can instead interact with the button. A better model of row selection would be a good enhancement. -->
321294
<div on:click={selectGesture}>
322295
<GestureTilePart small elevated selected={isChosenGesture || showAddActionWalkThrough}>
323296
<div class="flex items-center justify-center p-2 w-50 h-30 relative">
@@ -361,6 +334,8 @@
361334
</p>
362335
</div>
363336
{:else}
337+
<!-- svelte-ignore a11y-no-static-element-interactions
338+
See above -->
364339
<div
365340
class="max-w-max {isGestureNamed || hasRecordings ? 'visible' : 'invisible'}"
366341
on:click={selectGesture}>
@@ -369,14 +344,16 @@
369344
<div class="w-33 flex justify-center items-center gap-x-3">
370345
<IconButton
371346
ariaLabel={$t(
372-
isChosenGesture ? 'content.data.recordAction' : 'content.data.selectAction',
347+
isChosenGesture
348+
? 'content.data.recordAction'
349+
: 'content.data.selectAndRecordAction',
373350
{
374351
values: {
375352
action: $nameBind,
376353
},
377354
},
378355
)}
379-
onClick={isChosenGesture ? countdownStart : selectClicked}
356+
onClick={countdownStart}
380357
disabled={!$state.isInputConnected}
381358
rounded>
382359
<RecordIcon

src/messages/ui.en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"content.data.addActionWalkThrough": "Name an action you want the micro:bit to recognise",
4343
"content.data.addRecordingWalkThrough": "Press to record a data sample or press button B on your micro:bit.",
4444
"content.data.dataDescription": "Multiple samples of movement data collected in approximately 2 second bursts.",
45-
"content.data.selectAction": "Select action \"{action}\"",
45+
"content.data.selectAndRecordAction": "Select action \"{action}\" and record data",
4646
"content.data.recordAction": "Record data for action \"{action}\"",
4747
"content.data.deleteAction": "Delete action \"{action}\"",
4848
"content.data.deleteRecording": "Delete recording",

src/pages/DataPage.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@
118118
<section class="contents">
119119
<Gesture
120120
showWalkThrough={$gestures.length === 1}
121-
gesture={gestures.getGesture(gesture.ID)}
122-
onNoMicrobitSelect={() => (isConnectionDialogOpen = true)} />
121+
gesture={gestures.getGesture(gesture.ID)} />
123122
</section>
124123
{/each}
125124
</div>

0 commit comments

Comments
 (0)