From 950a528b2b5974e57d90650df8304eec6103642d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oriol=20G=C3=B3mez?= Date: Tue, 3 Sep 2024 16:08:54 +0200 Subject: [PATCH] feat: focus the previous/next message when one is deleted. If 0 messages, focus input --- frontend/src/api.ts | 1 + frontend/src/ui/list.ts | 1 + frontend/src/views/main.ts | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/frontend/src/api.ts b/frontend/src/api.ts index 1d20a3b..c405bf4 100644 --- a/frontend/src/api.ts +++ b/frontend/src/api.ts @@ -54,6 +54,7 @@ export const API = { async getMessages(channelId: string) { const response = await API.request("GET", `channels/${channelId}/messages`); + console.log(response) const json = await response.json(); return json.messages as IMessage[]; }, diff --git a/frontend/src/ui/list.ts b/frontend/src/ui/list.ts index 6b221e8..81d46a6 100644 --- a/frontend/src/ui/list.ts +++ b/frontend/src/ui/list.ts @@ -44,6 +44,7 @@ export class List extends UINode { if (idx === this.focused) { if (this.focused > 0) this.focused--; this.calculateTabIndex(); + this.children[this.focused].focus() } return this; } diff --git a/frontend/src/views/main.ts b/frontend/src/views/main.ts index d62aa16..ea0b1a6 100644 --- a/frontend/src/views/main.ts +++ b/frontend/src/views/main.ts @@ -231,7 +231,9 @@ export class MainView extends View { itm.onKeyDown((key: string, alt: boolean | undefined, shift: boolean | undefined, ctrl: boolean | undefined) => { if (key === "Delete") { this.removeMessage(message.id); - this.messageInput.focus() + if (this.messageList.children.length === 1) { + this.messageInput.focus() + } } }); return itm;