Add help and Region dialog
This commit is contained in:
@@ -1,7 +1,44 @@
|
|||||||
import type React from "react";
|
import type React from "react";
|
||||||
|
|
||||||
import { Pane } from "evergreen-ui";
|
import { CogIcon, Dialog, Text } from "evergreen-ui";
|
||||||
|
|
||||||
export const HelpDialog = (): JSX.Element => {
|
import { TabbedContent, TabType } from "../layout/page/TabbedContent.js";
|
||||||
return <Pane></Pane>;
|
|
||||||
|
export interface HelpDialogProps {
|
||||||
|
isOpen: boolean;
|
||||||
|
close: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const HelpDialog = ({ isOpen, close }: HelpDialogProps): JSX.Element => {
|
||||||
|
const tabs: TabType[] = [
|
||||||
|
{
|
||||||
|
name: "Device Config",
|
||||||
|
icon: CogIcon,
|
||||||
|
element: () => (
|
||||||
|
<div>
|
||||||
|
<Text>Title</Text>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Device Config",
|
||||||
|
icon: CogIcon,
|
||||||
|
element: () => (
|
||||||
|
<div>
|
||||||
|
<Text>Title 2</Text>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog
|
||||||
|
isShown={isOpen}
|
||||||
|
onCloseComplete={close}
|
||||||
|
title="Meshtastic Web Help"
|
||||||
|
hasFooter={true}
|
||||||
|
>
|
||||||
|
<TabbedContent direction="vertical" tabs={tabs} />
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
import type React from "react";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
|
import { Dialog, SelectField } from "evergreen-ui";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
|
||||||
|
import { LoRaValidation } from "@app/validation/config/lora.js";
|
||||||
|
import { useDevice } from "@core/providers/useDevice.js";
|
||||||
|
import { renderOptions } from "@core/utils/selectEnumOptions.js";
|
||||||
|
import { classValidatorResolver } from "@hookform/resolvers/class-validator";
|
||||||
|
import { Protobuf } from "@meshtastic/meshtasticjs";
|
||||||
|
|
||||||
|
import { Form } from "../form/Form.js";
|
||||||
|
|
||||||
|
export interface RegionDialogProps {
|
||||||
|
isOpen: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const RegionDialog = ({ isOpen }: RegionDialogProps): JSX.Element => {
|
||||||
|
const { config, connection } = useDevice();
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const {
|
||||||
|
register,
|
||||||
|
handleSubmit,
|
||||||
|
formState: { errors, isDirty },
|
||||||
|
reset,
|
||||||
|
} = useForm<LoRaValidation>({
|
||||||
|
defaultValues: config.lora,
|
||||||
|
resolver: classValidatorResolver(LoRaValidation),
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
reset(config.lora);
|
||||||
|
}, [reset, config.lora]);
|
||||||
|
|
||||||
|
const onSubmit = handleSubmit((data) => {
|
||||||
|
setLoading(true);
|
||||||
|
void connection?.setConfig(
|
||||||
|
{
|
||||||
|
payloadVariant: {
|
||||||
|
oneofKind: "lora",
|
||||||
|
lora: data,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
async () => {
|
||||||
|
reset({ ...data });
|
||||||
|
setLoading(false);
|
||||||
|
await Promise.resolve();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog isShown={isOpen} title="Generate QR Code" hasFooter={false}>
|
||||||
|
<Form loading={loading} dirty={isDirty} onSubmit={onSubmit}>
|
||||||
|
<SelectField
|
||||||
|
label="Region"
|
||||||
|
description="This is a description."
|
||||||
|
isInvalid={!!errors.region?.message}
|
||||||
|
validationMessage={errors.region?.message}
|
||||||
|
{...register("region", { valueAsNumber: true })}
|
||||||
|
>
|
||||||
|
{renderOptions(Protobuf.Config_LoRaConfig_RegionCode)}
|
||||||
|
</SelectField>
|
||||||
|
</Form>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -18,8 +18,9 @@ import {
|
|||||||
} from "evergreen-ui";
|
} from "evergreen-ui";
|
||||||
import { FiGithub } from "react-icons/fi";
|
import { FiGithub } from "react-icons/fi";
|
||||||
|
|
||||||
import { useAppStore } from "@app/core/stores/appStore.js";
|
import { HelpDialog } from "@components/Dialog/HelpDialog.js";
|
||||||
import { NewDevice } from "@components/SlideSheets/NewDevice.js";
|
import { NewDevice } from "@components/SlideSheets/NewDevice.js";
|
||||||
|
import { useAppStore } from "@core/stores/appStore.js";
|
||||||
import { useDeviceStore } from "@core/stores/deviceStore.js";
|
import { useDeviceStore } from "@core/stores/deviceStore.js";
|
||||||
import { Hashicon } from "@emeraldpay/hashicon-react";
|
import { Hashicon } from "@emeraldpay/hashicon-react";
|
||||||
import { Types } from "@meshtastic/meshtasticjs";
|
import { Types } from "@meshtastic/meshtasticjs";
|
||||||
@@ -27,6 +28,7 @@ import { Types } from "@meshtastic/meshtasticjs";
|
|||||||
export const Header = (): JSX.Element => {
|
export const Header = (): JSX.Element => {
|
||||||
const { getDevices, removeDevice } = useDeviceStore();
|
const { getDevices, removeDevice } = useDeviceStore();
|
||||||
const [newConnectionOpen, setNewConnectionOpen] = useState(false);
|
const [newConnectionOpen, setNewConnectionOpen] = useState(false);
|
||||||
|
const [helpDialogOpen, setHelpDialogOpen] = useState(false);
|
||||||
const { selectedDevice, setSelectedDevice } = useAppStore();
|
const { selectedDevice, setSelectedDevice } = useAppStore();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -142,7 +144,18 @@ export const Header = (): JSX.Element => {
|
|||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<IconButton icon={HelpIcon} />
|
<IconButton
|
||||||
|
icon={HelpIcon}
|
||||||
|
onClick={() => {
|
||||||
|
setHelpDialogOpen(true);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<HelpDialog
|
||||||
|
isOpen={helpDialogOpen}
|
||||||
|
close={() => {
|
||||||
|
setHelpDialogOpen(false);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
<Tooltip content="Visit Meshtastic.org">
|
<Tooltip content="Visit Meshtastic.org">
|
||||||
<Link target="_blank" href="https://meshtastic.org/">
|
<Link target="_blank" href="https://meshtastic.org/">
|
||||||
<IconButton icon={GlobeIcon} />
|
<IconButton icon={GlobeIcon} />
|
||||||
|
|||||||
Reference in New Issue
Block a user