Remove UI window hooks and wire explicit runtime callbacks

This commit is contained in:
2026-02-07 01:45:52 +01:00
parent 37db70e67e
commit 78701cebf2
4 changed files with 32 additions and 20 deletions

View File

@@ -33,6 +33,17 @@ const safeUrl = (url) => {
};
const cssEscapeUrl = (url) => url.replace(/['")\\]/g, "\\$&");
const runtime = {
refreshPhaseData: async () => { },
loadSuggestData: async () => { },
loadVoteData: async () => { },
handleAuthError: () => false,
};
export function configureUiRuntime(deps) {
Object.assign(runtime, deps ?? {});
}
export function setAuthUI(isAuthed) {
const main = document.querySelector("main");
const statusBar = document.querySelector(".status-bar");
@@ -251,7 +262,7 @@ export function renderVotes() {
const peerSlider = document.querySelector(`input[type=range][data-id="${id}"]`);
if (peerSlider) delete peerSlider.dataset.pending;
});
await window.loadVoteData();
await runtime.loadVoteData();
updateMissingBadgeFromDom();
} catch (err) {
delete e.target.dataset.pending;
@@ -470,7 +481,7 @@ export function buildCard(
await api.updateSuggestion(s.id, data);
toast(t("toast.savedChanges"));
close();
await window.refreshPhaseData();
await runtime.refreshPhaseData();
},
lockTitle,
}),
@@ -658,7 +669,7 @@ function openSuggestionModal({ title, submitLabel, initial = {}, onSubmit, lockT
try {
await onSubmit(data, close, submitBtn);
} catch (err) {
if (window.handleAuthError?.(err)) return;
if (runtime.handleAuthError?.(err)) return;
toast(err.message, true);
}
});
@@ -681,9 +692,9 @@ export function openNewSuggestionModal() {
if (submitBtn) triggerCelebration(submitBtn);
close();
if (wasVotePhase) {
await window.refreshPhaseData();
await runtime.refreshPhaseData();
} else {
await window.loadSuggestData();
await runtime.loadSuggestData();
}
},
});
@@ -994,7 +1005,7 @@ function openDeleteConfirmModal(s) {
await api.deleteSuggestion(s.id);
toast(t("toast.suggestionDeleted"));
close();
await window.loadSuggestData();
await runtime.loadSuggestData();
} catch (err) {
toast(err.message, true);
}
@@ -1084,7 +1095,7 @@ function openUnlinkConfirm(s) {
await adminApi.unlinkSuggestions(s.id);
toast(t("admin.unlinkDone"));
close();
await window.refreshPhaseData();
await runtime.refreshPhaseData();
} catch (err) {
toast(err.message, true);
}