Skip to content

Commit c4e4a1e

Browse files
committed
Add search results info bar
- Add info bar above search results showing match count - Display 'X matches found in Y snippets' when search is active - Hide info bar when no search query is entered - Update HTML structure to accommodate info bar
1 parent 2147dde commit c4e4a1e

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

public/index.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,13 @@ <h1 class="text-2xl font-bold">massCode-Web</h1>
5555
</div>
5656
</footer>
5757
</aside>
58-
<main id="snippets-container" class="flex-1 p-4 overflow-y-auto bg-white dark:bg-gray-900 transition-colors md:ml-0">
59-
<!-- Snippets will be rendered here -->
58+
<main class="flex-1 flex flex-col bg-white dark:bg-gray-900 transition-colors md:ml-0">
59+
<div id="search-info-bar" class="hidden px-4 py-2 bg-blue-50 border-b border-blue-200 text-blue-800 text-sm dark:bg-blue-900 dark:border-blue-700 dark:text-blue-200">
60+
<!-- Search results info will be displayed here -->
61+
</div>
62+
<div id="snippets-container" class="flex-1 p-4 overflow-y-auto">
63+
<!-- Snippets will be rendered here -->
64+
</div>
6065
</main>
6166
</div>
6267
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-core.min.js"></script>

public/js/app.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ document.addEventListener('DOMContentLoaded', () => {
77
const sidebar = document.getElementById('sidebar');
88
const sidebarBackdrop = document.getElementById('sidebar-backdrop');
99
const themeToggle = document.getElementById('theme-toggle');
10+
const searchInfoBar = document.getElementById('search-info-bar');
1011
let dbData = null;
1112
let currentSnippets = [];
1213
let loadedCount = 0;
@@ -220,6 +221,9 @@ document.addEventListener('DOMContentLoaded', () => {
220221
highlightedValue: content.value // No highlighting
221222
}))
222223
}));
224+
225+
// Hide search info bar when no search is active
226+
searchInfoBar.classList.add('hidden');
223227
} else {
224228
// Filter snippets and determine which tab should be active
225229
const filteredSnippets = activeSnippets.filter(snippet => {
@@ -265,6 +269,35 @@ document.addEventListener('DOMContentLoaded', () => {
265269
}));
266270

267271
currentSnippets = filteredSnippets;
272+
273+
// Show search info bar with match information
274+
const snippetCount = currentSnippets.length;
275+
const totalSnippets = activeSnippets.length;
276+
277+
// Count total matches across all snippets
278+
let totalMatches = 0;
279+
currentSnippets.forEach(snippet => {
280+
// Count matches in name
281+
if (matchesQuery(snippet.name, query)) {
282+
totalMatches++;
283+
}
284+
// Count matches in description
285+
if (snippet.description && matchesQuery(snippet.description, query)) {
286+
totalMatches++;
287+
}
288+
// Count matches in content
289+
snippet.content.forEach(content => {
290+
const highlighted = highlightSearchMatches(content.value, query);
291+
if (highlighted !== content.value) {
292+
// Count the number of <mark> tags (each represents a match)
293+
const matchCount = (highlighted.match(/<mark[^>]*>.*?<\/mark>/g) || []).length;
294+
totalMatches += matchCount;
295+
}
296+
});
297+
});
298+
299+
searchInfoBar.innerHTML = `${totalMatches} match${totalMatches !== 1 ? 'es' : ''} found in ${snippetCount} snippet${snippetCount !== 1 ? 's' : ''}`;
300+
searchInfoBar.classList.remove('hidden');
268301
}
269302

270303
loadedCount = 0;

0 commit comments

Comments
 (0)