Skip to content
Snippets Groups Projects
Commit 8cfbe1ca authored by insert's avatar insert
Browse files

Fluff: Jump to bottom when editing last message in chat. (up arrow)

parent 9bbbf5ff
No related merge requests found
......@@ -18,6 +18,7 @@ export function internalEmit(ns: string, event: string, ...args: any[]) {
// Event structure: namespace/event
/// Event List
// - MessageArea/jump_to_bottom
// - MessageRenderer/edit_last
// - MessageRenderer/edit_message
// - Intermediate/open_profile
......
......@@ -12,7 +12,7 @@ import {
} from "preact/hooks";
import { defer } from "../../../lib/defer";
import { internalEmit } from "../../../lib/eventEmitter";
import { internalEmit, internalSubscribe } from "../../../lib/eventEmitter";
import { SingletonMessageRenderer } from "../../../lib/renderer/Singleton";
import { RenderState, ScrollState } from "../../../lib/renderer/types";
......@@ -132,6 +132,12 @@ export function MessageArea({ id }: Props) {
const atTop = (offset = 0) =>
ref.current ? ref.current.scrollTop <= offset : false;
// ? Handle global jump to bottom, e.g. when editing last message in chat.
useEffect(() => {
return internalSubscribe('MessageArea', 'jump_to_bottom',
() => setScrollState({ type: 'ScrollToBottom' }));
}, []);
// ? Handle events from renderer.
useEffect(() => {
SingletonMessageRenderer.addListener("state", setState);
......
......@@ -60,6 +60,7 @@ function MessageRenderer({ id, state, queue }: Props) {
for (let i = state.messages.length - 1; i >= 0; i--) {
if (state.messages[i].author === userId) {
setEditing(state.messages[i]._id);
internalEmit('MessageArea', 'jump_to_bottom');
return;
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment