Decouple i18n from feature modules and fix auth/login UX
Replace hardcoded updateAllText() calls with languageChanged event pattern so feature modules subscribe independently. Guard all API calls behind apiKey checks to prevent unauthorized requests when not logged in. Fix login modal localization, hide tabs when logged out, clear all panels on logout, and treat profiles with no conditions as always-true. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,14 +2,17 @@
|
||||
* Profiles — profile cards, editor, condition builder, process picker.
|
||||
*/
|
||||
|
||||
import { _profilesCache, set_profilesCache } from '../core/state.js';
|
||||
import { apiKey, _profilesCache, set_profilesCache } from '../core/state.js';
|
||||
import { API_BASE, getHeaders, escapeHtml, handle401Error } from '../core/api.js';
|
||||
import { t, updateAllText } from '../core/i18n.js';
|
||||
import { t } from '../core/i18n.js';
|
||||
import { showToast, showConfirm } from '../core/ui.js';
|
||||
import { Modal } from '../core/modal.js';
|
||||
|
||||
const profileModal = new Modal('profile-editor-modal');
|
||||
|
||||
// Re-render profiles when language changes
|
||||
document.addEventListener('languageChanged', () => { if (apiKey) loadProfiles(); });
|
||||
|
||||
export async function loadProfiles() {
|
||||
const container = document.getElementById('profiles-content');
|
||||
if (!container) return;
|
||||
@@ -39,7 +42,11 @@ function renderProfiles(profiles) {
|
||||
html += '</div>';
|
||||
|
||||
container.innerHTML = html;
|
||||
updateAllText();
|
||||
// Localize data-i18n elements within the profiles container only
|
||||
// (calling global updateAllText() would trigger loadProfiles() again → infinite loop)
|
||||
container.querySelectorAll('[data-i18n]').forEach(el => {
|
||||
el.textContent = t(el.getAttribute('data-i18n'));
|
||||
});
|
||||
}
|
||||
|
||||
function createProfileCard(profile) {
|
||||
@@ -141,7 +148,9 @@ export async function openProfileEditor(profileId) {
|
||||
}
|
||||
|
||||
profileModal.open();
|
||||
updateAllText();
|
||||
modal.querySelectorAll('[data-i18n]').forEach(el => {
|
||||
el.textContent = t(el.getAttribute('data-i18n'));
|
||||
});
|
||||
}
|
||||
|
||||
export function closeProfileEditorModal() {
|
||||
|
||||
Reference in New Issue
Block a user