refactor(ui): remove unnecessary checks (i18n is always defined)
This commit is contained in:
@@ -134,7 +134,7 @@ async function loadFiles(options = { insertHistory: true }) {
|
||||
ui.showError(`
|
||||
<div class="files-loading-spinner">
|
||||
<div class="spinner"></div>
|
||||
<span>${i18n ? i18n.t('files.loading') : 'Loading files…'}</span>
|
||||
<span>${i18n.t('files.loading')}</span>
|
||||
</div>
|
||||
`);
|
||||
}, 100);
|
||||
|
||||
+8
-15
@@ -166,9 +166,7 @@ function setActionsBarMode(mode, force = false) {
|
||||
elements.gridViewBtn = document.getElementById('grid-view-btn');
|
||||
elements.listViewBtn = document.getElementById('list-view-btn');
|
||||
|
||||
if (i18n?.translateElement) {
|
||||
i18n.translateElement(elements.actionsBar);
|
||||
}
|
||||
i18n.translateElement(elements.actionsBar);
|
||||
|
||||
if (mode === 'files') {
|
||||
setupUploadDropdown();
|
||||
@@ -395,7 +393,7 @@ function initApp() {
|
||||
});
|
||||
|
||||
// Wait for translations to load before checking authentication
|
||||
if (i18n?.isLoaded?.()) {
|
||||
if (i18n.isLoaded()) {
|
||||
// Translations already loaded, proceed with authentication
|
||||
checkAuthentication();
|
||||
} else {
|
||||
@@ -408,7 +406,7 @@ function initApp() {
|
||||
|
||||
// Set a timeout as a fallback in case translations take too long
|
||||
setTimeout(() => {
|
||||
if (!i18n?.isLoaded?.()) {
|
||||
if (!i18n.isLoaded()) {
|
||||
console.warn('Translations loading timeout, proceeding with authentication anyway');
|
||||
checkAuthentication();
|
||||
}
|
||||
@@ -727,16 +725,11 @@ function updateStorageUsageDisplay(userData) {
|
||||
// Remove data-i18n attribute to prevent i18n from overwriting our value
|
||||
storageInfo.removeAttribute('data-i18n');
|
||||
|
||||
// Use i18n if available
|
||||
if (i18n?.t) {
|
||||
storageInfo.textContent = i18n.t('storage.used', {
|
||||
percentage: usagePercentage,
|
||||
used: usedFormatted,
|
||||
total: quotaFormatted
|
||||
});
|
||||
} else {
|
||||
storageInfo.textContent = `${usagePercentage}% used (${usedFormatted} / ${quotaFormatted})`;
|
||||
}
|
||||
storageInfo.textContent = i18n.t('storage.used', {
|
||||
percentage: usagePercentage,
|
||||
used: usedFormatted,
|
||||
total: quotaFormatted
|
||||
});
|
||||
}
|
||||
|
||||
console.log(`Updated storage display: ${usagePercentage}% (${usedFormatted} / ${quotaFormatted})`);
|
||||
|
||||
@@ -152,7 +152,7 @@ function setCurrentSection(section) {
|
||||
// Update page title
|
||||
const titleKey = `nav.${section}`;
|
||||
const defaultTitle = section.charAt(0).toUpperCase() + section.slice(1);
|
||||
appElements.pageTitle.textContent = i18n ? i18n.t(titleKey) : defaultTitle;
|
||||
appElements.pageTitle.textContent = i18n.t(titleKey);
|
||||
appElements.pageTitle.setAttribute('data-i18n', titleKey);
|
||||
|
||||
// Hide sharedView when switching to any other section
|
||||
|
||||
+10
-11
@@ -15,14 +15,13 @@ async function loadTrashItems() {
|
||||
try {
|
||||
if (multiSelect) multiSelect.clear();
|
||||
ui.resetFilesList(); // ensure also list visible & error hidden
|
||||
const _tt = i18n?.t ? i18n.t : (k) => k.split('.').pop();
|
||||
elements.filesList.innerHTML = `
|
||||
<div class="list-header trash-header">
|
||||
<div data-i18n="files.name">${_tt('files.name')}</div>
|
||||
<div data-i18n="files.type">${_tt('files.type')}</div>
|
||||
<div data-i18n="trash.original_location">${_tt('trash.original_location')}</div>
|
||||
<div data-i18n="trash.deleted_date">${_tt('trash.deleted_date')}</div>
|
||||
<div data-i18n="trash.actions">${_tt('trash.actions')}</div>
|
||||
<div data-i18n="files.name">${i18n.t('files.name')}</div>
|
||||
<div data-i18n="files.type">${i18n.t('files.type')}</div>
|
||||
<div data-i18n="trash.original_location">${i18n.t('trash.original_location')}</div>
|
||||
<div data-i18n="trash.deleted_date">${i18n.t('trash.deleted_date')}</div>
|
||||
<div data-i18n="trash.actions">${i18n.t('trash.actions')}</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
@@ -33,7 +32,7 @@ async function loadTrashItems() {
|
||||
if (trashItems.length === 0) {
|
||||
ui.showError(`
|
||||
<i class="fas fa-trash empty-state-icon"></i>
|
||||
<p>${i18n ? i18n.t('trash.empty_state') : 'The trash is empty'}</p>
|
||||
<p>${i18n.t('trash.empty_state')}</p>
|
||||
`);
|
||||
return;
|
||||
}
|
||||
@@ -58,12 +57,12 @@ function addTrashItemToView(item) {
|
||||
let iconSpecialClass = '';
|
||||
if (!isFile) {
|
||||
iconClass = item.icon_class || 'fas fa-folder';
|
||||
typeLabel = i18n ? i18n.t('files.file_types.folder') : 'Folder';
|
||||
typeLabel = i18n.t('files.file_types.folder');
|
||||
} else {
|
||||
iconClass = item.icon_class || (ui?.getIconClass ? ui.getIconClass(item.name) : 'fas fa-file');
|
||||
iconSpecialClass = ui?.getIconSpecialClass ? ui.getIconSpecialClass(item.name) : '';
|
||||
const cat = item.category || '';
|
||||
typeLabel = cat ? (i18n ? i18n.t(`files.file_types.${cat.toLowerCase()}`) || cat : cat) : i18n ? i18n.t('files.file_types.document') : 'Document';
|
||||
typeLabel = cat ? (i18n.t(`files.file_types.${cat.toLowerCase()}`) || cat) : i18n.t('files.file_types.document');
|
||||
}
|
||||
|
||||
const isFolder = !isFile;
|
||||
@@ -86,10 +85,10 @@ function addTrashItemToView(item) {
|
||||
<div class="path-cell">${escapeHtml(item.original_path || '--')}</div>
|
||||
<div class="date-cell">${escapeHtml(formattedDate)}</div>
|
||||
<div class="actions-cell">
|
||||
<button class="btn-restore" title="${i18n ? i18n.t('trash.restore') : 'Restore'}">
|
||||
<button class="btn-restore" title="${i18n.t('trash.restore')}">
|
||||
<i class="fas fa-undo"></i>
|
||||
</button>
|
||||
<button class="btn-delete" title="${i18n ? i18n.t('trash.delete_permanently') : 'Delete permanently'}">
|
||||
<button class="btn-delete" title="${i18n.t('trash.delete_permanently')}">
|
||||
<i class="fas fa-trash"></i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
+8
-14
@@ -542,17 +542,11 @@ const ui = {
|
||||
breadcrumb.innerHTML = '';
|
||||
const path = app.breadcrumbPath; // [{id, name}, ...]
|
||||
|
||||
// Helper function to safely get translation text
|
||||
const getTranslatedText = (key, defaultValue) => {
|
||||
if (!i18n?.t) return defaultValue;
|
||||
return i18n.t(key);
|
||||
};
|
||||
|
||||
// -- Home icon (always present, clickable to go to root) --
|
||||
const homeIcon = document.createElement('span');
|
||||
homeIcon.className = 'breadcrumb-item breadcrumb-home';
|
||||
homeIcon.innerHTML = '<i class="fas fa-home"></i>';
|
||||
homeIcon.title = getTranslatedText('breadcrumb.home', 'Home');
|
||||
homeIcon.title = i18n.t('breadcrumb.home');
|
||||
|
||||
// Home is always clickable if we have a home folder
|
||||
if (app.userHomeFolderId) {
|
||||
@@ -1265,7 +1259,7 @@ const ui = {
|
||||
<div class="file-badge file-badge-favorite ${isFav ? '' : 'hidden'}"><i class="fas fa-star favorite-star-inline"></i></div>
|
||||
<div class="file-badge file-badge-shared ${isShared ? '' : 'hidden'}"><i class="fas fa-share-alt"></i></div>
|
||||
</div>
|
||||
<div class="type-cell">${i18n ? i18n.t('files.file_types.folder') : 'Folder'}</div>
|
||||
<div class="type-cell">${i18n.t('files.file_types.folder')}</div>
|
||||
<div class="size-cell">--</div>
|
||||
<div class="date-cell">${formattedDate}</div>
|
||||
<div class="action-cell">
|
||||
@@ -1288,7 +1282,7 @@ const ui = {
|
||||
const iconClass = file.icon_class || this.getIconClass(file.name);
|
||||
const iconSpecialClass = file.icon_special_class || this.getIconSpecialClass(file.name);
|
||||
const cat = file.category || '';
|
||||
const typeLabel = cat ? (i18n ? i18n.t(`files.file_types.${cat.toLowerCase()}`) || cat : cat) : i18n ? i18n.t('files.file_types.document') : 'Document';
|
||||
const typeLabel = cat ? (i18n.t(`files.file_types.${cat.toLowerCase()}`) || cat) : i18n.t('files.file_types.document');
|
||||
const fileSize = file.size_formatted || formatFileSize(file.size);
|
||||
const formattedDate = formatDateTime(file.modified_at);
|
||||
const isFav = favorites?.isFavorite(file.id, 'file');
|
||||
@@ -1352,7 +1346,7 @@ const ui = {
|
||||
<div></div><!-- actions -->
|
||||
</div>`;
|
||||
|
||||
if (i18n?.translateElement) i18n.translateElement(filesList);
|
||||
i18n.translateElement(filesList);
|
||||
|
||||
filesList.classList.remove('hidden');
|
||||
filesContainerError?.classList.add('hidden');
|
||||
@@ -1376,7 +1370,7 @@ const ui = {
|
||||
const filesList = document.getElementById('files-list');
|
||||
if (filesContainerError) filesContainerError.innerHTML = content;
|
||||
|
||||
if (i18n?.translateElement) i18n.translateElement(filesContainerError);
|
||||
i18n.translateElement(filesContainerError);
|
||||
|
||||
filesContainerError?.classList.remove('hidden');
|
||||
filesList?.classList.add('hidden');
|
||||
@@ -1642,9 +1636,9 @@ if (document.readyState === 'loading') {
|
||||
* @returns {Promise<boolean>} true if confirmed, false if cancelled
|
||||
*/
|
||||
function showConfirmDialog({ title, message, confirmText, cancelText, danger = true } = {}) {
|
||||
const ct = confirmText || (i18n ? i18n.t('actions.delete') : 'Delete');
|
||||
const cc = cancelText || (i18n ? i18n.t('actions.cancel') : 'Cancel');
|
||||
const t = title || (i18n ? i18n.t('dialogs.confirm_title') : 'Confirm action');
|
||||
const ct = confirmText || i18n.t('actions.delete');
|
||||
const cc = cancelText || i18n.t('actions.cancel');
|
||||
const t = title || i18n.t('dialogs.confirm_title');
|
||||
|
||||
return new Promise((resolve) => {
|
||||
// Remove any previous confirm dialog
|
||||
|
||||
@@ -209,9 +209,10 @@ function showUserProfileModal() {
|
||||
const usedBytes = userData.storage_used_bytes || 0;
|
||||
const quotaBytes = userData.storage_quota_bytes == null ? 10 * 1024 * 1024 * 1024 : userData.storage_quota_bytes;
|
||||
const percentage = quotaBytes > 0 ? Math.min(Math.round((usedBytes / quotaBytes) * 100), 100) : 0;
|
||||
// FIXME: use classes
|
||||
const barColor = percentage > 90 ? '#ef4444' : percentage > 70 ? '#f59e0b' : '#22c55e';
|
||||
|
||||
const t = (key, fallback) => (i18n?.t ? i18n.t(key) || fallback : fallback);
|
||||
const t = (key, fallback) => i18n.t(key) || fallback;
|
||||
|
||||
const existing = document.getElementById('profile-modal-overlay');
|
||||
if (existing) existing.remove();
|
||||
|
||||
Reference in New Issue
Block a user