Merge pull request #297 from EdouardVanbelle/refactor/section

This commit is contained in:
Dionisio Pozo
2026-04-16 00:03:46 +02:00
committed by GitHub
4 changed files with 26 additions and 58 deletions
+11 -38
View File
@@ -15,14 +15,14 @@ import { sharedView } from '../views/shared/sharedView.js';
import { checkAuthentication } from './authSession.js';
import { loadFiles } from './filesView.js';
import {
SECTIONS_MAPPER,
switchToFavoritesSection,
switchToFilesSection,
switchToMusicSection,
switchToPhotosSection,
switchToRecentFilesSection,
switchToSharedSection,
switchToTrashSection,
VIEW_FLAGS
switchToTrashSection
} from './navigation.js';
import { performSearch } from './searchView.js';
import { app, appElements as elements } from './state.js';
@@ -247,7 +247,7 @@ function deserializeHash() {
const section = hash_elements[1];
if (section in VIEW_FLAGS) {
if (section in SECTIONS_MAPPER) {
hashContext.section = section;
}
@@ -306,40 +306,13 @@ function switchSectionTo(section) {
// no change ...
return;
//TODO: better to use a registry for the future (easier to add new section)
switch (section) {
case 'files':
switchToFilesSection();
break;
case 'shared':
switchToSharedSection();
break;
case 'recent':
switchToRecentFilesSection();
break;
case 'favorites':
switchToFavoritesSection();
break;
case 'photos':
switchToPhotosSection();
break;
case 'music':
switchToMusicSection();
break;
case 'trash':
switchToTrashSection();
break;
default:
console.warn(`context view ${section} unkonwn fallback to drive section`);
switchToFilesSection();
if ((!section) in SECTIONS_MAPPER) {
console.warn(`context view ${section} unkonwn fallback to files section`);
section = 'files';
}
const switchHandler = SECTIONS_MAPPER[section];
switchHandler();
}
/**
@@ -528,8 +501,8 @@ function setupEventListeners() {
if (searchDebounceTimer) clearTimeout(searchDebounceTimer);
const query = elements.searchInput.value.trim();
// In shared view, filter locally
if (app.isSharedView && sharedView) {
// In shared section, filter locally
if (app.currentSection === 'shared' && sharedView) {
sharedView.filterAndSortItems();
return;
}
+12 -12
View File
@@ -107,17 +107,6 @@ function initSidebarToggle() {
// Initialize sidebar toggle when DOM is ready
document.addEventListener('DOMContentLoaded', initSidebarToggle);
// Mapping of section names to their corresponding view flags
export const VIEW_FLAGS = {
files: 'isFilesView',
shared: 'isSharedView',
recent: 'isRecentView',
favorites: 'isFavoritesView',
trash: 'isTrashView',
photos: 'isPhotosView',
music: 'isMusicView'
};
/**
* Derive section name from nav item's data-i18n attribute.
* @param {HTMLElement} navItem - The nav item element
@@ -128,6 +117,17 @@ function getSectionFromNavItem(navItem) {
return i18nKey ? i18nKey.replace('nav.', '') : null;
}
// Mapping section name to associated switch functions
export const SECTIONS_MAPPER = {
files: switchToFilesSection,
shared: switchToSharedSection,
recent: switchToRecentFilesSection,
favorites: switchToFavoritesSection,
trash: switchToTrashSection,
photos: switchToPhotosSection,
music: switchToMusicSection
};
/**
* Set the current active section, updating all view flags and nav UI.
* @param {string} section - The section to activate ('files', 'shared', 'recent', 'favorites', 'trash')
@@ -137,7 +137,7 @@ function setCurrentSection(section) {
if (app.currentSection === section) return false;
// Set all view flags - true for active section, false for others
Object.entries(VIEW_FLAGS).forEach(([key, flag]) => {
Object.entries(SECTIONS_MAPPER).forEach(([key, flag]) => {
app[flag] = key === section;
});
+1 -1
View File
@@ -26,7 +26,7 @@ async function performSearch(query, sortBy) {
sort_by: sortBy || 'relevance'
};
if (!app.isTrashView) {
if (app.currentSection !== 'trash') {
// Ensure we have a valid folder_id before searching
if (!app.currentPath || app.currentPath === '') {
await resolveHomeFolder();
+2 -7
View File
@@ -12,13 +12,8 @@ export const app = {
contextMenuTargetFile: null,
selectedTargetFolderId: '',
moveDialogMode: 'file',
isFilesView: true,
isTrashView: false,
isSharedView: false,
isFavoritesView: false,
isRecentView: false,
isPhotosView: false,
currentSection: 'files',
currentSection: null, // will be defined on first call
isSearchMode: false,
shareDialogItem: null,
shareDialogItemType: null,