|
51 | 51 | import CloseIcon from 'virtual:icons/ri/close-line'; |
52 | 52 | import StandardDialog from './dialogs/StandardDialog.svelte'; |
53 | 53 |
|
54 | | - export let onNoMicrobitSelect: () => void; |
55 | 54 | export let gesture: Gesture; |
56 | 55 | export let showWalkThrough: Boolean = false; |
57 | 56 |
|
|
72 | 71 | let isThisRecording = false; |
73 | 72 | let showCountdown = false; |
74 | 73 | let countdownIdx = 0; |
75 | | - $: currCountdownConfig = countdownConfigs[countdownIdx]; |
76 | 74 |
|
77 | 75 | function cancelRecording(): void { |
78 | 76 | showCountdown = false; |
79 | 77 | isThisRecording = false; |
80 | 78 | } |
81 | 79 |
|
82 | 80 | function countdownStart(): void { |
| 81 | + selectGesture(); |
| 82 | +
|
83 | 83 | countdownIdx = 0; |
84 | 84 | showCountdown = true; |
85 | | - countdown(countdownConfigs[countdownIdx]); |
86 | | - } |
87 | 85 |
|
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]); |
102 | 103 | } |
103 | 104 |
|
104 | 105 | const nameBind = gesture.bindName(); |
|
169 | 170 | removeRecording(gesture.getId(), recording.ID); |
170 | 171 | } |
171 | 172 |
|
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; |
192 | 175 | } |
193 | 176 |
|
194 | 177 | $: isChosenGesture = $chosenGesture === gesture; |
|
253 | 236 | } |
254 | 237 | } |
255 | 238 |
|
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 | | -
|
268 | 239 | // Make function depend on buttonsPressed store. |
269 | 240 | let declaring = true; |
270 | 241 | $: { |
|
296 | 267 | <div class="flex items-center h-100px"> |
297 | 268 | {#if countdownIdx < countdownConfigs.length} |
298 | 269 | <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} |
302 | 273 | </p> |
303 | 274 | {:else} |
304 | 275 | <p class="text-5xl text-center font-bold text-brand-500"> |
|
318 | 289 | </StandardDialog> |
319 | 290 |
|
320 | 291 | <!-- 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. --> |
321 | 294 | <div on:click={selectGesture}> |
322 | 295 | <GestureTilePart small elevated selected={isChosenGesture || showAddActionWalkThrough}> |
323 | 296 | <div class="flex items-center justify-center p-2 w-50 h-30 relative"> |
|
361 | 334 | </p> |
362 | 335 | </div> |
363 | 336 | {:else} |
| 337 | + <!-- svelte-ignore a11y-no-static-element-interactions |
| 338 | + See above --> |
364 | 339 | <div |
365 | 340 | class="max-w-max {isGestureNamed || hasRecordings ? 'visible' : 'invisible'}" |
366 | 341 | on:click={selectGesture}> |
|
369 | 344 | <div class="w-33 flex justify-center items-center gap-x-3"> |
370 | 345 | <IconButton |
371 | 346 | ariaLabel={$t( |
372 | | - isChosenGesture ? 'content.data.recordAction' : 'content.data.selectAction', |
| 347 | + isChosenGesture |
| 348 | + ? 'content.data.recordAction' |
| 349 | + : 'content.data.selectAndRecordAction', |
373 | 350 | { |
374 | 351 | values: { |
375 | 352 | action: $nameBind, |
376 | 353 | }, |
377 | 354 | }, |
378 | 355 | )} |
379 | | - onClick={isChosenGesture ? countdownStart : selectClicked} |
| 356 | + onClick={countdownStart} |
380 | 357 | disabled={!$state.isInputConnected} |
381 | 358 | rounded> |
382 | 359 | <RecordIcon |
|
0 commit comments