ext(login): wire 8 smart-input affordances into renderForm()
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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 */ });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user