diff --git a/src/components/form/Input.tsx b/src/components/form/Input.tsx index 8b09dc66..4a02d27d 100644 --- a/src/components/form/Input.tsx +++ b/src/components/form/Input.tsx @@ -1,35 +1,32 @@ import React from 'react'; +type DefaultInputProps = JSX.IntrinsicElements['input']; + export interface InputProps { valid?: boolean; - placeholder?: string; validationMessage?: string; icon?: JSX.Element; - type: string; - name: string; - value?: string; - disabled?: boolean; - onChange: (event: React.ChangeEvent) => void; + label: string; } -export const Input = ({ - valid, - placeholder, - validationMessage, - icon, - type, - name, - value, - disabled, - onChange, -}: InputProps): JSX.Element => { +export const Input = React.forwardRef< + HTMLInputElement, + InputProps & DefaultInputProps +>(function Input( + { + valid, + validationMessage, + icon, + label, + id, + ...props + }: InputProps & DefaultInputProps, + ref, +) { return (
-
{!valid && ( @@ -57,4 +49,4 @@ export const Input = ({ )} ); -}; +}); diff --git a/src/components/form/Select.tsx b/src/components/form/Select.tsx new file mode 100644 index 00000000..b95a3cdb --- /dev/null +++ b/src/components/form/Select.tsx @@ -0,0 +1,38 @@ +import React from 'react'; + +type DefaultSelectProps = JSX.IntrinsicElements['select']; + +export interface SelectProps { + options: { + value: string; + label: string; + }[]; + label: string; +} + +export const Select = React.forwardRef< + HTMLSelectElement, + SelectProps & DefaultSelectProps +>(function Select( + { options, label, id, ...props }: SelectProps & DefaultSelectProps, + ref, +) { + return ( +
+ + +
+ ); +}); diff --git a/src/components/form/Toggle.tsx b/src/components/form/Toggle.tsx index 02d8b11e..94b50775 100644 --- a/src/components/form/Toggle.tsx +++ b/src/components/form/Toggle.tsx @@ -1,26 +1,33 @@ import React from 'react'; -import { Switch } from '@headlessui/react'; +type DefaultInputProps = JSX.IntrinsicElements['input']; export interface ToggleProps { - enabled: boolean; - setEnabled: (state: boolean) => void; + label: string; } -export const Toggle = ({ enabled, setEnabled }: ToggleProps): JSX.Element => { +export const Toggle = React.forwardRef< + HTMLInputElement, + ToggleProps & DefaultInputProps +>(function Input( + { label, id, checked, ...props }: ToggleProps & DefaultInputProps, + ref, +) { return ( - - Use setting - +
+ {label} +
+ + +
+
); -}; +}); diff --git a/src/pages/Settings.tsx b/src/pages/Settings.tsx index 2e998106..3eacc992 100644 --- a/src/pages/Settings.tsx +++ b/src/pages/Settings.tsx @@ -1,10 +1,15 @@ import React from 'react'; +import { useForm } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; +import { Protobuf } from '@meshtastic/meshtasticjs'; + import { Input } from '../components/form/Input'; +import { Select } from '../components/form/Select'; import { Toggle } from '../components/form/Toggle'; import { PrimaryTemplate } from '../components/templates/PrimaryTemplate'; +import { connection } from '../connection'; import { useAppDispatch, useAppSelector } from '../hooks/redux'; import { setHostOverride, @@ -21,6 +26,16 @@ export const Settings = (): JSX.Element => { (state) => state.meshtastic.hostOverrideEnabled, ); + const { register, handleSubmit } = + useForm({ + defaultValues: radioConfig, + }); + + const onSubmit = handleSubmit((data) => { + console.log(data); + connection.setPreferences(data); + }); + const [localHostOverride, setLocalHostOverride] = React.useState(hostOverride); const [localHostOverrideEnabled, setLocalHostOverrideEnabled] = @@ -28,57 +43,108 @@ export const Settings = (): JSX.Element => { return ( -
-
WiFi
-
- {}} - type="text" - valid={true} - /> - {}} - type="password" - valid={true} - /> -
-
-
-
Client
-
- { - setLocalHostOverrideEnabled(state); - }} - /> - { - setLocalHostOverride(event.target.value); - }} - type="text" - valid={true} - disabled={!localHostOverrideEnabled} - /> +
+
+
+
WiFi
+
+ + +
+
+
+
Node
+
+ + + + + + + + { + setLocalHostOverride(event.target.value); + }} + type="text" + valid={true} + disabled={!localHostOverrideEnabled} + /> +
+
-
- + + ); };