-
Notifications
You must be signed in to change notification settings - Fork 7.3k
feat(settings): add save feedback for preferences changes #2261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| export function showToast(message: string): void { | ||
| document.querySelector('.toast-notification')?.remove(); | ||
|
|
||
| const toast = document.createElement('div'); | ||
| toast.className = 'toast-notification'; | ||
| toast.setAttribute('role', 'status'); | ||
| toast.textContent = message; | ||
|
|
||
| document.body.appendChild(toast); | ||
| requestAnimationFrame(() => toast.classList.add('visible')); | ||
| setTimeout(() => { | ||
| toast.classList.remove('visible'); | ||
| setTimeout(() => toast.remove(), 300); | ||
| }, 3000); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { describe, it } from 'node:test'; | ||
| import assert from 'node:assert/strict'; | ||
| import { readFileSync } from 'node:fs'; | ||
| import { dirname, join, resolve } from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
| const root = resolve(__dirname, '..'); | ||
|
|
||
| function src(path) { | ||
| return readFileSync(join(root, path), 'utf-8'); | ||
| } | ||
|
|
||
| function extractMethodBody(source, methodName) { | ||
| const signature = `${methodName}(): void {`; | ||
| const start = source.indexOf(signature); | ||
| assert.notEqual(start, -1, `${methodName}() not found`); | ||
|
|
||
| let depth = 1; | ||
| let i = start + signature.length; | ||
| while (i < source.length && depth > 0) { | ||
| const char = source[i]; | ||
| if (char === '{') depth += 1; | ||
| if (char === '}') depth -= 1; | ||
| i += 1; | ||
| } | ||
|
|
||
| assert.equal(depth, 0, `${methodName}() body did not terminate`); | ||
| return source.slice(start + signature.length, i - 1); | ||
| } | ||
|
|
||
| describe('settings save feedback guardrails', () => { | ||
| const toastSrc = src('src/utils/toast.ts'); | ||
| const settingsSrc = src('src/components/UnifiedSettings.ts'); | ||
| const prefsSrc = src('src/services/preferences-content.ts'); | ||
| const handlersSrc = src('src/app/event-handlers.ts'); | ||
| const countryIntelSrc = src('src/app/country-intel.ts'); | ||
|
|
||
| it('uses a shared body-level toast utility with role=status', () => { | ||
| assert.match(toastSrc, /export function showToast\(message: string\): void/); | ||
| assert.match(toastSrc, /toast\.setAttribute\('role', 'status'\)/); | ||
| assert.match(toastSrc, /document\.querySelector\('\.toast-notification'\)\?\.remove\(\)/); | ||
| }); | ||
|
|
||
| it('shows saved feedback for Preferences through renderPreferences callback', () => { | ||
| assert.match(settingsSrc, /onSettingSaved:\s*\(\)\s*=>\s*showToast\(t\('modals\.settingsWindow\.saved'\)\)/); | ||
| assert.match(prefsSrc, /onSettingSaved\?: \(\) => void;/); | ||
| assert.match(prefsSrc, /host\.onSettingSaved\?\.\(\);/); | ||
| }); | ||
|
|
||
| it('keeps Panels save on inline status only', () => { | ||
| const saveBody = extractMethodBody(settingsSrc, 'savePanelChanges'); | ||
| assert.doesNotMatch(saveBody, /showToast\(/); | ||
| }); | ||
|
|
||
| it('removes duplicate global toast implementations from event handlers and country intel', () => { | ||
| assert.match(handlersSrc, /import \{ showToast \} from '@\/utils\/toast';/); | ||
|
Comment on lines
+54
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The pattern Consider anchoring on the method name itself rather than its closing brace, or reading the entire file and checking the region between known method boundaries: // alternative: just assert the method body does not contain showToast anywhere nearby
const methodStart = settingsSrc.indexOf('private savePanelChanges()');
const methodEnd = settingsSrc.indexOf('\n private ', methodStart + 1);
const methodBody = settingsSrc.slice(methodStart, methodEnd === -1 ? undefined : methodEnd);
assert.ok(methodBody.length > 0, 'savePanelChanges() not found');
assert.doesNotMatch(methodBody, /showToast\(/); |
||
| assert.match(countryIntelSrc, /import \{ showToast \} from '@\/utils\/toast';/); | ||
| assert.doesNotMatch(handlersSrc, /\n\s*showToast\(msg: string\): void \{/); | ||
| assert.doesNotMatch(countryIntelSrc, /\n\s*showToast\(msg: string\): void \{/); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UnifiedSettingstoastsThe old local
showToastinUnifiedSettings.tsused a 4 000 ms dismiss timeout;event-handlers.tsandcountry-intel.tsused 3 000 ms. The new shared helper standardises on 3 000 ms, which silently shortens the display time for two toasts inUnifiedSettings(the free-panel-limit toast fired fromtoggleDraftPanel, and the new "Saved" toast). This may be intentional, but it's worth confirming — users who currently see the panel-limit warning for 4 s will now only see it for 3 s.If 3 000 ms is the desired standard, a brief comment here would make the intention explicit: