Browse Source

chore: linting

pull/383/head
Dan Ditomaso 1 year ago
parent
commit
f0dd426055
  1. 59
      src/components/PageComponents/Messages/MessageInput.tsx
  2. 2
      src/core/utils/debounce.ts

59
src/components/PageComponents/Messages/MessageInput.tsx

@ -4,9 +4,7 @@ import { Input } from "@components/UI/Input.tsx";
import { useDevice } from "@core/stores/deviceStore.ts"; import { useDevice } from "@core/stores/deviceStore.ts";
import type { Types } from "@meshtastic/js"; import type { Types } from "@meshtastic/js";
import { SendIcon } from "lucide-react"; import { SendIcon } from "lucide-react";
import { useCallback, useState, useMemo } from "react"; import { useCallback, useMemo, useState } from "react";
export interface MessageInputProps { export interface MessageInputProps {
to: Types.Destination; to: Types.Destination;
@ -29,33 +27,36 @@ export const MessageInput = ({
const debouncedSetMessageDraft = useMemo( const debouncedSetMessageDraft = useMemo(
() => debounce(setMessageDraft, 300), () => debounce(setMessageDraft, 300),
[setMessageDraft] [setMessageDraft],
); );
const sendText = useCallback(async (message: string) => { const sendText = useCallback(
await connection async (message: string) => {
?.sendText(message, to, true, channel) await connection
.then((id) => ?.sendText(message, to, true, channel)
setMessageState( .then((id) =>
to === "broadcast" ? "broadcast" : "direct", setMessageState(
channel, to === "broadcast" ? "broadcast" : "direct",
to as number, channel,
myNodeNum, to as number,
id, myNodeNum,
"ack", id,
), "ack",
) ),
.catch((e: Types.PacketError) => )
setMessageState( .catch((e: Types.PacketError) =>
to === "broadcast" ? "broadcast" : "direct", setMessageState(
channel, to === "broadcast" ? "broadcast" : "direct",
to as number, channel,
myNodeNum, to as number,
e.id, myNodeNum,
e.error, e.id,
), e.error,
); ),
}, [channel, connection, myNodeNum, setMessageState, to]); );
},
[channel, connection, myNodeNum, setMessageState, to],
);
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => { const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const newValue = e.target.value; const newValue = e.target.value;
@ -91,4 +92,4 @@ export const MessageInput = ({
</form> </form>
</div> </div>
); );
}; };

2
src/core/utils/debounce.ts

@ -2,7 +2,7 @@ type Callback<Args extends unknown[]> = (...args: Args) => void;
export function debounce<Args extends unknown[]>( export function debounce<Args extends unknown[]>(
callback: Callback<Args>, callback: Callback<Args>,
wait: number wait: number,
): Callback<Args> { ): Callback<Args> {
let timeoutId: ReturnType<typeof setTimeout>; let timeoutId: ReturnType<typeof setTimeout>;

Loading…
Cancel
Save