fix(ui): fix go to parent + refactor types

This commit is contained in:
Edouard Vanbelle
2026-05-11 22:26:53 +02:00
parent a4f8805bce
commit 85c8c086ac
3 changed files with 39 additions and 56 deletions
+4 -27
View File
@@ -997,18 +997,8 @@ const ui = {
setContextTarget(card, info); setContextTarget(card, info);
const menuId = info.type === 'folder' ? 'folder-context-menu' : 'file-context-menu'; const menuId = info.type === 'folder' ? 'folder-context-menu' : 'file-context-menu';
const menu = document.getElementById(menuId); const menu = document.getElementById(menuId);
if (contextMenus && typeof contextMenus.syncFavoriteOptionLabels === 'function') { contextMenus.sync();
contextMenus.syncFavoriteOptionLabels();
}
if (contextMenus && typeof contextMenus.syncWopiOptionVisibility === 'function') {
contextMenus.syncWopiOptionVisibility().catch(() => {});
}
if (contextMenus && typeof contextMenus.syncAddToPlaylistOption === 'function') {
contextMenus.syncAddToPlaylistOption();
}
if (contextMenus && typeof contextMenus.syncOpenParentFolderOption === 'function') {
contextMenus.syncOpenParentFolderOption();
}
if (menu) { if (menu) {
menu.style.left = `${e.pageX}px`; menu.style.left = `${e.pageX}px`;
menu.style.top = `${e.pageY}px`; menu.style.top = `${e.pageY}px`;
@@ -1201,9 +1191,7 @@ const ui = {
} }
// Keep context-menu label in sync if available // Keep context-menu label in sync if available
if (contextMenus && typeof contextMenus.syncFavoriteOptionLabels === 'function') { contextMenus.syncFavoriteOptionLabels();
contextMenus.syncFavoriteOptionLabels();
}
}); });
const shared = el.querySelector('.file-badge-shared'); const shared = el.querySelector('.file-badge-shared');
@@ -1547,18 +1535,7 @@ function showContextMenuAtElement(triggerElement, menuId) {
top = rect.top - 4 + window.scrollY; // flip above if no room top = rect.top - 4 + window.scrollY; // flip above if no room
} }
if (contextMenus && typeof contextMenus.syncFavoriteOptionLabels === 'function') { contextMenus.sync();
contextMenus.syncFavoriteOptionLabels();
}
if (contextMenus && typeof contextMenus.syncWopiOptionVisibility === 'function') {
contextMenus.syncWopiOptionVisibility().catch(() => {});
}
if (contextMenus && typeof contextMenus.syncAddToPlaylistOption === 'function') {
contextMenus.syncAddToPlaylistOption();
}
if (contextMenus && typeof contextMenus.syncOpenParentFolderOption === 'function') {
contextMenus.syncOpenParentFolderOption();
}
menu.style.left = `${left}px`; menu.style.left = `${left}px`;
menu.style.top = `${top}px`; menu.style.top = `${top}px`;
+30 -24
View File
@@ -70,8 +70,8 @@ const contextMenus = {
const option = document.getElementById('open-parent-folder-option'); const option = document.getElementById('open-parent-folder-option');
if (!option) return; if (!option) return;
const folderId = app?.contextMenuTargetFile?.folder_id; const folderId = app?.contextMenuTargetFile?.folder_id;
const alreadyViewing = folderId && folderId === app?.currentPath; const isFilesSection = app.currentSection === 'files';
option.classList.toggle('hidden', !folderId || alreadyViewing); option.classList.toggle('hidden', !folderId || isFilesSection);
}, },
syncAddToPlaylistOption() { syncAddToPlaylistOption() {
@@ -87,6 +87,12 @@ const contextMenus = {
} }
}, },
sync() {
this.syncFavoriteOptionLabels();
this.syncWopiOptionVisibility().catch(() => {});
this.syncAddToPlaylistOption();
this.syncOpenParentFolderOption();
},
/** /**
* Assign events to menu items and dialogs * Assign events to menu items and dialogs
*/ */
@@ -688,8 +694,8 @@ const contextMenus = {
/** /**
* Load all folders for the move dialog (batch operations) * Load all folders for the move dialog (batch operations)
* Uses the same navigation pattern as loadMoveDialogFolders * Uses the same navigation pattern as loadMoveDialogFolders
* @param {string} itemId - ID of the item being moved (unused, kept for compatibility) * @param {string} _itemId - ID of the item being moved (unused, kept for compatibility)
* @param {string} mode - 'batch' for batch operations * @param {string} _mode - 'batch' for batch operations
*/ */
async loadAllFolders(_itemId, _mode) { async loadAllFolders(_itemId, _mode) {
// For batch mode, use the same navigation as regular move dialog // For batch mode, use the same navigation as regular move dialog
@@ -731,13 +737,13 @@ const contextMenus = {
if (itemName) itemName.textContent = item.name; if (itemName) itemName.textContent = item.name;
// Reset form // Reset form
const pwField = document.getElementById('share-password'); const pwField = /** @type HTMLInputElement */ (document.getElementById('share-password'));
const expField = document.getElementById('share-expiration'); const expField = /** @type HTMLInputElement */ (document.getElementById('share-expiration'));
if (pwField) pwField.value = ''; if (pwField) pwField.value = '';
if (expField) expField.value = ''; if (expField) expField.value = '';
const permRead = document.getElementById('share-permission-read'); const permRead = /** @type HTMLInputElement */ (document.getElementById('share-permission-read'));
const permWrite = document.getElementById('share-permission-write'); const permWrite = /** @type HTMLInputElement */ (document.getElementById('share-permission-write'));
const permReshare = document.getElementById('share-permission-reshare'); const permReshare = /** @type HTMLInputElement */ (document.getElementById('share-permission-reshare'));
if (permRead) permRead.checked = true; if (permRead) permRead.checked = true;
if (permWrite) permWrite.checked = false; if (permWrite) permWrite.checked = false;
if (permReshare) permReshare.checked = false; if (permReshare) permReshare.checked = false;
@@ -862,11 +868,11 @@ const contextMenus = {
} }
// Get values from form // Get values from form
const password = document.getElementById('share-password').value; const password = /** @type HTMLInputElement */ (document.getElementById('share-password')).value;
const expirationDate = document.getElementById('share-expiration').value; const expirationDate = /** @type HTMLInputElement */ (document.getElementById('share-expiration')).value;
const permissionRead = document.getElementById('share-permission-read').checked; const permissionRead = /** @type HTMLInputElement */ (document.getElementById('share-permission-read')).checked;
const permissionWrite = document.getElementById('share-permission-write').checked; const permissionWrite = /** @type HTMLInputElement */ (document.getElementById('share-permission-write')).checked;
const permissionReshare = document.getElementById('share-permission-reshare').checked; const permissionReshare = /** @type HTMLInputElement */ (document.getElementById('share-permission-reshare')).checked;
const item = app.shareDialogItem; const item = app.shareDialogItem;
const itemType = app.shareDialogItemType; const itemType = app.shareDialogItemType;
@@ -905,7 +911,7 @@ const contextMenus = {
const shareInfo = await response.json(); const shareInfo = await response.json();
// Update UI with new share // Update UI with new share
const shareUrl = document.getElementById('generated-share-url'); const shareUrl = /** @type HTMLInputElement */ (document.getElementById('generated-share-url'));
if (shareUrl) { if (shareUrl) {
shareUrl.value = shareInfo.url; shareUrl.value = shareInfo.url;
document.getElementById('new-share-section').classList.remove('hidden'); document.getElementById('new-share-section').classList.remove('hidden');
@@ -920,7 +926,7 @@ const contextMenus = {
ui.showNotification(i18n.t('notifications.link_created'), i18n.t('notifications.share_success')); ui.showNotification(i18n.t('notifications.link_created'), i18n.t('notifications.share_success'));
} catch (error) { } catch (error) {
console.error('Error creating shared link:', error); console.error('Error creating shared link:', error);
ui.showNotification('Error', error.message || 'Could not create shared link'); ui.showNotification('Error', /** @type {Error} */ (error).message || 'Could not create shared link');
} }
}, },
@@ -931,8 +937,8 @@ const contextMenus = {
showEmailNotificationDialog(shareUrl) { showEmailNotificationDialog(shareUrl) {
// Update dialog content // Update dialog content
document.getElementById('notification-share-url').textContent = shareUrl; document.getElementById('notification-share-url').textContent = shareUrl;
document.getElementById('notification-email').value = ''; /** @type HTMLInputElement */ (document.getElementById('notification-email')).value = '';
document.getElementById('notification-message').value = ''; /** @type HTMLInputElement */ (document.getElementById('notification-message')).value = '';
// Store the URL for later use // Store the URL for later use
app.notificationShareUrl = shareUrl; app.notificationShareUrl = shareUrl;
@@ -945,8 +951,8 @@ const contextMenus = {
* Send share notification email * Send share notification email
*/ */
sendShareNotification() { sendShareNotification() {
const email = document.getElementById('notification-email').value.trim(); const email = /** @type HTMLInputElement */ (document.getElementById('notification-email')).value.trim();
const message = document.getElementById('notification-message').value.trim(); const message = /** @type HTMLInputElement */ (document.getElementById('notification-message')).value.trim();
const shareUrl = app.notificationShareUrl; const shareUrl = app.notificationShareUrl;
if (!email || !shareUrl) { if (!email || !shareUrl) {
@@ -1013,7 +1019,7 @@ const contextMenus = {
container.innerHTML = '<div class="folder-select-loading"><i class="fas fa-spinner fa-spin"></i></div>'; container.innerHTML = '<div class="folder-select-loading"><i class="fas fa-spinner fa-spin"></i></div>';
// Reset add button state // Reset add button state
const addBtn = document.getElementById('playlist-add-btn'); const addBtn = /** @type {HTMLButtonElement} */ (document.getElementById('playlist-add-btn'));
if (addBtn) addBtn.disabled = true; if (addBtn) addBtn.disabled = true;
// Show dialog // Show dialog
@@ -1057,7 +1063,7 @@ const contextMenus = {
}); });
item.classList.add('selected'); item.classList.add('selected');
this._selectedPlaylistId = playlist.id; this._selectedPlaylistId = playlist.id;
const addBtn = document.getElementById('playlist-add-btn'); const addBtn = /** @type {HTMLButtonElement} */ (document.getElementById('playlist-add-btn'));
if (addBtn) addBtn.disabled = false; if (addBtn) addBtn.disabled = false;
}); });
@@ -1071,7 +1077,7 @@ const contextMenus = {
if (!playlistId || files.length === 0) return; if (!playlistId || files.length === 0) return;
const addBtn = document.getElementById('playlist-add-btn'); const addBtn = /** @type {HTMLButtonElement} */ (document.getElementById('playlist-add-btn'));
if (addBtn) addBtn.disabled = true; if (addBtn) addBtn.disabled = true;
try { try {
@@ -1101,7 +1107,7 @@ const contextMenus = {
} }
} catch (err) { } catch (err) {
console.error('Error adding to playlist:', err); console.error('Error adding to playlist:', err);
ui.showNotification(i18n.t('music.error'), err.message || i18n.t('music.add_error')); ui.showNotification(i18n.t('music.error'), /** @type {Error} */ (err).message || i18n.t('music.add_error'));
if (addBtn) addBtn.disabled = false; if (addBtn) addBtn.disabled = false;
} }
}, },
+5 -5
View File
@@ -208,7 +208,7 @@ const fileOps = {
safeUpdateFile(0, 'error'); safeUpdateFile(0, 'error');
finalize({ finalize({
ok: false, ok: false,
errorMsg: `Client send() failed: ${e?.message || 'unknown error'}` errorMsg: `Client send() failed: ${/** @type {Error} */ (e)?.message || 'unknown error'}`
}); });
} }
}); });
@@ -286,7 +286,7 @@ const fileOps = {
try { try {
// Legacy progress bar (inside dropzone) — keep working for drag-drop // Legacy progress bar (inside dropzone) — keep working for drag-drop
const progressBar = document.querySelector('.progress-fill'); const progressBar = /** @type {HTMLDivElement} */ (document.querySelector('.progress-fill'));
const uploadProgressDiv = document.querySelector('.upload-progress'); const uploadProgressDiv = document.querySelector('.upload-progress');
if (uploadProgressDiv) { if (uploadProgressDiv) {
uploadProgressDiv.classList.remove('hidden'); uploadProgressDiv.classList.remove('hidden');
@@ -447,7 +447,7 @@ const fileOps = {
} }
this._isUploading = true; this._isUploading = true;
const progressBar = document.querySelector('.progress-fill'); const progressBar = /** @type {HTMLDivElement} */ (document.querySelector('.progress-fill'));
const uploadProgressDiv = document.querySelector('.upload-progress'); const uploadProgressDiv = document.querySelector('.upload-progress');
if (uploadProgressDiv) { if (uploadProgressDiv) {
uploadProgressDiv.classList.remove('hidden'); uploadProgressDiv.classList.remove('hidden');
@@ -929,8 +929,8 @@ const fileOps = {
/** /**
* Copy a folder to another folder * Copy a folder to another folder
* Note: Backend folder copy is not yet implemented, this shows a notification * Note: Backend folder copy is not yet implemented, this shows a notification
* @param {string} folderId - Folder ID * @param {string} _folderId - Folder ID
* @param {string} targetFolderId - Target folder ID * @param {string} _targetFolderId - Target folder ID
* @returns {Promise<boolean>} - Success status * @returns {Promise<boolean>} - Success status
*/ */
async copyFolder(_folderId, _targetFolderId) { async copyFolder(_folderId, _targetFolderId) {