ext(login): wire 8 smart-input affordances into renderForm()

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
adlee-was-taken
2026-05-01 22:32:14 -04:00
parent e6eb698c4c
commit b450ecd1cc
4 changed files with 220 additions and 16 deletions

View File

@@ -7,8 +7,13 @@ const DATALIST_ID = 'groups-datalist';
export async function wireGroupAutocomplete(form: HTMLElement, opts: GroupAutocompleteOpts): Promise<void> {
const input = form.querySelector<HTMLInputElement>('#f-group');
if (!input) return;
const resp = await opts.sendMessage({ type: 'list_groups' });
if (!resp.ok || !resp.data) return;
let resp: Awaited<ReturnType<typeof opts.sendMessage>>;
try {
resp = await opts.sendMessage({ type: 'list_groups' });
} catch {
return;
}
if (!resp?.ok || !resp.data?.groups) return;
// Datalists must live in the document, not nested inside an input. Reuse if
// we've already mounted one this session.

View File

@@ -10,14 +10,20 @@ export async function wireNotesMonoToggle(form: HTMLElement, opts: NotesMonoOpts
if (!btn || !ta) return;
const key = `notesMono.${opts.itemId || '__new__'}`;
const stored = await new Promise<boolean>((resolve) => {
chrome.storage.local.get([key], (result) => resolve(!!result[key]));
});
if (stored) ta.classList.add('f-notes--mono');
// chrome.storage may be absent in test environments — guard gracefully.
if (typeof chrome !== 'undefined' && chrome.storage?.local) {
const stored = await new Promise<boolean>((resolve) => {
chrome.storage.local.get([key], (result) => resolve(!!result[key]));
});
if (stored) ta.classList.add('f-notes--mono');
}
btn.addEventListener('click', () => {
const next = !ta.classList.contains('f-notes--mono');
ta.classList.toggle('f-notes--mono', next);
chrome.storage.local.set({ [key]: next }, () => { /* fire and forget */ });
if (typeof chrome !== 'undefined' && chrome.storage?.local) {
chrome.storage.local.set({ [key]: next }, () => { /* fire and forget */ });
}
});
}