feat: focus the previous/next message when one is deleted. If 0 messages, focus input

This commit is contained in:
2024-09-03 16:08:54 +02:00
parent 49c73a3d76
commit 950a528b2b
3 changed files with 5 additions and 1 deletions

View File

@@ -54,6 +54,7 @@ export const API = {
async getMessages(channelId: string) { async getMessages(channelId: string) {
const response = await API.request("GET", `channels/${channelId}/messages`); const response = await API.request("GET", `channels/${channelId}/messages`);
console.log(response)
const json = await response.json(); const json = await response.json();
return json.messages as IMessage[]; return json.messages as IMessage[];
}, },

View File

@@ -44,6 +44,7 @@ export class List extends UINode {
if (idx === this.focused) { if (idx === this.focused) {
if (this.focused > 0) this.focused--; if (this.focused > 0) this.focused--;
this.calculateTabIndex(); this.calculateTabIndex();
this.children[this.focused].focus()
} }
return this; return this;
} }

View File

@@ -231,8 +231,10 @@ export class MainView extends View {
itm.onKeyDown((key: string, alt: boolean | undefined, shift: boolean | undefined, ctrl: boolean | undefined) => { itm.onKeyDown((key: string, alt: boolean | undefined, shift: boolean | undefined, ctrl: boolean | undefined) => {
if (key === "Delete") { if (key === "Delete") {
this.removeMessage(message.id); this.removeMessage(message.id);
if (this.messageList.children.length === 1) {
this.messageInput.focus() this.messageInput.focus()
} }
}
}); });
return itm; return itm;
} }