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

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

Loading…
Cancel
Save