Files
Oxicloud/static/js/app/searchView.js
T
BillionClaw 91e907bef6 fix(ui): resolve dark mode toggle and file search errors
- Fix dark mode toggle not responding by deriving theme state from
  localStorage instead of UI pill state. Added syncThemePill() to ensure
  UI and document theme stay synchronized.

- Fix file search error when folder_id is empty by validating the
  currentPath before setting it in search options. Empty folder_id
  now correctly triggers global search instead of causing a backend
  error with invalid UUID.

Fixes #102
2026-03-17 14:19:09 +08:00

59 lines
1.8 KiB
JavaScript
Executable File

/**
* 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}"`);
const filesGrid = document.getElementById('files-grid');
if (filesGrid) {
filesGrid.innerHTML = `
<div class="search-results-header">
<h3><i class="fas fa-spinner fa-spin search-spinner"></i> Searching for "${query}"...</h3>
</div>
`;
}
const options = {
recursive: true,
limit: 100,
sort_by: sortBy || 'relevance'
};
if (!app.isTrashView) {
// Ensure we have a valid folder_id before searching
if (!app.currentPath || app.currentPath === '') {
await window.resolveHomeFolder();
}
// Only set folder_id if we have a valid value
if (app.currentPath && app.currentPath !== '') {
options.folder_id = app.currentPath;
}
// If still no valid folder_id, search will be global (without folder_id)
}
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');
if (searchInput && searchInput.value.trim()) {
performSearch(searchInput.value.trim(), e.detail.sort_by);
}
});
window.performSearch = performSearch;