mirror of
https://github.com/revoltchat/revite.git
synced 2024-12-01 11:20:58 -05:00
feat(messaging): hide new message bar on esc or sent message
This commit is contained in:
parent
b2c24d33ed
commit
af3eb754f7
3 changed files with 13 additions and 0 deletions
|
@ -192,6 +192,7 @@ export default observer(({ channel }: Props) => {
|
||||||
if (uploadState.type === "attached") return sendFile(content);
|
if (uploadState.type === "attached") return sendFile(content);
|
||||||
if (content.length === 0) return;
|
if (content.length === 0) return;
|
||||||
|
|
||||||
|
internalEmit("NewMessages", "hide");
|
||||||
stopTyping();
|
stopTyping();
|
||||||
setMessage();
|
setMessage();
|
||||||
setReplies([]);
|
setReplies([]);
|
||||||
|
|
|
@ -6,6 +6,7 @@ import { decodeTime } from "ulid";
|
||||||
|
|
||||||
import { useEffect, useState } from "preact/hooks";
|
import { useEffect, useState } from "preact/hooks";
|
||||||
|
|
||||||
|
import { internalSubscribe } from "../../../../lib/eventEmitter";
|
||||||
import { getRenderer } from "../../../../lib/renderer/Singleton";
|
import { getRenderer } from "../../../../lib/renderer/Singleton";
|
||||||
|
|
||||||
import { dayjs } from "../../../../context/Locale";
|
import { dayjs } from "../../../../context/Locale";
|
||||||
|
@ -15,7 +16,17 @@ import { Bar } from "./JumpToBottom";
|
||||||
export default observer(
|
export default observer(
|
||||||
({ channel, last_id }: { channel: Channel; last_id?: string }) => {
|
({ channel, last_id }: { channel: Channel; last_id?: string }) => {
|
||||||
const [hidden, setHidden] = useState(false);
|
const [hidden, setHidden] = useState(false);
|
||||||
|
const hide = () => setHidden(true);
|
||||||
|
|
||||||
useEffect(() => setHidden(false), [last_id]);
|
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 renderer = getRenderer(channel);
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
|
|
@ -29,3 +29,4 @@ export function internalEmit(ns: string, event: string, ...args: unknown[]) {
|
||||||
// - ReplyBar/add
|
// - ReplyBar/add
|
||||||
// - Modal/close
|
// - Modal/close
|
||||||
// - PWA/update
|
// - PWA/update
|
||||||
|
// - NewMessages/hide
|
||||||
|
|
Loading…
Reference in a new issue