Browse Source

biome

pull/266/head
Hunter Thornsberry 2 years ago
parent
commit
32acd23362
  1. 5
      src/components/Form/FormPasswordGenerator.tsx
  2. 13
      src/components/PageComponents/Channel.tsx
  3. 33
      src/components/UI/Generator.tsx

5
src/components/Form/FormPasswordGenerator.tsx

@ -21,12 +21,13 @@ export function PasswordGenerator<T extends FieldValues>({
render={({ field: { value, onChange, ...rest } }) => ( render={({ field: { value, onChange, ...rest } }) => (
<Generator <Generator
devicePSKBitCount={field.devicePSKBitCount} devicePSKBitCount={field.devicePSKBitCount}
changeEvent={onChange} changeEvent={onChange}
value={value} value={value}
variant={"success"} variant={"success"}
buttonText="Generate" buttonText="Generate"
{...field.properties} {...field.properties}
{...rest} /> {...rest}
/>
)} )}
/> />
); );

13
src/components/PageComponents/Channel.tsx

@ -15,8 +15,12 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
const { config, connection, addChannel } = useDevice(); const { config, connection, addChannel } = useDevice();
const { toast } = useToast(); const { toast } = useToast();
const [pass, setPass] = useState<string>(fromByteArray(channel?.settings?.psk ?? new Uint8Array(0))); const [pass, setPass] = useState<string>(
const [bitCount, setBits] = useState<number>(channel?.settings?.psk.length ?? 16); fromByteArray(channel?.settings?.psk ?? new Uint8Array(0)),
);
const [bitCount, setBits] = useState<number>(
channel?.settings?.psk.length ?? 16,
);
const onSubmit = (data: ChannelValidation) => { const onSubmit = (data: ChannelValidation) => {
const channel = new Protobuf.Channel.Channel({ const channel = new Protobuf.Channel.Channel({
@ -41,7 +45,6 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
}); });
}; };
const clickEventCb = (e) => { const clickEventCb = (e) => {
setPass( setPass(
btoa( btoa(
@ -51,7 +54,7 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
}), }),
), ),
); );
} };
return ( return (
<DynamicForm<ChannelValidation> <DynamicForm<ChannelValidation>
@ -101,7 +104,7 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
properties: { properties: {
value: pass, value: pass,
onClick: clickEventCb, onClick: clickEventCb,
changeEvent: (e: string) => setBits(parseInt(e)), changeEvent: (e: string) => setBits(Number.parseInt(e)),
}, },
}, },
{ {

33
src/components/UI/Generator.tsx

@ -10,9 +10,9 @@ import {
SelectTrigger, SelectTrigger,
SelectValue, SelectValue,
} from "@components/UI/Select.js"; } from "@components/UI/Select.js";
import { fromByteArray, toByteArray } from "base64-js";
import cryptoRandomString from "crypto-random-string"; import cryptoRandomString from "crypto-random-string";
import { useState } from "react"; import { useState } from "react";
import { fromByteArray, toByteArray } from "base64-js";
const generatorVariants = cva( const generatorVariants = cva(
"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus:outline-none focus:ring-2", "inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus:outline-none focus:ring-2",
@ -51,33 +51,24 @@ export interface GeneratorProps
devicePSKBitCount?: number; devicePSKBitCount?: number;
value: string; value: string;
buttonText?: string; buttonText?: string;
changeEvent: Function; changeEvent: (event: string) => void;
} }
const getBitString = (bitcount?: number) => { const getBitString = (bitcount?: number) => {
if (bitcount == 32) { if (bitcount === 32) {
return "32" return "32";
} }
if (bitcount == 1) { if (bitcount === 1) {
return "1" return "1";
} }
return "16" return "16";
} };
const Generator = React.forwardRef<HTMLInputElement, GeneratorProps>( const Generator = React.forwardRef<HTMLInputElement, GeneratorProps>(
( (
{ { devicePSKBitCount, value, buttonText, variant, changeEvent, ...props },
devicePSKBitCount,
value,
buttonText,
variant,
changeEvent,
...props
},
ref, ref,
) => { ) => {
return ( return (
<> <>
<Input type="text" id="pskInput" value={value} /> <Input type="text" id="pskInput" value={value} />
@ -100,11 +91,7 @@ const Generator = React.forwardRef<HTMLInputElement, GeneratorProps>(
</SelectItem> </SelectItem>
</SelectContent> </SelectContent>
</Select> </Select>
<Button <Button type="button" variant="success" {...props}>
type="button"
variant="success"
{...props}
>
{buttonText} {buttonText}
</Button> </Button>
</> </>

Loading…
Cancel
Save