refactor(ui): remove unnecessary checks (i18n is always defined)
This commit is contained in:
@@ -27,7 +27,7 @@ const contextMenus = {
|
||||
if (!option) return;
|
||||
const label = option.querySelector('span');
|
||||
if (!label) return;
|
||||
label.textContent = i18n ? i18n.t(isFavorite ? 'actions.unfavorite' : 'actions.favorite') : isFavorite ? 'Remove from favorites' : 'Add to favorites';
|
||||
label.textContent = i18n.t(isFavorite ? 'actions.unfavorite' : 'actions.favorite');
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -382,7 +382,7 @@ const contextMenus = {
|
||||
renameInput.value = folder.name;
|
||||
// Update header text
|
||||
const headerSpan = renameDialog.querySelector('.rename-dialog-header span');
|
||||
if (headerSpan) headerSpan.textContent = i18n ? i18n.t('dialogs.rename_folder') : 'Rename folder';
|
||||
if (headerSpan) headerSpan.textContent = i18n.t('dialogs.rename_folder');
|
||||
renameDialog?.classList.remove('hidden');
|
||||
renameInput.focus();
|
||||
renameInput.select();
|
||||
@@ -402,7 +402,7 @@ const contextMenus = {
|
||||
renameInput.value = file.name;
|
||||
// Update header text
|
||||
const headerSpan = renameDialog.querySelector('.rename-dialog-header span');
|
||||
if (headerSpan) headerSpan.textContent = i18n ? i18n.t('dialogs.rename_file') : 'Rename file';
|
||||
if (headerSpan) headerSpan.textContent = i18n.t('dialogs.rename_file');
|
||||
renameDialog?.classList.remove('hidden');
|
||||
renameInput.focus();
|
||||
renameInput.select();
|
||||
@@ -471,7 +471,7 @@ const contextMenus = {
|
||||
|
||||
// Update dialog title (preserve icon)
|
||||
const dialogHeader = document.getElementById('move-file-dialog').querySelector('.rename-dialog-header');
|
||||
const titleText = mode === 'file' ? (i18n ? i18n.t('dialogs.move_file') : 'Move file') : i18n ? i18n.t('dialogs.move_folder') : 'Move folder';
|
||||
const titleText = mode === 'file' ? i18n.t('dialogs.move_file') : i18n.t('dialogs.move_folder');
|
||||
dialogHeader.innerHTML = `<i class="fas fa-arrows-alt dialog-header-icon"></i> <span>${titleText}</span>`;
|
||||
|
||||
// Load folders for the starting location
|
||||
@@ -496,7 +496,7 @@ const contextMenus = {
|
||||
async renameItem() {
|
||||
const newName = document.getElementById('rename-input').value.trim();
|
||||
if (!newName) {
|
||||
alert(i18n ? i18n.t('errors.empty_name') : 'Name cannot be empty');
|
||||
alert(i18n.t('errors.empty_name'));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -587,7 +587,7 @@ const contextMenus = {
|
||||
currentFolderOption.className = 'folder-select-item folder-select-current';
|
||||
currentFolderOption.innerHTML = `
|
||||
<i class="fas fa-check-circle check-icon"></i>
|
||||
<span>${i18n ? i18n.t('dialogs.select_this_folder') : 'Select this folder'}</span>
|
||||
<span>${i18n.t('dialogs.select_this_folder')}</span>
|
||||
`;
|
||||
currentFolderOption.addEventListener('click', () => {
|
||||
document.querySelectorAll('.folder-select-item').forEach((item) => {
|
||||
@@ -606,7 +606,7 @@ const contextMenus = {
|
||||
parentOption.className = 'folder-select-item folder-navigate-up';
|
||||
parentOption.innerHTML = `
|
||||
<i class="fas fa-level-up-alt"></i>
|
||||
<span>${i18n ? i18n.t('dialogs.go_to_parent') : '.. (parent folder)'}</span>
|
||||
<span>${i18n.t('dialogs.go_to_parent')}</span>
|
||||
`;
|
||||
parentOption.addEventListener('click', () => {
|
||||
// Navigate to parent folder
|
||||
@@ -664,7 +664,7 @@ const contextMenus = {
|
||||
homeOption.className = 'folder-select-item folder-select-current';
|
||||
homeOption.innerHTML = `
|
||||
<i class="fas fa-check-circle check-icon"></i>
|
||||
<span>${i18n ? i18n.t('dialogs.move_to_home') : 'Move to Home folder'}</span>
|
||||
<span>${i18n.t('dialogs.move_to_home')}</span>
|
||||
`;
|
||||
homeOption.addEventListener('click', () => {
|
||||
document.querySelectorAll('.folder-select-item').forEach((item) => {
|
||||
@@ -678,7 +678,7 @@ const contextMenus = {
|
||||
// Inside a subfolder with no children - show empty message
|
||||
const emptyMsg = document.createElement('div');
|
||||
emptyMsg.className = 'folder-select-empty';
|
||||
emptyMsg.innerHTML = `<i class="fas fa-folder-open"></i> <span>${i18n ? i18n.t('dialogs.no_subfolders') : 'No subfolders to navigate'}</span>`;
|
||||
emptyMsg.innerHTML = `<i class="fas fa-folder-open"></i> <span>${i18n.t('dialogs.no_subfolders')}</span>`;
|
||||
folderSelectContainer.appendChild(emptyMsg);
|
||||
}
|
||||
|
||||
@@ -686,9 +686,7 @@ const contextMenus = {
|
||||
app.selectedTargetFolderId = parentFolderId || '';
|
||||
|
||||
// Translate new elements
|
||||
if (i18n?.translateElement) {
|
||||
i18n.translateElement(folderSelectContainer);
|
||||
}
|
||||
i18n.translateElement(folderSelectContainer);
|
||||
} catch (error) {
|
||||
console.error('Error loading folders:', error);
|
||||
}
|
||||
@@ -799,7 +797,7 @@ const contextMenus = {
|
||||
if (dialogHeader) {
|
||||
const headerSpan = dialogHeader.querySelector('span');
|
||||
const titleText =
|
||||
itemType === 'file' ? (i18n ? i18n.t('dialogs.share_file') : 'Share file') : i18n ? i18n.t('dialogs.share_folder') : 'Share folder';
|
||||
itemType === 'file' ? i18n.t('dialogs.share_file') : i18n.t('dialogs.share_folder');
|
||||
if (headerSpan) {
|
||||
headerSpan.textContent = titleText;
|
||||
} else {
|
||||
@@ -900,9 +898,9 @@ const contextMenus = {
|
||||
const shareId = btn.getAttribute('data-share-id');
|
||||
|
||||
showConfirmDialog({
|
||||
title: i18n ? i18n.t('dialogs.confirm_delete_share') : 'Delete link',
|
||||
message: i18n ? i18n.t('dialogs.confirm_delete_share_msg') : 'Are you sure you want to delete this shared link?',
|
||||
confirmText: i18n ? i18n.t('actions.delete') : 'Delete'
|
||||
title: i18n.t('dialogs.confirm_delete_share'),
|
||||
message: i18n.t('dialogs.confirm_delete_share_msg'),
|
||||
confirmText: i18n.t('actions.delete')
|
||||
}).then(async (confirmed) => {
|
||||
if (confirmed) {
|
||||
await fileSharing.removeSharedLink(shareId);
|
||||
@@ -998,8 +996,8 @@ const contextMenus = {
|
||||
|
||||
// Show success message
|
||||
ui.showNotification(
|
||||
i18n ? i18n.t('notifications.link_created') : 'Link created',
|
||||
i18n ? i18n.t('notifications.share_success') : 'Shared link created successfully'
|
||||
i18n.t('notifications.link_created'),
|
||||
i18n.t('notifications.share_success')
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Error creating shared link:', error);
|
||||
@@ -1088,7 +1086,7 @@ const contextMenus = {
|
||||
|
||||
// Update files info
|
||||
if (filesInfo) {
|
||||
filesInfo.innerHTML = `<strong>${i18n ? i18n.t('music.selected_files', 'Selected:') : 'Selected:'} </strong>${file.name}`;
|
||||
filesInfo.innerHTML = `<strong>${i18n.t('music.selected_files')} </strong>${file.name}`;
|
||||
}
|
||||
|
||||
// Reset selection
|
||||
@@ -1112,12 +1110,12 @@ const contextMenus = {
|
||||
this._renderPlaylistSelect(container, playlists);
|
||||
} catch (err) {
|
||||
console.error('Error loading playlists:', err);
|
||||
container.innerHTML = `<div class="folder-select-empty">${i18n ? i18n.t('music.load_error', 'Error loading playlists') : 'Error loading playlists'}</div>`;
|
||||
container.innerHTML = `<div class="folder-select-empty">${i18n.t('music.load_error')}</div>`;
|
||||
}
|
||||
},
|
||||
|
||||
_renderPlaylistSelect(container, playlists) {
|
||||
const t = (key, fallback) => (i18n ? i18n.t(key, fallback) : fallback);
|
||||
const t = i18n.t.bind(i18n);
|
||||
|
||||
container.innerHTML = '';
|
||||
|
||||
@@ -1177,8 +1175,8 @@ const contextMenus = {
|
||||
|
||||
await resp.json();
|
||||
ui.showNotification(
|
||||
i18n ? i18n.t('music.added', 'Added!') : 'Added!',
|
||||
`${files.length} ${files.length === 1 ? 'track' : 'tracks'} ${i18n ? i18n.t('music.added_to_playlist', 'added to playlist') : 'added to playlist'}`
|
||||
i18n.t('music.added'),
|
||||
`${files.length} ${files.length === 1 ? 'track' : 'tracks'} ${i18n.t('music.added_to_playlist')}`
|
||||
);
|
||||
|
||||
this.closePlaylistDialog();
|
||||
@@ -1189,7 +1187,7 @@ const contextMenus = {
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error adding to playlist:', err);
|
||||
ui.showNotification(i18n ? i18n.t('music.error', 'Error') : 'Error', err.message || i18n.t('music.add_error', 'Could not add tracks to playlist'));
|
||||
ui.showNotification(i18n.t('music.error'), err.message || i18n.t('music.add_error'));
|
||||
if (addBtn) addBtn.disabled = false;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -30,12 +30,12 @@ const fileOps = {
|
||||
|
||||
/** Start a new upload batch in the notification bell */
|
||||
_initUploadToast(totalFiles, folderName) {
|
||||
this._currentBatchId = notifications ? notifications.addUploadBatch(totalFiles, folderName) : null;
|
||||
this._currentBatchId = notifications.addUploadBatch(totalFiles, folderName);
|
||||
},
|
||||
|
||||
/** Finalise the batch in the notification bell */
|
||||
_finishUploadToast(successCount, totalFiles) {
|
||||
if (notifications && this._currentBatchId) {
|
||||
if (this._currentBatchId) {
|
||||
notifications.finishBatch(this._currentBatchId, successCount, totalFiles);
|
||||
}
|
||||
},
|
||||
@@ -361,7 +361,7 @@ const fileOps = {
|
||||
progressBar.style.width = `${(uploadedCount / totalFiles) * 100}%`;
|
||||
}
|
||||
// Notify bell of per-file completion
|
||||
if (notifications && batchId) {
|
||||
if (batchId) {
|
||||
try {
|
||||
notifications.fileCompleted(batchId, result.ok);
|
||||
} catch (e) {
|
||||
@@ -383,7 +383,7 @@ const fileOps = {
|
||||
});
|
||||
}
|
||||
if (result.isQuotaError) {
|
||||
const msg = result.errorMsg || i18n?.t('storage_quota_exceeded') || 'Storage quota exceeded';
|
||||
const msg = result.errorMsg || i18n.t('storage_quota_exceeded');
|
||||
if (notifications) {
|
||||
notifications.addNotification({
|
||||
icon: 'fa-exclamation-triangle',
|
||||
@@ -591,7 +591,7 @@ const fileOps = {
|
||||
console.warn(`[SKIP] #${idx} ${rel} — cannot read 0-byte file (FIFO/pipe?), skipping`);
|
||||
uploadedCount++;
|
||||
successCount++;
|
||||
if (notifications && batchId) {
|
||||
if (batchId) {
|
||||
try {
|
||||
notifications.fileCompleted(batchId, true);
|
||||
} catch (_) {}
|
||||
@@ -623,7 +623,7 @@ const fileOps = {
|
||||
|
||||
uploadedCount++;
|
||||
|
||||
if (notifications && batchId) {
|
||||
if (batchId) {
|
||||
try {
|
||||
notifications.fileCompleted(batchId, result.ok);
|
||||
} catch (_) {}
|
||||
@@ -995,8 +995,8 @@ const fileOps = {
|
||||
|
||||
if (response.ok) {
|
||||
ui.showNotification(
|
||||
i18n ? i18n.t('notifications.file_renamed') : 'File renamed',
|
||||
i18n ? i18n.t('notifications.file_renamed_to', { name: newName }) : `File renamed to "${newName}"`
|
||||
i18n.t('notifications.file_renamed'),
|
||||
i18n.t('notifications.file_renamed_to', { name: newName })
|
||||
);
|
||||
return true;
|
||||
} else {
|
||||
@@ -1075,9 +1075,9 @@ const fileOps = {
|
||||
*/
|
||||
async deleteFile(fileId, fileName) {
|
||||
const confirmed = await showConfirmDialog({
|
||||
title: i18n ? i18n.t('dialogs.confirm_delete') : 'Move to trash',
|
||||
message: i18n ? i18n.t('dialogs.confirm_delete_file', { name: fileName }) : `Are you sure you want to move the file "${fileName}" to trash?`,
|
||||
confirmText: i18n ? i18n.t('actions.delete') : 'Delete'
|
||||
title: i18n.t('dialogs.confirm_delete'),
|
||||
message: i18n.t('dialogs.confirm_delete_file', { name: fileName }),
|
||||
confirmText: i18n.t('actions.delete')
|
||||
});
|
||||
if (!confirmed) return false;
|
||||
|
||||
@@ -1123,11 +1123,9 @@ const fileOps = {
|
||||
*/
|
||||
async deleteFolder(folderId, folderName) {
|
||||
const confirmed = await showConfirmDialog({
|
||||
title: i18n ? i18n.t('dialogs.confirm_delete') : 'Move to trash',
|
||||
message: i18n
|
||||
? i18n.t('dialogs.confirm_delete_folder', { name: folderName })
|
||||
: `Are you sure you want to move the folder "${folderName}" and all its contents to trash?`,
|
||||
confirmText: i18n ? i18n.t('actions.delete') : 'Delete'
|
||||
title: i18n.t('dialogs.confirm_delete'),
|
||||
message: i18n.t('dialogs.confirm_delete_folder', { name: folderName }),
|
||||
confirmText: i18n.t('actions.delete')
|
||||
});
|
||||
if (!confirmed) return false;
|
||||
|
||||
@@ -1234,11 +1232,9 @@ const fileOps = {
|
||||
*/
|
||||
async deletePermanently(trashId) {
|
||||
const confirmed = await showConfirmDialog({
|
||||
title: i18n ? i18n.t('dialogs.confirm_permanent_delete') : 'Delete permanently',
|
||||
message: i18n
|
||||
? i18n.t('dialogs.confirm_permanent_delete_msg')
|
||||
: 'Are you sure you want to permanently delete this item? This action cannot be undone.',
|
||||
confirmText: i18n ? i18n.t('actions.delete_permanently') : 'Delete permanently'
|
||||
title: i18n.t('dialogs.confirm_permanent_delete'),
|
||||
message: i18n.t('dialogs.confirm_permanent_delete_msg'),
|
||||
confirmText: i18n.t('actions.delete_permanently')
|
||||
});
|
||||
if (!confirmed) return false;
|
||||
|
||||
@@ -1268,9 +1264,9 @@ const fileOps = {
|
||||
*/
|
||||
async emptyTrash() {
|
||||
const confirmed = await showConfirmDialog({
|
||||
title: i18n ? i18n.t('dialogs.confirm_empty_trash') : 'Empty trash',
|
||||
message: i18n ? i18n.t('trash.empty_confirm') : 'Are you sure you want to empty the trash? This action will permanently delete all items.',
|
||||
confirmText: i18n ? i18n.t('actions.empty_trash') : 'Empty trash'
|
||||
title: i18n.t('dialogs.confirm_empty_trash'),
|
||||
message: i18n.t('trash.empty_confirm'),
|
||||
confirmText: i18n.t('actions.empty_trash')
|
||||
});
|
||||
if (!confirmed) return false;
|
||||
|
||||
|
||||
@@ -50,12 +50,8 @@ const multiSelect = {
|
||||
// ── Helpers for i18n ────────────────────────────────────
|
||||
|
||||
_t(key, vars) {
|
||||
if (i18n && typeof i18n.t === 'function') {
|
||||
const val = i18n.t(key, vars);
|
||||
// If i18n returned the key itself, it's missing → fall back
|
||||
if (val && val !== key) return val;
|
||||
}
|
||||
return null;
|
||||
const val = i18n.t(key, vars);
|
||||
return val !== key ? val : null;
|
||||
},
|
||||
|
||||
// ── Selection state management ──────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user