From 38b056429e3dbdd650699a58667361a582a8e436 Mon Sep 17 00:00:00 2001 From: dragonwocky Date: Sun, 19 Mar 2023 18:43:57 +1100 Subject: [PATCH] feat(menu): indicate upload status of file inputs with label change --- src/core/menu/components/Input.mjs | 12 ++++++- src/core/menu/islands/Onboarding.mjs | 2 ++ src/core/menuu/client.mjs | 48 ---------------------------- 3 files changed, 13 insertions(+), 49 deletions(-) delete mode 100644 src/core/menuu/client.mjs diff --git a/src/core/menu/components/Input.mjs b/src/core/menu/components/Input.mjs index 8ba512c..7b9f8b0 100644 --- a/src/core/menu/components/Input.mjs +++ b/src/core/menu/components/Input.mjs @@ -120,9 +120,19 @@ function Input({ let _initialValue; extendProps($input, { + onclick: () => { + // change text to "uploading..." until file has uploaded + // to reassure users experiencing latency while file is processed + if (type === "file") $filename.innerText = "Uploading..."; + }, onchange: (event) => { if (_set && type === "file") { - readUpload(event).then(_set); + readUpload(event) + .then(_set) + // refocus iframe after file has uploaded, + // sometimes switching back after opening the + // native file upload menu causes a loss of focus + .then(() => window.focus()); } else _set?.($input.value); }, onrerender: async () => { diff --git a/src/core/menu/islands/Onboarding.mjs b/src/core/menu/islands/Onboarding.mjs index 83cd105..2167901 100644 --- a/src/core/menu/islands/Onboarding.mjs +++ b/src/core/menu/islands/Onboarding.mjs @@ -42,6 +42,8 @@ function Onboarding() { notion-enhancer's privacy policy and terms & conditions.
+ <${Checkbox} _set=${(checked) => ($submitAgreement.disabled = !checked)} _requireReload=${false} diff --git a/src/core/menuu/client.mjs b/src/core/menuu/client.mjs deleted file mode 100644 index 62b06e7..0000000 --- a/src/core/menuu/client.mjs +++ /dev/null @@ -1,48 +0,0 @@ -/** - * notion-enhancer: menu - * (c) 2021 dragonwocky (https://dragonwocky.me/) - * (https://notion-enhancer.github.io/) under the MIT license - */ - -'use strict'; - -const notificationsURL = 'https://notion-enhancer.github.io/notifications.json'; - -export default async function ({ env, fs, storage, registry, web }, db) { - web.addHotkeyListener(await db.get(['hotkey']), env.focusMenu); - - const sidebarSelector = '.notion-sidebar-container .notion-sidebar > div:nth-child(3) > div > div:nth-child(2)'; - await web.whenReady([sidebarSelector]); - - const $sidebarLink = web.html``; - $sidebarLink.addEventListener('click', env.focusMenu); - - const notifications = { - cache: await storage.get(['notifications'], []), - provider: await fs.getJSON(notificationsURL), - count: (await registry.errors()).length, - }; - for (const notification of notifications.provider) { - if ( - !notifications.cache.includes(notification.id) && - notification.version === env.version && - (!notification.environments || notification.environments.includes(env.name)) - ) { - notifications.count++; - } - } - if ((await storage.get(['last_read_changelog'])) !== env.version) notifications.count++; - if (notifications.count) { - web.render( - $sidebarLink.children[0], - web.html`
${notifications.count}
` - ); - } - - web.render(document.querySelector(sidebarSelector), $sidebarLink); -}