From bbfa4ae54508c0d8b4fa18c99dffd794277161cf Mon Sep 17 00:00:00 2001 From: OFF0 Date: Sat, 8 Apr 2023 11:52:49 +0200 Subject: [PATCH] main: fix global click handler settings view and write new message didnt show. reason was typescript expected an instance of an HTMLElement but this didnt allow for SVG elements inside the write button. Another reason was that the condition expected a parent with data-id which isn't the case for settings button nor write-new-message. --- src/main.ts | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/main.ts b/src/main.ts index d921ee5..0d6fa7e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -294,27 +294,28 @@ const handleLink = (a: HTMLAnchorElement, e: MouseEvent) => { }; const handleButton = (button: HTMLButtonElement) => { - const id = (button.closest('[data-id]') as HTMLElement)?.dataset.id; - if (!id) { - return; - } switch(button.name) { - case 'reply': - openWriteInput(button, id); - break; - case 'star': - const note = replyList.find(r => r.id === id) || textNoteList.find(n => n.id === (id)); - note && handleUpvote(note); - break; case 'settings': toggleSettingsView(); - break; + return; case 'new-note': togglePublishView(); - break; + return; case 'back': closePublishView(); - break; + return; + } + const id = (button.closest('[data-id]') as HTMLElement)?.dataset.id; + if (id) { + switch(button.name) { + case 'reply': + openWriteInput(button, id); + break; + case 'star': + const note = replyList.find(r => r.id === id) || textNoteList.find(n => n.id === (id)); + note && handleUpvote(note); + break; + } } // const container = e.target.closest('[data-append]'); // if (container) { @@ -325,15 +326,14 @@ const handleButton = (button: HTMLButtonElement) => { }; document.body.addEventListener('click', (event: MouseEvent) => { - if (event.target instanceof HTMLElement) { - const a = event.target?.closest('a'); - if (a) { - handleLink(a, event); - return; - } - const button = event.target.closest('button'); - if (button) { - handleButton(button); - } + const target = event.target as HTMLElement; + const a = target?.closest('a'); + if (a) { + handleLink(a, event); + return; + } + const button = target?.closest('button'); + if (button) { + handleButton(button); } });