Skip to content

Commit 8a9242e

Browse files
Update Reconnect Prompt (#190)
* Use StandardDialog for ReconnectPrompt * Reconnect button restarts connection flow * Add title to reconnect dialog
1 parent cc60524 commit 8a9242e

File tree

3 files changed

+33
-64
lines changed

3 files changed

+33
-64
lines changed

src/components/ReconnectPrompt.svelte

Lines changed: 31 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,74 +5,44 @@
55
-->
66

77
<script lang="ts">
8-
import { horizontalSlide } from '../script/transitions';
98
import StandardButton from '../components/StandardButton.svelte';
109
import { state } from '../script/stores/uiStore';
1110
import { t } from '../i18n';
12-
import { btPatternInput, btPatternOutput } from '../script/stores/connectionStore';
13-
import MBSpecs from '../script/microbit-interfacing/MBSpecs';
14-
import Microbits from '../script/microbit-interfacing/Microbits';
1511
import { DeviceRequestStates } from '../script/stores/connectDialogStore';
16-
17-
let reconnectText: string;
18-
let reconnectButtonText: string;
19-
20-
state.subscribe(s => {
21-
if (s.reconnectState === DeviceRequestStates.INPUT) {
22-
reconnectText = $t('disconnectedWarning.input');
23-
reconnectButtonText = $t('disconnectedWarning.reconnectButton.input');
24-
} else if (s.reconnectState === DeviceRequestStates.OUTPUT) {
25-
reconnectText = $t('disconnectedWarning.output');
26-
reconnectButtonText = $t('disconnectedWarning.reconnectButton.output');
27-
}
28-
});
29-
// When disconnected by lost connection, offer the option to attempt to reconnect
30-
let hideReconnectMessageAfterTimeout = false;
31-
state.subscribe(s => {
32-
if (s.offerReconnect) {
33-
hideReconnectMessageAfterTimeout = true;
34-
}
35-
});
36-
37-
const reconnect = (connectState: DeviceRequestStates) => {
38-
hideReconnectMessageAfterTimeout = false;
39-
console.assert(connectState != DeviceRequestStates.NONE);
40-
const pairingPattern =
41-
connectState === DeviceRequestStates.INPUT ? $btPatternInput : $btPatternOutput;
42-
const name = MBSpecs.Utility.patternToName(pairingPattern);
43-
44-
const connect = () => {
45-
if (connectState == DeviceRequestStates.INPUT) {
46-
return Microbits.assignBluetoothInput(name);
47-
}
48-
return Microbits.assignOutput(name);
49-
};
50-
51-
void connect().then(didSucceed => {
52-
if (didSucceed) {
53-
$state.offerReconnect = false;
54-
}
55-
});
12+
import StandardDialog from './dialogs/StandardDialog.svelte';
13+
import { startConnectionProcess } from '../script/stores/connectDialogStore';
14+
15+
export let isOpen: boolean = false;
16+
17+
$: dialogText =
18+
$state.reconnectState === DeviceRequestStates.INPUT
19+
? {
20+
bodyId: 'disconnectedWarning.input',
21+
buttonId: 'disconnectedWarning.reconnectButton.input',
22+
}
23+
: {
24+
bodyId: 'disconnectedWarning.output',
25+
buttonId: 'disconnectedWarning.reconnectButton.output',
26+
};
27+
28+
const stopOfferingReconnect = () => {
29+
$state.offerReconnect = false;
30+
};
31+
const reconnect = () => {
32+
startConnectionProcess();
33+
stopOfferingReconnect();
5634
};
5735
</script>
5836

59-
<div
60-
class="absolute top-8 right-4 bg-white rounded-md p-6 border-1 border-black z-5"
61-
transition:horizontalSlide>
62-
<div class="w-100">
63-
<div class="absolute right-2 top-2 svelte-1rnkjvh">
64-
<button
65-
class="hover:bg-gray-100 rounded outline-transparent w-8 svelte-1rnkjvh"
66-
on:click={() => ($state.offerReconnect = false)}>
67-
<i
68-
class="fas fa-plus text-lg text-gray-600 hover:text-gray-800 duration-75 svelte-1rnkjvh"
69-
style="transform: rotate(45deg);" />
70-
</button>
71-
</div>
72-
<p>{reconnectText}</p>
37+
<StandardDialog {isOpen} onClose={stopOfferingReconnect} class="w-110">
38+
<svelte:fragment slot="heading">
39+
{$t('disconnectedWarning.heading')}
40+
</svelte:fragment>
41+
<div slot="body" class="flex flex-col pt-5 gap-7">
42+
<p>{$t(dialogText.bodyId)}</p>
7343
<div class="flex justify-center">
74-
<StandardButton onClick={() => reconnect($state.reconnectState)}
75-
>{reconnectButtonText}</StandardButton>
44+
<StandardButton type="primary" onClick={reconnect}
45+
>{$t(dialogText.buttonId)}</StandardButton>
7646
</div>
7747
</div>
78-
</div>
48+
</StandardDialog>

src/messages/ui.en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@
202202
"connectMB.connecting": "Connecting…",
203203
"connectMB.bluetooth.invalidPattern": "The pattern you have drawn is invalid.",
204204

205+
"disconnectedWarning.heading": "micro:bit connection lost",
205206
"disconnectedWarning.input": "Your input micro:bit lost connection, do want to try again?",
206207
"disconnectedWarning.output": "Your output micro:bit lost connection, do want to try again?",
207208
"disconnectedWarning.reconnectButton.input": "Reconnect input",

src/views/OverlayView.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,5 @@
7070
</div>
7171
</div>
7272
{/if}
73-
{#if $state.offerReconnect && isInputPatternValid()}
74-
<ReconnectPrompt />
75-
{/if}
73+
<ReconnectPrompt isOpen={$state.offerReconnect && isInputPatternValid()} />
7674
</div>

0 commit comments

Comments
 (0)