import type React from 'react'; import { useState } from 'react'; import { useForm } from 'react-hook-form'; import { Checkbox } from '@components/generic/form/Checkbox'; import { Form } from '@components/generic/form/Form'; import { Input } from '@components/generic/form/Input'; import { Select } from '@components/generic/form/Select'; import { connection } from '@core/connection'; import { useAppSelector } from '@hooks/useAppSelector'; import { Protobuf } from '@meshtastic/meshtasticjs'; export const Channels = (): JSX.Element => { const channels = useAppSelector((state) => state.meshtastic.radio.channels); const adminChannel = channels.find( (channel) => channel.role === Protobuf.Channel_Role.PRIMARY, ) ?? channels[0]; const [usePreset, setUsePreset] = useState(true); const [loading, setLoading] = useState(false); const [selectedChannel, setSelectedChannel] = useState< Protobuf.Channel | undefined >(); const { register, handleSubmit, reset, formState } = useForm< DeepOmit >({ defaultValues: { ...adminChannel, }, }); const onSubmit = handleSubmit(async (data) => { setLoading(true); const channelData = Protobuf.Channel.create({ ...data, settings: { ...data.settings, psk: adminChannel.settings?.psk, }, }); await connection.setChannel(channelData, (): Promise => { reset({ ...data }); setLoading(false); return Promise.resolve(); }); }); return ( <> {adminChannel && ( <> setUsePreset(e.target.checked)} />
{usePreset ? ( )}
)} ); };