fix: add missing state. prefix to all bare state variable references across all modules
All checks were successful
CI / lint (push) Successful in 15s
CI / security (push) Successful in 8s
CI / test (push) Successful in 16s
CI / build (push) Successful in 2s

This commit is contained in:
Bruno Charest 2026-05-28 18:33:39 -04:00
parent 75fac8256b
commit 148b3851ae
8 changed files with 47 additions and 47 deletions

View File

@ -330,7 +330,7 @@ function initLoginForm() {
const AdminPanel = { const AdminPanel = {
_modal: null, _modal: null,
_allVaults: [], _state.allVaults: [],
show() { show() {
this._createModal(); this._createModal();
@ -378,9 +378,9 @@ const AdminPanel = {
// Also load available vaults // Also load available vaults
try { try {
const vaultsData = await api("/api/vaults"); const vaultsData = await api("/api/vaults");
this._allVaults = vaultsData.map((v) => v.name); this._state.allVaults = vaultsData.map((v) => v.name);
} catch (e) { } catch (e) {
this._allVaults = []; this._state.allVaults = [];
} }
this._renderUsers(users); this._renderUsers(users);
} catch (err) { } catch (err) {
@ -486,8 +486,8 @@ const AdminPanel = {
document.getElementById("admin-user-form").addEventListener("submit", async (e) => { document.getElementById("admin-user-form").addEventListener("submit", async (e) => {
e.preventDefault(); e.preventDefault();
const form = e.target; const form = e.target;
const allVaults = document.getElementById("admin-all-vaults").checked; const state.allVaults = document.getElementById("admin-all-vaults").checked;
const selectedVaults = allVaults ? ["*"] : Array.from(form.querySelectorAll('input[name="vault"]:checked')).map((cb) => cb.value); const selectedVaults = state.allVaults ? ["*"] : Array.from(form.querySelectorAll('input[name="vault"]:checked')).map((cb) => cb.value);
try { try {
if (isEdit) { if (isEdit) {

View File

@ -98,7 +98,7 @@ function _humanizeDelta(mtime) {
} }
function _refreshRecentTimestamps() { function _refreshRecentTimestamps() {
if (activeSidebarTab !== "recent" || !_recentFilesCache.length) return; if (state.activeSidebarTab !== "recent" || !_recentFilesCache.length) return;
const items = document.querySelectorAll(".recent-item"); const items = document.querySelectorAll(".recent-item");
items.forEach((item, i) => { items.forEach((item, i) => {
if (i < _recentFilesCache.length) { if (i < _recentFilesCache.length) {
@ -165,7 +165,7 @@ function switchSidebarTab(tab) {
const placeholders = { vaults: "Filtrer fichiers...", tags: "Filtrer tags...", recent: "" }; const placeholders = { vaults: "Filtrer fichiers...", tags: "Filtrer tags...", recent: "" };
filterInput.placeholder = placeholders[tab] || ""; filterInput.placeholder = placeholders[tab] || "";
} }
const query = filterInput ? (sidebarFilterCaseSensitive ? filterInput.value.trim() : filterInput.value.trim().toLowerCase()) : ""; const query = filterInput ? (state.sidebarFilterCaseSensitive ? filterInput.value.trim() : filterInput.value.trim().toLowerCase()) : "";
if (query) { if (query) {
if (tab === "vaults") performTreeSearch(query); if (tab === "vaults") performTreeSearch(query);
else if (tab === "tags") filterTagCloud(query); else if (tab === "tags") filterTagCloud(query);
@ -653,7 +653,7 @@ async function loadHiddenFilesSettings() {
function renderHiddenFilesSettings(container, allSettings) { function renderHiddenFilesSettings(container, allSettings) {
container.innerHTML = ""; container.innerHTML = "";
if (!allVaults || state.allVaults.length === 0) { if (!state.allVaults || state.allVaults.length === 0) {
container.innerHTML = '<div style="padding:12px;color:var(--text-muted)">Aucun vault configuré</div>'; container.innerHTML = '<div style="padding:12px;color:var(--text-muted)">Aucun vault configuré</div>';
return; return;
} }

View File

@ -153,7 +153,7 @@ const DashboardRecentWidget = {
_currentFilter: "", _currentFilter: "",
async load(vaultFilter = "") { async load(vaultFilter = "") {
const v = vaultFilter || selectedContextVault || "all"; const v = vaultFilter || state.selectedContextVault || "all";
this._currentFilter = v; this._currentFilter = v;
this.showLoading(); this.showLoading();
@ -371,7 +371,7 @@ const DashboardRecentWidget = {
// Keep first option "Tous les vaults" // Keep first option "Tous les vaults"
while (select.options.length > 1) select.remove(1); while (select.options.length > 1) select.remove(1);
if (typeof allVaults !== "undefined" && Array.isArray(state.allVaults)) { if (typeof state.allVaults !== "undefined" && Array.isArray(state.allVaults)) {
state.allVaults.forEach((v) => { state.allVaults.forEach((v) => {
const opt = document.createElement("option"); const opt = document.createElement("option");
opt.value = v.name; opt.value = v.name;
@ -401,7 +401,7 @@ const DashboardBookmarkWidget = {
_currentFilter: "", _currentFilter: "",
async load(vaultFilter = "") { async load(vaultFilter = "") {
const v = vaultFilter || selectedContextVault || "all"; const v = vaultFilter || state.selectedContextVault || "all";
this._currentFilter = v; this._currentFilter = v;
this.showLoading(); this.showLoading();

View File

@ -108,7 +108,7 @@ function initSearch() {
caseBtn.addEventListener("click", () => { state.searchCaseSensitive = !state.searchCaseSensitive; _updateToggleUI(); _research(); }); caseBtn.addEventListener("click", () => { state.searchCaseSensitive = !state.searchCaseSensitive; _updateToggleUI(); _research(); });
if (wordBtn) wordBtn.addEventListener("click", () => { state.searchWholeWord = !state.searchWholeWord; _updateToggleUI(); _research(); }); if (wordBtn) wordBtn.addEventListener("click", () => { state.searchWholeWord = !state.searchWholeWord; _updateToggleUI(); _research(); });
if (regexBtn) regexBtn.addEventListener("click", () => { state.searchRegex = !state.searchRegex; _updateToggleUI(); _research(); }); if (regexBtn) regexBtn.addEventListener("click", () => { state.searchRegex = !state.searchRegex; _updateToggleUI(); _research(); });
if (filterBtn) filterBtn.addEventListener("click", () => { state.searchFilterVisible = !state.searchFilterVisible; if (filterRow) filterRow.style.display = searchFilterVisible ? "flex" : "none"; _updateToggleUI(); }); if (filterBtn) filterBtn.addEventListener("click", () => { state.searchFilterVisible = !state.searchFilterVisible; if (filterRow) filterRow.style.display = state.searchFilterVisible ? "flex" : "none"; _updateToggleUI(); });
// Result navigation (up/down arrows + Enter) // Result navigation (up/down arrows + Enter)
let _searchResultIdx = -1; let _searchResultIdx = -1;

View File

@ -676,7 +676,7 @@ function initSidebarFilter() {
clearBtn.style.display = hasText ? "flex" : "none"; clearBtn.style.display = hasText ? "flex" : "none";
clearTimeout(state.filterDebounce); clearTimeout(state.filterDebounce);
state.filterDebounce = setTimeout(async () => { state.filterDebounce = setTimeout(async () => {
const q = sidebarFilterCaseSensitive ? input.value.trim() : input.value.trim().toLowerCase(); const q = state.sidebarFilterCaseSensitive ? input.value.trim() : input.value.trim().toLowerCase();
if (hasText) { if (hasText) {
if (state.activeSidebarTab === "vaults") { if (state.activeSidebarTab === "vaults") {
await performTreeSearch(q); await performTreeSearch(q);
@ -696,7 +696,7 @@ function initSidebarFilter() {
caseBtn.addEventListener("click", async () => { caseBtn.addEventListener("click", async () => {
state.sidebarFilterCaseSensitive = !state.sidebarFilterCaseSensitive; state.sidebarFilterCaseSensitive = !state.sidebarFilterCaseSensitive;
caseBtn.classList.toggle("active"); caseBtn.classList.toggle("active");
const q = sidebarFilterCaseSensitive ? input.value.trim() : input.value.trim().toLowerCase(); const q = state.sidebarFilterCaseSensitive ? input.value.trim() : input.value.trim().toLowerCase();
if (input.value.trim()) { if (input.value.trim()) {
if (state.activeSidebarTab === "vaults") { if (state.activeSidebarTab === "vaults") {
await performTreeSearch(q); await performTreeSearch(q);
@ -742,7 +742,7 @@ async function performTreeSearch(query) {
async function restoreSidebarTree() { async function restoreSidebarTree() {
await refreshSidebarForContext(); await refreshSidebarForContext();
if (state.currentVault) { if (state.currentVault) {
focusPathInSidebar(state.currentVault, currentPath || "", { alignToTop: false }).catch(() => {}); focusPathInSidebar(state.currentVault, state.currentPath || "", { alignToTop: false }).catch(() => {});
} }
} }
@ -838,8 +838,8 @@ function filterSidebarTree(query) {
const matchingItems = new Set(); const matchingItems = new Set();
items.forEach((item) => { items.forEach((item) => {
const text = sidebarFilterCaseSensitive ? item.textContent : item.textContent.toLowerCase(); const text = state.sidebarFilterCaseSensitive ? item.textContent : item.textContent.toLowerCase();
const searchQuery = sidebarFilterCaseSensitive ? query : query.toLowerCase(); const searchQuery = state.sidebarFilterCaseSensitive ? query : query.toLowerCase();
if (text.includes(searchQuery)) { if (text.includes(searchQuery)) {
matchingItems.add(item); matchingItems.add(item);
item.classList.remove("filtered-out"); item.classList.remove("filtered-out");
@ -898,8 +898,8 @@ function showAllDescendants(container) {
function filterTagCloud(query) { function filterTagCloud(query) {
const tags = document.querySelectorAll("#tag-cloud .tag-item"); const tags = document.querySelectorAll("#tag-cloud .tag-item");
tags.forEach((tag) => { tags.forEach((tag) => {
const text = sidebarFilterCaseSensitive ? tag.textContent : tag.textContent.toLowerCase(); const text = state.sidebarFilterCaseSensitive ? tag.textContent : tag.textContent.toLowerCase();
const searchQuery = sidebarFilterCaseSensitive ? query : query.toLowerCase(); const searchQuery = state.sidebarFilterCaseSensitive ? query : query.toLowerCase();
if (!query || text.includes(searchQuery)) { if (!query || text.includes(searchQuery)) {
tag.classList.remove("filtered-out"); tag.classList.remove("filtered-out");
} else { } else {

View File

@ -156,8 +156,8 @@ export const IndexUpdateManager = (() => {
try { try {
await Promise.all([refreshSidebarTreePreservingState(), refreshTagsForContext()]); await Promise.all([refreshSidebarTreePreservingState(), refreshTagsForContext()]);
// Refresh current file if it was updated // Refresh current file if it was updated
if (currentVault && state.currentPath) { if (state.currentVault && state.currentPath) {
const changed = (data.changes || []).some((c) => c.vault === currentVault && c.path === state.currentPath); const changed = (data.changes || []).some((c) => c.vault === state.currentVault && c.path === state.currentPath);
if (changed) { if (changed) {
openFile(state.currentVault, state.currentPath); openFile(state.currentVault, state.currentPath);
} }

View File

@ -36,9 +36,9 @@ export const RightSidebarManager = {
if (!sidebar) return; if (!sidebar) return;
if (rightSidebarVisible) { if (state.rightSidebarVisible) {
sidebar.classList.remove("hidden"); sidebar.classList.remove("hidden");
sidebar.style.width = `${rightSidebarWidth}px`; sidebar.style.width = `${state.rightSidebarWidth}px`;
if (handle) handle.classList.remove("hidden"); if (handle) handle.classList.remove("hidden");
if (tocBtn) { if (tocBtn) {
tocBtn.classList.add("active"); tocBtn.classList.add("active");
@ -67,7 +67,7 @@ export const RightSidebarManager = {
toggle() { toggle() {
state.rightSidebarVisible = !state.rightSidebarVisible; state.rightSidebarVisible = !state.rightSidebarVisible;
localStorage.setItem("obsigate-right-sidebar-visible", rightSidebarVisible); localStorage.setItem("obsigate-right-sidebar-visible", state.rightSidebarVisible);
this.applyState(); this.applyState();
}, },
@ -118,7 +118,7 @@ export const RightSidebarManager = {
document.body.style.cursor = ""; document.body.style.cursor = "";
document.body.style.userSelect = ""; document.body.style.userSelect = "";
localStorage.setItem("obsigate-right-sidebar-width", rightSidebarWidth); localStorage.setItem("obsigate-right-sidebar-width", state.rightSidebarWidth);
}; };
handle.addEventListener("mousedown", onMouseDown); handle.addEventListener("mousedown", onMouseDown);
@ -905,10 +905,10 @@ const FileOperations = {
if (type === 'file' && state.currentVault === vault && state.currentPath === path) { if (type === 'file' && state.currentVault === vault && state.currentPath === path) {
await openFile(vault, nextPath); await openFile(vault, nextPath);
} else if (type === 'directory' && state.currentVault === vault && currentPath && (state.currentPath === path || currentPath.startsWith(`${path}/`))) { } else if (type === 'directory' && state.currentVault === vault && state.currentPath && (state.currentPath === path || currentPath.startsWith(`${path}/`))) {
const suffix = state.currentPath === path ? '' : currentPath.slice(path.length); const suffix = state.currentPath === path ? '' : currentPath.slice(path.length);
state.currentPath = `${nextPath}${suffix}`; state.currentPath = `${nextPath}${suffix}`;
await focusPathInSidebar(vault, currentPath, { alignToTop: false }); await focusPathInSidebar(vault, state.currentPath, { alignToTop: false });
} }
showToast(type === 'directory' ? 'Dossier renommé' : 'Fichier renommé', 'success'); showToast(type === 'directory' ? 'Dossier renommé' : 'Fichier renommé', 'success');
@ -992,7 +992,7 @@ const FileOperations = {
this._closeModal(overlay); this._closeModal(overlay);
await refreshSidebarTreePreservingState(); await refreshSidebarTreePreservingState();
if (state.currentVault === vault && currentPath && currentPath.startsWith(path)) { if (state.currentVault === vault && state.currentPath && currentPath.startsWith(path)) {
showWelcome(); showWelcome();
} }
} catch (err) { } catch (err) {
@ -1922,8 +1922,8 @@ export const TabManager = {
if (!cache) return; if (!cache) return;
// Update global state // Update global state
currentVault = cache.vault; state.currentVault = cache.vault;
currentPath = cache.path; state.currentPath = cache.path;
syncActiveFileTreeItem(cache.vault, cache.path); syncActiveFileTreeItem(cache.vault, cache.path);
const area = document.getElementById("content-area"); const area = document.getElementById("content-area");
@ -2098,8 +2098,8 @@ export const TabManager = {
// Refresh widgets after restoring // Refresh widgets after restoring
if (typeof DashboardStatsWidget !== "undefined") DashboardStatsWidget.load(); if (typeof DashboardStatsWidget !== "undefined") DashboardStatsWidget.load();
if (typeof DashboardConflictsWidget !== "undefined") DashboardConflictsWidget.load(); if (typeof DashboardConflictsWidget !== "undefined") DashboardConflictsWidget.load();
if (typeof DashboardRecentWidget !== "undefined") DashboardRecentWidget.load(selectedContextVault); if (typeof DashboardRecentWidget !== "undefined") DashboardRecentWidget.load(state.selectedContextVault);
if (typeof DashboardBookmarkWidget !== "undefined") DashboardBookmarkWidget.load(selectedContextVault); if (typeof DashboardBookmarkWidget !== "undefined") DashboardBookmarkWidget.load(state.selectedContextVault);
if (history.pushState) { if (history.pushState) {
history.pushState(null, "", "#"); history.pushState(null, "", "#");
} }

View File

@ -439,12 +439,12 @@ function renderFile(data) {
copyBtn.addEventListener("click", async () => { copyBtn.addEventListener("click", async () => {
try { try {
// Fetch raw content if not already cached // Fetch raw content if not already cached
if (!cachedRawSource) { if (!state.cachedRawSource) {
const rawUrl = `/api/file/${encodeURIComponent(data.vault)}/raw?path=${encodeURIComponent(data.path)}`; const rawUrl = `/api/file/${encodeURIComponent(data.vault)}/raw?path=${encodeURIComponent(data.path)}`;
const rawData = await api(rawUrl); const rawData = await api(rawUrl);
state.cachedRawSource = rawData.raw; state.cachedRawSource = rawData.raw;
} }
await navigator.clipboard.writeText(cachedRawSource); await navigator.clipboard.writeText(state.cachedRawSource);
copyBtn.lastChild.textContent = "Copié !"; copyBtn.lastChild.textContent = "Copié !";
setTimeout(() => (copyBtn.lastChild.textContent = "Copier"), 1500); setTimeout(() => (copyBtn.lastChild.textContent = "Copier"), 1500);
} catch (err) { } catch (err) {
@ -546,9 +546,9 @@ function renderFile(data) {
if (!rendered || !raw) return; if (!rendered || !raw) return;
state.showingSource = !state.showingSource; state.showingSource = !state.showingSource;
if (showingSource) { if (state.showingSource) {
sourceBtn.classList.add("active"); sourceBtn.classList.add("active");
if (!cachedRawSource) { if (!state.cachedRawSource) {
const rawUrl = `/api/file/${encodeURIComponent(data.vault)}/raw?path=${encodeURIComponent(data.path)}`; const rawUrl = `/api/file/${encodeURIComponent(data.vault)}/raw?path=${encodeURIComponent(data.path)}`;
const rawData = await api(rawUrl); const rawData = await api(rawUrl);
state.cachedRawSource = rawData.raw; state.cachedRawSource = rawData.raw;
@ -948,10 +948,10 @@ function showWelcome() {
DashboardConflictsWidget.load(); DashboardConflictsWidget.load();
} }
if (typeof DashboardRecentWidget !== "undefined") { if (typeof DashboardRecentWidget !== "undefined") {
DashboardRecentWidget.load(selectedContextVault); DashboardRecentWidget.load(state.selectedContextVault);
} }
if (typeof DashboardBookmarkWidget !== "undefined") { if (typeof DashboardBookmarkWidget !== "undefined") {
DashboardBookmarkWidget.load(selectedContextVault); DashboardBookmarkWidget.load(state.selectedContextVault);
} }
if (typeof DashboardSharedWidget !== "undefined") { if (typeof DashboardSharedWidget !== "undefined") {
DashboardSharedWidget.load(); DashboardSharedWidget.load();
@ -1002,9 +1002,9 @@ async function loadSavedSearches() {
// Apply the saved search // Apply the saved search
const input = document.getElementById("search-input"); const input = document.getElementById("search-input");
if (input) input.value = s.query; if (input) input.value = s.query;
searchCaseSensitive = s.case_sensitive || false; state.searchCaseSensitive = s.case_sensitive || false;
searchWholeWord = s.whole_word || false; state.searchWholeWord = s.whole_word || false;
searchRegex = s.regex || false; state.searchRegex = s.regex || false;
if (typeof _updateToggleUI === "function") _updateToggleUI(); if (typeof _updateToggleUI === "function") _updateToggleUI();
if (s.include_paths) { if (s.include_paths) {
const incl = document.getElementById("search-include-input"); const incl = document.getElementById("search-include-input");
@ -1019,7 +1019,7 @@ async function loadSavedSearches() {
AutocompleteDropdown._suppressNext = true; AutocompleteDropdown._suppressNext = true;
const vault = s.vault || "all"; const vault = s.vault || "all";
if (input) { input.dispatchEvent(new Event("input")); } if (input) { input.dispatchEvent(new Event("input")); }
clearTimeout(searchTimeout); clearTimeout(state.searchTimeout);
advancedSearchOffset = 0; advancedSearchOffset = 0;
performAdvancedSearch(s.query, vault, null); performAdvancedSearch(s.query, vault, null);
}); });
@ -1217,15 +1217,15 @@ const IndexUpdateManager = (() => {
// Toast removed: silent auto-indexing — no notification needed // Toast removed: silent auto-indexing — no notification needed
// Refresh sidebar and tags if affected vault matches current context // Refresh sidebar and tags if affected vault matches current context
const affectsCurrentVault = state.selectedContextVault === "all" || (data.vaults || []).includes(selectedContextVault); const affectsCurrentVault = state.selectedContextVault === "all" || (data.vaults || []).includes(state.selectedContextVault);
if (affectsCurrentVault) { if (affectsCurrentVault) {
try { try {
await Promise.all([refreshSidebarTreePreservingState(), refreshTagsForContext()]); await Promise.all([refreshSidebarTreePreservingState(), refreshTagsForContext()]);
// Refresh current file if it was updated // Refresh current file if it was updated
if (currentVault && currentPath) { if (state.currentVault && state.currentPath) {
const changed = (data.changes || []).some((c) => c.vault === currentVault && c.path === currentPath); const changed = (data.changes || []).some((c) => c.vault === state.currentVault && c.path === state.currentPath);
if (changed) { if (changed) {
openFile(currentVault, currentPath); openFile(state.currentVault, state.currentPath);
} }
} }
} catch (err) { } catch (err) {
@ -1234,7 +1234,7 @@ const IndexUpdateManager = (() => {
} }
// Refresh recent tab if it is active // Refresh recent tab if it is active
if (activeSidebarTab === "recent") { if (state.activeSidebarTab === "recent") {
const vaultFilter = document.getElementById("recent-vault-filter"); const vaultFilter = document.getElementById("recent-vault-filter");
loadRecentFiles(vaultFilter ? vaultFilter.value || null : null); loadRecentFiles(vaultFilter ? vaultFilter.value || null : null);
} }