|
5 | 5 | --> |
6 | 6 |
|
7 | 7 | <script lang="ts"> |
8 | | - import { horizontalSlide } from '../script/transitions'; |
9 | 8 | import StandardButton from '../components/StandardButton.svelte'; |
10 | 9 | import { state } from '../script/stores/uiStore'; |
11 | 10 | 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'; |
15 | 11 | 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(); |
56 | 34 | }; |
57 | 35 | </script> |
58 | 36 |
|
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> |
73 | 43 | <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> |
76 | 46 | </div> |
77 | 47 | </div> |
78 | | -</div> |
| 48 | +</StandardDialog> |
0 commit comments