Merge remote-tracking branch 'origin/HEAD' into feature/node-quick-options
This commit is contained in:
@@ -18,6 +18,9 @@
|
|||||||
"simple-git-hooks": {
|
"simple-git-hooks": {
|
||||||
"pre-commit": "npm run check:fix && npm run format"
|
"pre-commit": "npm run check:fix && npm run format"
|
||||||
},
|
},
|
||||||
|
"lint-staged": {
|
||||||
|
"*.{ts,tsx}": ["npm run check:fix", "npm run format"]
|
||||||
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/meshtastic/web.git"
|
"url": "git+https://github.com/meshtastic/web.git"
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ export const ChannelChat = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="pl-3 pr-3 pt-3 pb-1">
|
<div className="pl-3 pr-3 pt-3 pb-1">
|
||||||
<MessageInput to={to} channel={channel} />
|
<MessageInput to={to} channel={channel} maxBytes={200} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,11 +9,13 @@ import { useCallback, useMemo, useState } from "react";
|
|||||||
export interface MessageInputProps {
|
export interface MessageInputProps {
|
||||||
to: Types.Destination;
|
to: Types.Destination;
|
||||||
channel: Types.ChannelNumber;
|
channel: Types.ChannelNumber;
|
||||||
|
maxBytes: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MessageInput = ({
|
export const MessageInput = ({
|
||||||
to,
|
to,
|
||||||
channel,
|
channel,
|
||||||
|
maxBytes,
|
||||||
}: MessageInputProps): JSX.Element => {
|
}: MessageInputProps): JSX.Element => {
|
||||||
const {
|
const {
|
||||||
connection,
|
connection,
|
||||||
@@ -24,6 +26,7 @@ export const MessageInput = ({
|
|||||||
} = useDevice();
|
} = useDevice();
|
||||||
const myNodeNum = hardware.myNodeNum;
|
const myNodeNum = hardware.myNodeNum;
|
||||||
const [localDraft, setLocalDraft] = useState(messageDraft);
|
const [localDraft, setLocalDraft] = useState(messageDraft);
|
||||||
|
const [messageBytes, setMessageBytes] = useState(maxBytes);
|
||||||
|
|
||||||
const debouncedSetMessageDraft = useMemo(
|
const debouncedSetMessageDraft = useMemo(
|
||||||
() => debounce(setMessageDraft, 300),
|
() => debounce(setMessageDraft, 300),
|
||||||
@@ -60,8 +63,12 @@ export const MessageInput = ({
|
|||||||
|
|
||||||
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
const newValue = e.target.value;
|
const newValue = e.target.value;
|
||||||
setLocalDraft(newValue);
|
const byteLength = new Blob([newValue]).size;
|
||||||
debouncedSetMessageDraft(newValue);
|
if (byteLength <= maxBytes) {
|
||||||
|
setLocalDraft(newValue);
|
||||||
|
debouncedSetMessageDraft(newValue);
|
||||||
|
setMessageBytes(maxBytes - byteLength);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -85,6 +92,9 @@ export const MessageInput = ({
|
|||||||
onChange={handleInputChange}
|
onChange={handleInputChange}
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
|
<div className="flex items-center">
|
||||||
|
{messageBytes}/{maxBytes}
|
||||||
|
</div>
|
||||||
<Button type="submit">
|
<Button type="submit">
|
||||||
<SendIcon size={16} />
|
<SendIcon size={16} />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user