WIP
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import React from 'react';
|
||||
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { connection } from '@app/core/connection';
|
||||
import { useAppSelector } from '@app/hooks/redux';
|
||||
import { Button } from '@components/generic/Button';
|
||||
import { Input } from '@components/generic/Input';
|
||||
import { PrimaryTemplate } from '@components/templates/PrimaryTemplate';
|
||||
import { MenuIcon, SaveIcon } from '@heroicons/react/outline';
|
||||
import type { Protobuf } from '@meshtastic/meshtasticjs';
|
||||
|
||||
export interface DeviceProps {
|
||||
navOpen: boolean;
|
||||
setNavOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
}
|
||||
|
||||
export const Device = ({ navOpen, setNavOpen }: DeviceProps): JSX.Element => {
|
||||
const { t } = useTranslation();
|
||||
const radioConfig = useAppSelector((state) => state.meshtastic.preferences);
|
||||
|
||||
const { register, handleSubmit, formState } =
|
||||
useForm<Protobuf.RadioConfig_UserPreferences>({
|
||||
defaultValues: radioConfig,
|
||||
});
|
||||
|
||||
const onSubmit = handleSubmit((data) => {
|
||||
void connection.setPreferences(data);
|
||||
});
|
||||
|
||||
return (
|
||||
<PrimaryTemplate
|
||||
title="Device"
|
||||
tagline="Settings"
|
||||
button={
|
||||
<Button
|
||||
icon={<MenuIcon className="w-5 h-5" />}
|
||||
onClick={(): void => {
|
||||
setNavOpen(!navOpen);
|
||||
}}
|
||||
circle
|
||||
/>
|
||||
}
|
||||
footer={
|
||||
<Button
|
||||
className="px-10 ml-auto"
|
||||
icon={<SaveIcon className="w-5 h-5" />}
|
||||
disabled={!formState.isDirty}
|
||||
active
|
||||
border
|
||||
>
|
||||
{t('strings.save_changes')}
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<div className="w-full max-w-3xl space-y-2 md:max-w-xl">
|
||||
<form onSubmit={onSubmit}>
|
||||
<Input label={t('strings.wifi_ssid')} {...register('wifiSsid')} />
|
||||
<Input
|
||||
type="password"
|
||||
label={t('strings.wifi_psk')}
|
||||
{...register('wifiPassword')}
|
||||
/>
|
||||
</form>
|
||||
</div>
|
||||
</PrimaryTemplate>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,101 @@
|
||||
import React from 'react';
|
||||
|
||||
import { useBreakpoint } from '@app/hooks/breakpoint';
|
||||
import { Button } from '@components/generic/Button';
|
||||
import { Drawer } from '@components/generic/Drawer';
|
||||
import { SidebarItem } from '@components/generic/SidebarItem';
|
||||
import { Tab } from '@headlessui/react';
|
||||
import {
|
||||
CollectionIcon,
|
||||
DeviceMobileIcon,
|
||||
WifiIcon,
|
||||
XCircleIcon,
|
||||
} from '@heroicons/react/outline';
|
||||
|
||||
import { Device } from './Device';
|
||||
import { Interface } from './Interface';
|
||||
import { Radio } from './Radio';
|
||||
|
||||
export const Settings = (): JSX.Element => {
|
||||
const [navOpen, setNavOpen] = React.useState(false);
|
||||
|
||||
const { breakpoint } = useBreakpoint();
|
||||
|
||||
return (
|
||||
<Tab.Group>
|
||||
<div className="relative flex w-full dark:text-white">
|
||||
<Drawer
|
||||
open={breakpoint === 'sm' ? navOpen : true}
|
||||
permenant={breakpoint !== 'sm'}
|
||||
onClose={(): void => {
|
||||
setNavOpen(!navOpen);
|
||||
}}
|
||||
>
|
||||
<Tab.List className="flex flex-col border-b divide-y divide-gray-300 dark:divide-gray-600 dark:border-gray-600">
|
||||
<div className="flex items-center justify-between m-8 mr-6 md:my-10">
|
||||
<div className="text-4xl font-extrabold leading-none tracking-tight">
|
||||
Settings
|
||||
</div>
|
||||
<div className="md:hidden">
|
||||
<Button
|
||||
icon={<XCircleIcon className="w-5 h-5" />}
|
||||
circle
|
||||
onClick={(): void => {
|
||||
setNavOpen(false);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<Tab
|
||||
onClick={(): void => {
|
||||
setNavOpen(false);
|
||||
}}
|
||||
>
|
||||
{({ selected }): JSX.Element => (
|
||||
<SidebarItem
|
||||
title="Device"
|
||||
description="Device settings, such as device name and wifi settings"
|
||||
selected={selected}
|
||||
icon={<DeviceMobileIcon className="flex-shrink-0 w-6 h-6" />}
|
||||
/>
|
||||
)}
|
||||
</Tab>
|
||||
<Tab>
|
||||
{({ selected }): JSX.Element => (
|
||||
<SidebarItem
|
||||
title="Radio"
|
||||
description="Adjust radio power and frequency settings"
|
||||
selected={selected}
|
||||
icon={<WifiIcon className="flex-shrink-0 w-6 h-6" />}
|
||||
/>
|
||||
)}
|
||||
</Tab>
|
||||
<Tab>
|
||||
{({ selected }): JSX.Element => (
|
||||
<SidebarItem
|
||||
title="Interface"
|
||||
description="Change language and other UI settings"
|
||||
selected={selected}
|
||||
icon={<CollectionIcon className="flex-shrink-0 w-6 h-6" />}
|
||||
/>
|
||||
)}
|
||||
</Tab>
|
||||
</Tab.List>
|
||||
</Drawer>
|
||||
<div className="flex w-full">
|
||||
<Tab.Panels className="flex w-full">
|
||||
<Tab.Panel className="flex w-full">
|
||||
<Device navOpen={navOpen} setNavOpen={setNavOpen} />
|
||||
</Tab.Panel>
|
||||
<Tab.Panel className="flex w-full">
|
||||
<Radio navOpen={navOpen} setNavOpen={setNavOpen} />
|
||||
</Tab.Panel>
|
||||
<Tab.Panel className="flex w-full">
|
||||
<Interface navOpen={navOpen} setNavOpen={setNavOpen} />
|
||||
</Tab.Panel>
|
||||
</Tab.Panels>
|
||||
</div>
|
||||
</div>
|
||||
</Tab.Group>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,76 @@
|
||||
import React from 'react';
|
||||
|
||||
import { Jp, Pt, Us } from 'react-flags-select';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Select } from '@app/components/generic/Select';
|
||||
import i18n from '@app/core/translation';
|
||||
import { Button } from '@components/generic/Button';
|
||||
import { PrimaryTemplate } from '@components/templates/PrimaryTemplate';
|
||||
import { MenuIcon, SaveIcon } from '@heroicons/react/outline';
|
||||
|
||||
export interface InterfaceProps {
|
||||
navOpen: boolean;
|
||||
setNavOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
}
|
||||
|
||||
export const Interface = ({
|
||||
navOpen,
|
||||
setNavOpen,
|
||||
}: InterfaceProps): JSX.Element => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<PrimaryTemplate
|
||||
title="Interface"
|
||||
tagline="Settings"
|
||||
button={
|
||||
<Button
|
||||
icon={<MenuIcon className="w-5 h-5" />}
|
||||
onClick={(): void => {
|
||||
setNavOpen(!navOpen);
|
||||
}}
|
||||
circle
|
||||
/>
|
||||
}
|
||||
footer={
|
||||
<Button
|
||||
className="px-10 ml-auto"
|
||||
icon={<SaveIcon className="w-5 h-5" />}
|
||||
active
|
||||
border
|
||||
>
|
||||
{t('strings.save_changes')}
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<div className="w-full max-w-3xl space-y-2 md:max-w-xl">
|
||||
<Select
|
||||
label="Language"
|
||||
value={i18n.language}
|
||||
onChange={(value): void => {
|
||||
void i18n.changeLanguage(value);
|
||||
}}
|
||||
id="aaa"
|
||||
options={[
|
||||
{
|
||||
name: 'English',
|
||||
value: 'en',
|
||||
icon: <Us className="w-6" />,
|
||||
},
|
||||
{
|
||||
name: 'Português',
|
||||
value: 'pt',
|
||||
icon: <Pt className="w-6" />,
|
||||
},
|
||||
{
|
||||
name: 'Japanese',
|
||||
value: 'jp',
|
||||
icon: <Jp className="w-6" />,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
</PrimaryTemplate>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,47 @@
|
||||
import React from 'react';
|
||||
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Button } from '@components/generic/Button';
|
||||
import { Input } from '@components/generic/Input';
|
||||
import { PrimaryTemplate } from '@components/templates/PrimaryTemplate';
|
||||
import { MenuIcon, SaveIcon } from '@heroicons/react/outline';
|
||||
|
||||
export interface RadioProps {
|
||||
navOpen: boolean;
|
||||
setNavOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
}
|
||||
|
||||
export const Radio = ({ navOpen, setNavOpen }: RadioProps): JSX.Element => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<PrimaryTemplate
|
||||
title="Radio"
|
||||
tagline="Settings"
|
||||
button={
|
||||
<Button
|
||||
icon={<MenuIcon className="w-5 h-5" />}
|
||||
onClick={(): void => {
|
||||
setNavOpen(!navOpen);
|
||||
}}
|
||||
circle
|
||||
/>
|
||||
}
|
||||
footer={
|
||||
<Button
|
||||
className="px-10 ml-auto"
|
||||
icon={<SaveIcon className="w-5 h-5" />}
|
||||
active
|
||||
border
|
||||
>
|
||||
{t('strings.save_changes')}
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<div className="w-full max-w-3xl space-y-2 md:max-w-xl">
|
||||
<Input label="test" />
|
||||
</div>
|
||||
</PrimaryTemplate>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user