Skip to content

Commit 8ac5cc0

Browse files
committed
setup default mdns
1 parent 7327523 commit 8ac5cc0

5 files changed

Lines changed: 100 additions & 23 deletions

File tree

src/components/Cards/NetworkCard/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import DefaultButton from '@components/Buttons/DefaultButton'
33
import NetworkBars from '@components/NetworkBars'
44
import Typography from '@components/Typography'
55
import { INetwork } from '@src/esp/interfaces/interfaces'
6-
import { shortMdnsAddress } from '@src/utils'
76
import { FaSolidWifi } from 'solid-icons/fa'
87
import { IoChevronBackSharp } from 'solid-icons/io'
98
import { Component, For, Show } from 'solid-js'

src/containers/FlashWizard/WirelessWizard/index.tsx

Lines changed: 67 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Button from '@components/Buttons/Button'
12
import DefaultButton from '@components/Buttons/DefaultButton'
23
import SwitchButton from '@components/Buttons/Toggle'
34
import Card from '@components/Cards/Card'
@@ -18,6 +19,7 @@ import {
1819
import { NOTIFICATION_TYPE } from '@interfaces/notifications/enums'
1920
import { getApi } from '@src/esp'
2021
import { logger } from '@src/logger'
22+
import { TRACKERS } from '@src/static'
2123
import { formatMac, shortMdnsAddress } from '@src/utils'
2224
import { addNotification } from '@store/actions/notifications/addNotification'
2325
import { setAction, setStep } from '@store/animation/animation'
@@ -39,15 +41,15 @@ import {
3941
selectedNetwork,
4042
ssid,
4143
} from '@store/network/selectors'
42-
import { activeStepAction } from '@store/ui/selectors'
44+
import { activeStepAction, setupCustomMdns, setupMacAddress } from '@store/ui/selectors'
45+
import { setSetupCustomMdns, setSetupMacAddress } from '@store/ui/ui'
4346
import { writeText } from '@tauri-apps/api/clipboard'
4447
import { BiRegularError, BiRegularLoaderAlt } from 'solid-icons/bi'
4548
import { IoCheckmarkSharp } from 'solid-icons/io'
4649
import { RiSystemLockPasswordLine } from 'solid-icons/ri'
47-
import { batch, createMemo, createSignal, Match, onCleanup, Show, Switch } from 'solid-js'
50+
import { batch, createMemo, createSignal, For, Match, onCleanup, Show, Switch } from 'solid-js'
4851

4952
const WirelessWizard = () => {
50-
const [setupMacAddress, setSetupMacAddress] = createSignal(false)
5153
const [ipAddress, setIpAddress] = createSignal<string | undefined>('')
5254
const sortedNetworks = createMemo(() => {
5355
return [...availableNetworks()].sort((a, b) => {
@@ -120,6 +122,8 @@ const WirelessWizard = () => {
120122
setMac(formatMac(network.mac_address))
121123
setResetNetworkState()
122124
setSetupMacAddress(false)
125+
setSetupCustomMdns(false)
126+
setMdns('')
123127
setStep(WIRELESS_WIZARD_STEPS.WIRELESS_SETUP_CREDENTIALS)
124128
})
125129
}}
@@ -129,7 +133,9 @@ const WirelessWizard = () => {
129133
setStep(WIRELESS_WIZARD_STEPS.WIRELESS_MANUAL_SETUP)
130134
setSelectedNetwork(undefined)
131135
setSetupMacAddress(false)
136+
setSetupCustomMdns(false)
132137
setResetNetworkState()
138+
setMdns('')
133139
setSsid('')
134140
setMac('')
135141
})
@@ -197,7 +203,7 @@ const WirelessWizard = () => {
197203
<SwitchButton
198204
active={setupMacAddress()}
199205
onClick={() => {
200-
setSetupMacAddress((prev) => !prev)
206+
setSetupMacAddress(!setupMacAddress())
201207
}}
202208
/>
203209
</div>
@@ -251,7 +257,7 @@ const WirelessWizard = () => {
251257
<SwitchButton
252258
active={setupMacAddress()}
253259
onClick={() => {
254-
setSetupMacAddress((prev) => !prev)
260+
setSetupMacAddress(!setupMacAddress())
255261
}}
256262
/>
257263
</div>
@@ -345,25 +351,65 @@ const WirelessWizard = () => {
345351
The tracker will be accessible under
346352
</Typography>
347353
<Typography color="blue" text="caption">
348-
http://{!mdns().length ? 'openiristracker' : shortMdnsAddress(mdns())}
354+
http://
355+
{!mdns().length ? '- - - -' : shortMdnsAddress(mdns())}
349356
.local
350357
</Typography>
351358
</div>
352-
<div class="flex flex-col gap-10 w-full">
353-
<Typography color="white" text="caption" class="text-left">
354-
Setup tracker name
355-
</Typography>
356-
<NetworkInput
357-
id="mdns"
358-
type="text"
359-
onChange={(mdns) => {
360-
setMdns(mdns)
361-
}}
362-
value={mdns()}
363-
placeholder={
364-
!mdns().length ? 'openiristracker' : shortMdnsAddress(mdns())
365-
}
366-
/>
359+
<div class="w-full flex flex-col gap-24 items-end justify-end">
360+
<div class="flex flex-col gap-12 w-full">
361+
<Typography color="white" text="caption" class="text-left">
362+
Setup tracker name
363+
</Typography>
364+
<Show
365+
when={setupCustomMdns()}
366+
fallback={
367+
<div class="flex w-full flex-row gap-12">
368+
<For each={TRACKERS}>
369+
{(tracker) => (
370+
<Button
371+
size="h-[39px]"
372+
label={tracker.label}
373+
isActive={!!mdns().match(tracker.value)}
374+
onClick={() => {
375+
setMdns(
376+
mdns().match(tracker.value)
377+
? ''
378+
: tracker.value,
379+
)
380+
}}
381+
/>
382+
)}
383+
</For>
384+
</div>
385+
}>
386+
<NetworkInput
387+
id="mdns"
388+
type="text"
389+
onChange={(mdns) => {
390+
setMdns(mdns)
391+
}}
392+
value={mdns()}
393+
placeholder={
394+
!mdns().length
395+
? 'openiristracker'
396+
: shortMdnsAddress(mdns())
397+
}
398+
/>
399+
</Show>
400+
</div>
401+
<div class="flex w-full flex-row justify-between">
402+
<Typography color="white" text="caption" class="text-left">
403+
Setup Custom Mdns
404+
</Typography>
405+
<SwitchButton
406+
active={setupCustomMdns()}
407+
onClick={() => {
408+
setMdns('')
409+
setSetupCustomMdns(!setupCustomMdns())
410+
}}
411+
/>
412+
</div>
367413
</div>
368414
</Card>
369415
</Match>

src/static/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,8 @@ export const CHANNEL_OPTIONS: Record<CHANNEL_TYPE, IChannelOptions> = {
101101
description: 'Official channel for official releases.',
102102
},
103103
}
104+
105+
export const TRACKERS: Array<{ label: string; value: string }> = [
106+
{ label: 'Right eye', value: 'ETVR-Right' },
107+
{ label: 'Left eye', value: 'ETVR-Left' },
108+
]

src/store/ui/selectors.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
import { createStoreSelectors } from '@store/utils'
22
import { uiState } from './ui'
33

4-
export const { hideModal, openModal, activeStepAction, appVersion } = createStoreSelectors(uiState)
4+
export const {
5+
hideModal,
6+
openModal,
7+
activeStepAction,
8+
appVersion,
9+
setupMacAddress,
10+
setupCustomMdns,
11+
} = createStoreSelectors(uiState)

src/store/ui/ui.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export interface IOpenModal {
88
}
99

1010
export interface UiStore {
11+
setupMacAddress: boolean
12+
setupCustomMdns: boolean
1113
appVersion: string
1214
activeStepAction: STEP_ACTION
1315
openModal: IOpenModal
@@ -22,6 +24,8 @@ const defaultState: UiStore = {
2224
type: MODAL_TYPE.NONE,
2325
},
2426
hideModal: false,
27+
setupCustomMdns: false,
28+
setupMacAddress: false,
2529
}
2630

2731
const [state, setState] = createStore<UiStore>(defaultState)
@@ -58,4 +62,20 @@ export const setHideModal = () => {
5862
)
5963
}
6064

65+
export const setSetupMacAddress = (value: boolean) => {
66+
setState(
67+
produce((s) => {
68+
s.setupMacAddress = value
69+
}),
70+
)
71+
}
72+
73+
export const setSetupCustomMdns = (value: boolean) => {
74+
setState(
75+
produce((s) => {
76+
s.setupCustomMdns = value
77+
}),
78+
)
79+
}
80+
6181
export const uiState = () => state

0 commit comments

Comments
 (0)