feat(messaging): hide new message bar on esc or sent message

This commit is contained in:
Paul 2021-12-24 17:20:05 +00:00
parent b2c24d33ed
commit af3eb754f7
3 changed files with 13 additions and 0 deletions

View file

@ -192,6 +192,7 @@ export default observer(({ channel }: Props) => {
if (uploadState.type === "attached") return sendFile(content);
if (content.length === 0) return;
internalEmit("NewMessages", "hide");
stopTyping();
setMessage();
setReplies([]);

View file

@ -6,6 +6,7 @@ import { decodeTime } from "ulid";
import { useEffect, useState } from "preact/hooks";
import { internalSubscribe } from "../../../../lib/eventEmitter";
import { getRenderer } from "../../../../lib/renderer/Singleton";
import { dayjs } from "../../../../context/Locale";
@ -15,7 +16,17 @@ import { Bar } from "./JumpToBottom";
export default observer(
({ channel, last_id }: { channel: Channel; last_id?: string }) => {
const [hidden, setHidden] = useState(false);
const hide = () => setHidden(true);
useEffect(() => setHidden(false), [last_id]);
useEffect(() => internalSubscribe("NewMessages", "hide", hide), []);
useEffect(() => {
const onKeyDown = (e: KeyboardEvent) =>
e.key === "Escape" && hide();
document.addEventListener("keydown", onKeyDown);
return () => document.removeEventListener("keydown", onKeyDown);
}, []);
const renderer = getRenderer(channel);
const history = useHistory();

View file

@ -29,3 +29,4 @@ export function internalEmit(ns: string, event: string, ...args: unknown[]) {
// - ReplyBar/add
// - Modal/close
// - PWA/update
// - NewMessages/hide