2026-02-20 12:27:52 +01:00
|
|
|
/**
|
|
|
|
|
* Search view orchestration logic
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
async function performSearch(query, sortBy) {
|
|
|
|
|
const app = window.app;
|
|
|
|
|
|
|
|
|
|
console.log(`Performing search for: "${query}" (sort: ${sortBy || 'relevance'})`);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
app.isSearchMode = true;
|
|
|
|
|
window.ui.updateBreadcrumb(`Search: "${query}"`);
|
|
|
|
|
|
2026-04-07 22:48:59 +02:00
|
|
|
window.ui.showError(`<h3><i class="fas fa-spinner fa-spin search-spinner"></i> Searching for "${query}"...</h3>`);
|
2026-02-20 12:27:52 +01:00
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
|
recursive: true,
|
|
|
|
|
limit: 100,
|
|
|
|
|
sort_by: sortBy || 'relevance'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!app.isTrashView) {
|
2026-03-17 14:19:09 +08:00
|
|
|
// Ensure we have a valid folder_id before searching
|
|
|
|
|
if (!app.currentPath || app.currentPath === '') {
|
2026-02-20 12:27:52 +01:00
|
|
|
await window.resolveHomeFolder();
|
2026-03-17 14:19:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Only set folder_id if we have a valid value
|
|
|
|
|
if (app.currentPath && app.currentPath !== '') {
|
2026-02-20 12:27:52 +01:00
|
|
|
options.folder_id = app.currentPath;
|
|
|
|
|
}
|
2026-03-17 14:19:09 +08:00
|
|
|
// If still no valid folder_id, search will be global (without folder_id)
|
2026-02-20 12:27:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const searchResults = await window.search.searchFiles(query, options);
|
|
|
|
|
window.search.displaySearchResults(searchResults);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Search error:', error);
|
|
|
|
|
window.ui.showNotification('Error', 'Error performing search');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
document.addEventListener('search-resort', (e) => {
|
|
|
|
|
const searchInput = document.querySelector('.search-container input');
|
2026-04-07 22:50:42 +02:00
|
|
|
if (searchInput?.value.trim()) {
|
2026-02-20 12:27:52 +01:00
|
|
|
performSearch(searchInput.value.trim(), e.detail.sort_by);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
window.performSearch = performSearch;
|