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.
OFF0 2 years ago
parent fdcba88bf2
commit 4ba3f62f12
Signed by: offbyn
GPG Key ID: 94A2F643C51F37FA

@ -294,10 +294,19 @@ const handleLink = (a: HTMLAnchorElement, e: MouseEvent) => {
}; };
const handleButton = (button: HTMLButtonElement) => { const handleButton = (button: HTMLButtonElement) => {
const id = (button.closest('[data-id]') as HTMLElement)?.dataset.id; switch(button.name) {
if (!id) { case 'settings':
toggleSettingsView();
return;
case 'new-note':
togglePublishView();
return;
case 'back':
closePublishView();
return; return;
} }
const id = (button.closest('[data-id]') as HTMLElement)?.dataset.id;
if (id) {
switch(button.name) { switch(button.name) {
case 'reply': case 'reply':
openWriteInput(button, id); openWriteInput(button, id);
@ -306,15 +315,7 @@ const handleButton = (button: HTMLButtonElement) => {
const note = replyList.find(r => r.id === id) || textNoteList.find(n => n.id === (id)); const note = replyList.find(r => r.id === id) || textNoteList.find(n => n.id === (id));
note && handleUpvote(note); note && handleUpvote(note);
break; break;
case 'settings': }
toggleSettingsView();
break;
case 'new-note':
togglePublishView();
break;
case 'back':
closePublishView();
break;
} }
// const container = e.target.closest('[data-append]'); // const container = e.target.closest('[data-append]');
// if (container) { // if (container) {
@ -325,15 +326,14 @@ const handleButton = (button: HTMLButtonElement) => {
}; };
document.body.addEventListener('click', (event: MouseEvent) => { document.body.addEventListener('click', (event: MouseEvent) => {
if (event.target instanceof HTMLElement) { const target = event.target as HTMLElement;
const a = event.target?.closest('a'); const a = target?.closest('a');
if (a) { if (a) {
handleLink(a, event); handleLink(a, event);
return; return;
} }
const button = event.target.closest('button'); const button = target?.closest('button');
if (button) { if (button) {
handleButton(button); handleButton(button);
} }
}
}); });

Loading…
Cancel
Save