generated from ZanzyTHEbar/SolidJSTauri
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.tsx
More file actions
179 lines (176 loc) · 8.09 KB
/
index.tsx
File metadata and controls
179 lines (176 loc) · 8.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import Card from '@components/Cards/Card'
import Input from '@components/Inputs/Input'
import Typography from '@components/Typography'
import {
ACTION,
INIT_WIZARD_STEPS,
SELECT_MODE_WIZARD,
WIRED_WIZARD_STEPS,
} from '@interfaces/animation/enums'
import { getApi } from '@src/esp'
import { logger } from '@src/logger'
import { shortMdnsAddress } from '@src/utils'
import { setAction, setStep } from '@store/animation/animation'
import { activeStep } from '@store/animation/selectors'
import { activePort } from '@store/esp/selectors'
import { setTrackerName } from '@store/firmware/firmware'
import { trackerName } from '@store/firmware/selectors'
import { BiRegularError, BiRegularLoaderAlt } from 'solid-icons/bi'
import { IoCheckmarkSharp } from 'solid-icons/io'
import { VsDeviceCameraVideo } from 'solid-icons/vs'
import { batch, createSignal, Match, Switch } from 'solid-js'
const WiredWizard = () => {
const [isPendingUpdate, setIsPendingUpdate] = createSignal(false)
const [error, setError] = createSignal('')
return (
<Switch>
<Match when={activeStep() === WIRED_WIZARD_STEPS.WIRED_SETUP_TRACKER_NAME}>
<Card
secondaryButtonLabel="Wi-Fi mode"
onClickOptionLabel="Wired Mode"
label="Setup tracker name"
primaryButtonLabel="Setup Tracker"
isActive={trackerName().trim().length > 3 && trackerName().trim().length <= 15}
icon={VsDeviceCameraVideo}
onClickBack={() => {
batch(() => {
setAction(ACTION.PREV)
setStep(SELECT_MODE_WIZARD.SELECT_MODE)
})
}}
onClickPrimary={() => {
batch(() => {
logger.infoStart('setupWiredConnection')
logger.add('tracker name: ' + trackerName())
logger.add('active port: ' + activePort())
setStep(WIRED_WIZARD_STEPS.WIRED_SETUP_TRACKER_PROCESS)
setIsPendingUpdate(true)
setAction(ACTION.NEXT)
setError('')
})
getApi()
.setupWiredConnection(trackerName(), activePort())
.then(() => {
batch(() => {
setStep(WIRED_WIZARD_STEPS.WIRED_SETUP_TRACKER_PROCESS_SUCCESS)
setAction(ACTION.NEXT)
})
})
.catch((err) => {
batch(() => {
logger.errorStart('setupWiredConnection ERROR')
logger.add(err instanceof Error ? err.message : `${err}`)
logger.errorEnd('setupWiredConnection ERROR')
setStep(WIRED_WIZARD_STEPS.WIRED_SETUP_TRACKER_PROCESS_FAILED)
setAction(ACTION.NEXT)
setError(err instanceof Error ? err.message : `${err}`)
})
})
.finally(() => {
setIsPendingUpdate(false)
logger.infoEnd('setupWiredConnection')
})
}}>
<Typography color="blue" text="caption" class="leading-[18px]">
The tracker will be accessible under:
<br />
<code class="text-purple-100">
(
{!trackerName().trim().length
? '----'
: shortMdnsAddress(trackerName())}
)
</code>
</Typography>
<div class="flex flex-col gap-10 w-full">
<Typography color="white" text="caption" class="text-left">
Tracker name
</Typography>
<Input
id="trackerName"
required={true}
autoFocus={true}
type="text"
onChange={(name) => {
if (/[^A-Za-z\d]/.test(name)) return
let cleanedName = name.replace(/^\s+/, '').replace(/\s+/g, ' ')
setTrackerName(cleanedName)
}}
placeholder="Enter your tracker name"
value={trackerName()}
/>
</div>
</Card>
</Match>
<Match when={activeStep() === WIRED_WIZARD_STEPS.WIRED_SETUP_TRACKER_PROCESS}>
<Card
label="Setup tracker name"
primaryButtonLabel="Continue"
isLoader
icon={BiRegularLoaderAlt}
onClickBack={() => {
if (isPendingUpdate()) return
batch(() => {
setAction(ACTION.PREV)
setStep(WIRED_WIZARD_STEPS.WIRED_SETUP_TRACKER_NAME)
})
}}
onClickPrimary={() => {}}>
<Typography color="white" text="caption" class="leading-[18px]">
Switching to wired mode… The device will now appear as a UVC camera. with an
additional COM port for communication
</Typography>
</Card>
</Match>
<Match when={activeStep() === WIRED_WIZARD_STEPS.WIRED_SETUP_TRACKER_PROCESS_SUCCESS}>
<Card
status="success"
secondaryButtonLabel="Return to the beginning"
isActive
icon={IoCheckmarkSharp}
onClickBack={() => {
batch(() => {
setAction(ACTION.PREV)
setStep(WIRED_WIZARD_STEPS.WIRED_SETUP_TRACKER_NAME)
})
}}
onClickSecondary={() => {
batch(() => {
setAction(ACTION.NEXT)
setStep(INIT_WIZARD_STEPS.PROCESS_INIT)
})
}}
label="Its done!"
description="Your device is set up and ready to go."
/>
</Match>
<Match when={activeStep() === WIRED_WIZARD_STEPS.WIRED_SETUP_TRACKER_PROCESS_FAILED}>
<Card
label="Failed to Switch to wired mode"
primaryButtonLabel="Try again"
status="fail"
isActive
icon={BiRegularError}
onClickBack={() => {
batch(() => {
setAction(ACTION.PREV)
setStep(WIRED_WIZARD_STEPS.WIRED_SETUP_TRACKER_NAME)
})
}}
onClickPrimary={() => {
batch(() => {
setAction(ACTION.NEXT)
setStep(WIRED_WIZARD_STEPS.WIRED_SETUP_TRACKER_NAME)
})
}}>
<Typography color="red">
{!error()?.length
? 'Something went wrong, please contact with us on discord'
: error()}
</Typography>
</Card>
</Match>
</Switch>
)
}
export default WiredWizard