mirror of
https://github.com/olehomelchenko/astrolabe.git
synced 2025-12-21 21:22:25 +00:00
feat: add search functionality for snippets with input field in UI
This commit is contained in:
@@ -2,6 +2,7 @@ export class UIManager {
|
||||
constructor(snippetManager) {
|
||||
this.snippetManager = snippetManager;
|
||||
this.setupEventListeners();
|
||||
this.setupSearchInput();
|
||||
}
|
||||
|
||||
setupEventListeners() {
|
||||
@@ -147,4 +148,25 @@ export class UIManager {
|
||||
'View Saved' :
|
||||
'View Draft';
|
||||
}
|
||||
|
||||
setupSearchInput() {
|
||||
const searchInput = document.getElementById('snippet-search');
|
||||
searchInput.addEventListener('input', (e) => {
|
||||
const query = e.target.value;
|
||||
let filteredSnippets;
|
||||
try {
|
||||
const regex = new RegExp(query, 'i');
|
||||
filteredSnippets = this.snippetManager.snippets.filter(snippet => {
|
||||
const snippetText = JSON.stringify(snippet);
|
||||
return regex.test(snippetText);
|
||||
});
|
||||
} catch (err) {
|
||||
filteredSnippets = this.snippetManager.snippets.filter(snippet => {
|
||||
const snippetText = JSON.stringify(snippet).toLowerCase();
|
||||
return snippetText.includes(query.toLowerCase());
|
||||
});
|
||||
}
|
||||
this.renderSnippetList(filteredSnippets, this.snippetManager.currentSnippetId);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user