refactor: global click listener and cleanup

breaking up the global click callback to make it easier in the future
to move some parts into ui modules such as settings.ts.
pull/72/head
OFF0 2 years ago
parent 52e2a31421
commit 9a34d4f31e
Signed by: offbyn
GPG Key ID: 94A2F643C51F37FA

@ -483,22 +483,6 @@ writeInput.addEventListener('input', () => {
});
writeInput.addEventListener('blur', () => sendStatus.textContent = '');
document.body.onload = () => console.log('------------ pageload ------------')
// subscribe and change view
function route(path) {
if (path === '/') {
@ -532,11 +516,7 @@ window.addEventListener('popstate', (event) => {
const publishView = document.querySelector('#newNote');
document.body.addEventListener('click', (e) => {
const a = e.target.closest('a');
const pubkey = e.target.closest('[data-pubkey]')?.dataset.pubkey;
const id = e.target.closest('[data-id]')?.dataset.id;
if (a) {
const handleLink = (e, a) => {
if ('nav' in a.dataset) {
e.preventDefault();
closeSettingsView();
@ -548,10 +528,10 @@ document.body.addEventListener('click', (e) => {
history.pushState({}, null, href);
e.preventDefault();
}
return;
}
const button = e.target.closest('button');
if (button) {
};
const handleButton = (e, button) => {
const id = e.target.closest('[data-id]')?.dataset.id;
switch(button.name) {
case 'reply':
if (localStorage.getItem('reply_to') === id) {
@ -588,13 +568,24 @@ document.body.addEventListener('click', (e) => {
publishView.hidden = true;
break;
}
}
// const container = e.target.closest('[data-append]');
// if (container) {
// container.append(...parseTextContent(container.dataset.append));
// delete container.dataset.append;
// return;
// }
};
document.body.addEventListener('click', (e) => {
const a = e.target.closest('a');
if (a) {
handleLink(e, a);
return;
}
const button = e.target.closest('button');
if (button) {
handleButton(e, button);
}
});
// document.body.addEventListener('keyup', (e) => {

Loading…
Cancel
Save