search inside folders

This commit is contained in:
2025-05-31 12:24:48 +02:00
parent 4494ebdeb3
commit 45a1bc07c6
5 changed files with 54 additions and 18 deletions

View File

@@ -22,6 +22,7 @@ export class SearchManager {
this.roomManager = roomManager;
this.searchInput = document.getElementById('quickSearchInput');
this.clearSearchBtn = document.getElementById('clearSearchBtn');
this.isSearching = false;
}
/**
@@ -35,9 +36,11 @@ export class SearchManager {
// Create debounced search function
const debouncedSearch = this.debounce((searchTerm) => {
if (searchTerm) {
this.isSearching = true;
this.performSearch(searchTerm);
this.clearSearchBtn.style.display = 'block';
} else {
this.isSearching = false;
this.roomManager.fileManager.fetchFiles(); // Reset to show all files
this.clearSearchBtn.style.display = 'none';
}
@@ -53,6 +56,7 @@ export class SearchManager {
if (this.clearSearchBtn) {
this.clearSearchBtn.addEventListener('click', () => {
this.searchInput.value = '';
this.isSearching = false;
this.roomManager.fileManager.fetchFiles(); // Reset to show all files
this.clearSearchBtn.style.display = 'none';
});
@@ -60,20 +64,25 @@ export class SearchManager {
}
/**
* Performs the search operation on the current file list.
* Filters files based on name and type matching the search term.
* Performs the search operation using the server-side search endpoint.
* @param {string} searchTerm - The term to search for
*/
performSearch(searchTerm) {
if (!this.roomManager.fileManager.currentFiles) return;
const filteredFiles = this.roomManager.fileManager.currentFiles.filter(file => {
const searchLower = searchTerm.toLowerCase();
return file.name.toLowerCase().includes(searchLower) ||
(file.type && file.type.toLowerCase().includes(searchLower));
});
this.roomManager.viewManager.renderFiles(filteredFiles);
// Fetch all files from the server for searching
fetch(`/api/rooms/${this.roomManager.roomId}/search?query=${encodeURIComponent(searchTerm)}`)
.then(response => response.json())
.then(files => {
// Modify the file objects to show full paths in search results
const modifiedFiles = files.map(file => ({
...file,
displayName: this.isSearching ? file.full_path : file.name
}));
this.roomManager.viewManager.renderFiles(modifiedFiles);
})
.catch(error => {
console.error('Error performing search:', error);
});
}
/**