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
This commit is contained in:
@@ -27,12 +27,16 @@ async function performSearch(query, sortBy) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (!app.isTrashView) {
|
if (!app.isTrashView) {
|
||||||
options.folder_id = app.currentPath;
|
// Ensure we have a valid folder_id before searching
|
||||||
|
if (!app.currentPath || app.currentPath === '') {
|
||||||
if (!options.folder_id || options.folder_id === '') {
|
|
||||||
await window.resolveHomeFolder();
|
await window.resolveHomeFolder();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only set folder_id if we have a valid value
|
||||||
|
if (app.currentPath && app.currentPath !== '') {
|
||||||
options.folder_id = 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);
|
const searchResults = await window.search.searchFiles(query, options);
|
||||||
|
|||||||
+43
-13
@@ -52,24 +52,54 @@ function setupUserMenu() {
|
|||||||
|
|
||||||
if (themeBtn) {
|
if (themeBtn) {
|
||||||
const pill = document.getElementById('theme-toggle-pill');
|
const pill = document.getElementById('theme-toggle-pill');
|
||||||
const isDark = localStorage.getItem('oxicloud_theme') === 'dark';
|
|
||||||
if (isDark) {
|
// Sync pill UI with current theme state
|
||||||
if (pill) pill.classList.add('active');
|
function syncThemePill() {
|
||||||
document.documentElement.setAttribute('data-theme', 'dark');
|
const isDark = localStorage.getItem('oxicloud_theme') === 'dark';
|
||||||
|
if (pill) {
|
||||||
|
if (isDark) {
|
||||||
|
pill.classList.add('active');
|
||||||
|
} else {
|
||||||
|
pill.classList.remove('active');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Ensure document theme matches localStorage
|
||||||
|
if (isDark) {
|
||||||
|
document.documentElement.setAttribute('data-theme', 'dark');
|
||||||
|
} else {
|
||||||
|
document.documentElement.removeAttribute('data-theme');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize pill state on load
|
||||||
|
syncThemePill();
|
||||||
|
|
||||||
themeBtn.addEventListener('click', (e) => {
|
themeBtn.addEventListener('click', (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (pill) {
|
// Toggle theme based on current state, not pill state
|
||||||
pill.classList.toggle('active');
|
const currentIsDark = localStorage.getItem('oxicloud_theme') === 'dark';
|
||||||
const dark = pill.classList.contains('active');
|
const newIsDark = !currentIsDark;
|
||||||
localStorage.setItem('oxicloud_theme', dark ? 'dark' : 'light');
|
|
||||||
document.documentElement.setAttribute('data-theme', dark ? 'dark' : 'light');
|
localStorage.setItem('oxicloud_theme', newIsDark ? 'dark' : 'light');
|
||||||
window.ui.showNotification(
|
|
||||||
dark ? '🌙' : '☀️',
|
if (newIsDark) {
|
||||||
dark ? 'Dark mode enabled' : 'Light mode enabled'
|
document.documentElement.setAttribute('data-theme', 'dark');
|
||||||
);
|
} else {
|
||||||
|
document.documentElement.removeAttribute('data-theme');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pill) {
|
||||||
|
if (newIsDark) {
|
||||||
|
pill.classList.add('active');
|
||||||
|
} else {
|
||||||
|
pill.classList.remove('active');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.ui.showNotification(
|
||||||
|
newIsDark ? '🌙' : '☀️',
|
||||||
|
newIsDark ? 'Dark mode enabled' : 'Light mode enabled'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user