mirror of
https://github.com/revoltchat/revite.git
synced 2024-12-24 22:52:09 -05:00
Fluff: Jump to bottom when editing last message in chat. (up arrow)
This commit is contained in:
parent
9bbbf5ffc8
commit
8cfbe1ca3f
3 changed files with 9 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue