search all categories
This commit is contained in:
1 parent
e7cf77e57e
commit
089982a5c5
2 files changed
+137
-10
No files matched your search
+28
-10
@@ -417,7 +417,7 @@ function initSearch() {
|
||||
|
||||
searchTimeout = setTimeout(() => {
|
||||
performSearch(query);
|
||||
}, 300);
|
||||
}, 200);
|
||||
});
|
||||
|
||||
// Search button click
|
||||
@@ -492,13 +492,27 @@ function initSearch() {
|
||||
}
|
||||
|
||||
function performSearch(query) {
|
||||
const results = allBookmarks.filter(bookmark =>
|
||||
bookmark.title.toLowerCase().includes(query.toLowerCase()) ||
|
||||
bookmark.url.toLowerCase().includes(query.toLowerCase()) ||
|
||||
bookmark.category.toLowerCase().includes(query.toLowerCase())
|
||||
);
|
||||
|
||||
displaySearchResults(results, query);
|
||||
// Use API to search all bookmarks
|
||||
fetch(`api/search.php?q=${encodeURIComponent(query)}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.error) {
|
||||
console.error('Search error:', data.error);
|
||||
displaySearchResults([], query);
|
||||
return;
|
||||
}
|
||||
displaySearchResults(data.results || [], query);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Search failed:', error);
|
||||
// Fallback to local search
|
||||
const results = allBookmarks.filter(bookmark =>
|
||||
bookmark.title.toLowerCase().includes(query.toLowerCase()) ||
|
||||
bookmark.url.toLowerCase().includes(query.toLowerCase()) ||
|
||||
bookmark.category.toLowerCase().includes(query.toLowerCase())
|
||||
);
|
||||
displaySearchResults(results, query);
|
||||
});
|
||||
}
|
||||
|
||||
function displaySearchResults(results, query) {
|
||||
@@ -534,13 +548,17 @@ function initSearch() {
|
||||
hideSearchResults();
|
||||
};
|
||||
|
||||
const categoryText = bookmark.category ? bookmark.category : '';
|
||||
const tabText = bookmark.tab ? ` (${bookmark.tab})` : '';
|
||||
const favoriteIcon = bookmark.is_favorite ? ' <i class="bi bi-star-fill text-warning"></i>' : '';
|
||||
|
||||
resultItem.innerHTML = `
|
||||
<img src="${bookmark.icon}" alt="" class="bookmark-icon" onerror="this.onerror=null;this.src='include/images/default-icon.png';">
|
||||
<div class="bookmark-info">
|
||||
<div class="bookmark-title">${bookmark.title}</div>
|
||||
<div class="bookmark-title">${bookmark.title}${favoriteIcon}</div>
|
||||
<div class="bookmark-url">${bookmark.url}</div>
|
||||
</div>
|
||||
${bookmark.category ? `<span class="bookmark-category">${bookmark.category}</span>` : ''}
|
||||
${categoryText ? `<span class="bookmark-category">${categoryText}${tabText}</span>` : ''}
|
||||
`;
|
||||
|
||||
searchResults.appendChild(resultItem);
|
||||
|
||||
Reference in new issue
Block a user