fix(main.js): add missing break in swithc/case + apply linter

This commit is contained in:
Edouard Vanbelle
2026-04-07 23:57:27 +02:00
parent 057bab5dad
commit 786a778546
+51 -54
View File
@@ -3,8 +3,6 @@
* This file contains the core functionality, initialization and state management
*/
// @ts-check
const app = window.app;
const elements = window.appElements;
@@ -96,10 +94,10 @@ const ACTIONS_BAR_TEMPLATES = {
};
/**
*
* @param {string} mode
* @param {boolean} [force=false]
* @returns
*
* @param {string} mode
* @param {boolean} [force=false]
* @returns
*/
function setActionsBarMode(mode, force = false) {
if (!elements.actionsBar) return;
@@ -202,7 +200,7 @@ function setupActionsBarDelegation() {
/**
* Read the application hash
*
* format:
* format:
*
* #/<section>/
*
@@ -217,21 +215,21 @@ function setupActionsBarDelegation() {
* @returns {OxiContext}
*/
function deserializeHash() {
let hashContext = /** type {OxiContext} */ {};
const hashContext = /** type {OxiContext} */ {};
// FIXME rename files into drive ?
hashContext.section = 'files';
let hash_elements = window.location.hash.split("/");
const hash_elements = window.location.hash.split("/");
let section = hash_elements[1];
const section = hash_elements[1];
// FIXME: use navigation.VIEW_FLAGS
if (section && ['files', 'shared', 'recent', 'favorites', 'trash', 'photos'].includes(section)) {
hashContext.section = section;
}
if (hash_elements[1] == 'files' && hash_elements[2] == 'folder' && hash_elements[3] !== null) {
if (hash_elements[1] === 'files' && hash_elements[2] === 'folder' && hash_elements[3] !== null) {
hashContext.path = hash_elements[3];
if (hash_elements[4] == 'file' && hash_elements[5] !== null) {
@@ -244,7 +242,7 @@ function deserializeHash() {
/**
* update borwser's url/history
*
*
* @param {boolean} insertHistory true to change url and browser's history, false to change url only
*/
function updateHistory( insertHistory) {
@@ -277,8 +275,6 @@ function updateHistory( insertHistory) {
console.log(`replace history with ${historyUrl}`)
window.history.replaceState(historyData, "", historyUrl);
}
}
/**
@@ -295,6 +291,7 @@ function switchSectionTo(section) {
switch (section) {
case "files":
switchToFilesSection();
break;
case "shared":
switchToSharedSection();
@@ -328,22 +325,22 @@ function switchSectionTo(section) {
function initApp() {
// Cache DOM elements
cacheElements();
// Initialize file sharing module first
if (window.fileSharing && window.fileSharing.init) {
window.fileSharing.init();
} else {
console.warn('fileSharing module not fully initialized');
}
// Then create menus and dialogs after modules have initialized
setTimeout(() => {
ui.initializeContextMenus();
}, 100);
// Setup event listeners
setupEventListeners();
// Ensure inline viewer is initialized
if (!window.inlineViewer && typeof InlineViewer !== 'undefined') {
try {
@@ -352,7 +349,7 @@ function initApp() {
console.error('Error initializing inline viewer:', e);
}
}
// Initialize favorites module if available
if (window.favorites && window.favorites.init) {
console.log('Initializing favorites module');
@@ -360,7 +357,7 @@ function initApp() {
} else {
console.warn('Favorites module not available or not initializable');
}
// Initialize recent files module if available
if (window.recent && window.recent.init) {
console.log('Initializing recent files module');
@@ -368,13 +365,13 @@ function initApp() {
} else {
console.warn('Recent files module not available or not initializable');
}
// Initialize multi-select / batch actions
if (window.multiSelect && window.multiSelect.init) {
console.log('Initializing multi-select module');
window.multiSelect.init();
}
window.addEventListener('authenticationDone', () => {
// Check if a context was provided in the URL
let hashContext = deserializeHash();
@@ -404,7 +401,7 @@ function initApp() {
console.log('Translations loaded, proceeding with authentication');
window.checkAuthentication();
});
// Set a timeout as a fallback in case translations take too long
setTimeout(() => {
if (!window.i18n || !window.i18n.isLoaded || !window.i18n.isLoaded()) {
@@ -440,7 +437,7 @@ function cacheElements() {
function setupUploadDropdown() {
const uploadBtn = document.getElementById('upload-btn');
const menu = document.getElementById('upload-dropdown-menu');
if (!uploadBtn || !menu) return;
// Abort any previous local bindings (safe across repeated/rebuilt UI)
@@ -449,7 +446,7 @@ function setupUploadDropdown() {
}
uploadDropdownBindingsController = new AbortController();
const signal = uploadDropdownBindingsController.signal;
// Toggle dropdown on button click
uploadBtn.addEventListener('click', (e) => {
e.stopPropagation();
@@ -481,14 +478,14 @@ function setupUploadDropdown() {
function setupEventListeners() {
// Set up drag and drop
ui.setupDragAndDrop();
// Debounce timer for live search
let searchDebounceTimer = null;
const SEARCH_DEBOUNCE_MS = 300;
const SEARCH_MIN_CHARS = 3;
// handle history / url change
window.addEventListener("popstate", (e) => {
window.addEventListener("popstate", (e) => {
if (e.state === null) {
// change is from user (url explicitely change, read information from hash)
let hashContext = deserializeHash();
@@ -512,13 +509,13 @@ function setupEventListeners() {
// Cancel any pending debounce
if (searchDebounceTimer) clearTimeout(searchDebounceTimer);
const query = elements.searchInput.value.trim();
// In shared view, filter locally
if (app.isSharedView && window.sharedView) {
window.sharedView.filterAndSortItems();
return;
}
if (query) {
window.performSearch(query);
} else if (app.isSearchMode) {
@@ -530,12 +527,12 @@ function setupEventListeners() {
}
}
});
// Search input — Live search (debounced, after 3+ chars)
elements.searchInput.addEventListener('input', () => {
if (searchDebounceTimer) clearTimeout(searchDebounceTimer);
const query = elements.searchInput.value.trim();
if (query.length >= SEARCH_MIN_CHARS) {
searchDebounceTimer = setTimeout(() => {
window.performSearch(query);
@@ -550,7 +547,7 @@ function setupEventListeners() {
}, SEARCH_DEBOUNCE_MS);
}
});
// Search button
document.getElementById('search-button').addEventListener('click', () => {
if (searchDebounceTimer) clearTimeout(searchDebounceTimer);
@@ -559,14 +556,14 @@ function setupEventListeners() {
window.performSearch(query);
}
});
// Upload dropdown
setupUploadDropdown();
setupActionsBarDelegation();
if (elements.actionsBar) {
elements.actionsBar.dataset.mode = 'files';
}
// File input
elements.fileInput.addEventListener('change', (e) => {
if (e.target.files.length > 0) {
@@ -574,7 +571,7 @@ function setupEventListeners() {
e.target.value = ''; // reset so same file can be re-uploaded
}
});
// Folder input
const folderInput = document.getElementById('folder-input');
if (folderInput) {
@@ -585,20 +582,20 @@ function setupEventListeners() {
}
});
}
// Sidebar navigation
elements.navItems.forEach(item => {
item.addEventListener('click', () => {
// Remove active class from all nav items
elements.navItems.forEach(navItem => navItem.classList.remove('active'));
// Add active class to clicked item
item.classList.add('active');
let _updateHistory = true;
let itemI18nKey=item.querySelector('span').getAttribute('data-i18n')
switch(itemI18nKey) {
case 'nav.shared':
case 'nav.shared':
// Switch to shared view
switchToSharedSection();
break;
@@ -608,7 +605,7 @@ function setupEventListeners() {
switchToFavoritesSection();
break;
case 'nav.recent':
case 'nav.recent':
// Switch to recent files view
switchToRecentFilesSection();
break;
@@ -617,7 +614,7 @@ function setupEventListeners() {
switchToPhotosSection();
break;
case 'nav.trash':
case 'nav.trash':
switchToTrashSection();
break;
@@ -625,7 +622,7 @@ function setupEventListeners() {
// Use the proper switchToFilesView function which handles all UI restoration
window.switchToFilesSection();
// FIXME: because fileview handles it: need to converge code
_updateHistory = false;
_updateHistory = false;
}
document.title = `OxiCloud: ${window.i18n.t(itemI18nKey)}`;
@@ -635,7 +632,7 @@ function setupEventListeners() {
}
});
});
// Load saved view preference
const savedView = localStorage.getItem('oxicloud-view');
if (savedView === 'list') {
@@ -643,21 +640,21 @@ function setupEventListeners() {
} else {
ui.switchToGridView();
}
// User menu
window.setupUserMenu();
// Global events to close context menus and deselect cards
document.addEventListener('click', (e) => {
const folderMenu = document.getElementById('folder-context-menu');
const fileMenu = document.getElementById('file-context-menu');
if (folderMenu && folderMenu.style.display === 'block' &&
if (folderMenu && folderMenu.style.display === 'block' &&
!folderMenu.contains(e.target)) {
ui.closeContextMenu();
}
if (fileMenu && fileMenu.style.display === 'block' &&
if (fileMenu && fileMenu.style.display === 'block' &&
!fileMenu.contains(e.target)) {
ui.closeFileContextMenu();
}
@@ -693,7 +690,7 @@ function updateStorageUsageDisplay(userData) {
usedBytes = userData.storage_used_bytes || 0;
// Use == null to allow 0 (unlimited) to pass through; only default to DEFAULT_QUOTA when null/undefined
quotaBytes = userData.storage_quota_bytes == null ? DEFAULT_QUOTA : userData.storage_quota_bytes;
// Calculate percentage (avoid division by zero)
if (quotaBytes > 0) {
usagePercentage = Math.min(Math.round((usedBytes / quotaBytes) * 100), 100);
@@ -707,15 +704,15 @@ function updateStorageUsageDisplay(userData) {
// Update the storage display elements
const storageFill = document.querySelector('.storage-fill');
const storageInfo = document.querySelector('.storage-info');
if (storageFill) {
storageFill.style.width = `${usagePercentage}%`;
}
if (storageInfo) {
// Remove data-i18n attribute to prevent i18n from overwriting our value
storageInfo.removeAttribute('data-i18n');
// Use i18n if available
if (window.i18n && window.i18n.t) {
storageInfo.textContent = window.i18n.t('storage.used', {
@@ -727,7 +724,7 @@ function updateStorageUsageDisplay(userData) {
storageInfo.textContent = `${usagePercentage}% used (${usedFormatted} / ${quotaFormatted})`;
}
}
console.log(`Updated storage display: ${usagePercentage}% (${usedFormatted} / ${quotaFormatted})`);
}