Skip to content

Commit c16aeae

Browse files
Add real-time search bar (#17)
* Add real-time search bar - Search input above the filter section searches across conference name, description, venue, and location as you type - Search and tag filters compose — both must match for an entry to show - Clear (×) button on the search input resets the query - Clear Filters button now also resets the search input * Move search bar below filters; fix clear button height * Fix search bar spacing: add top margin above search row
1 parent 46df612 commit c16aeae

3 files changed

Lines changed: 78 additions & 4 deletions

File tree

index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ <h1>
100100
<button class="btn btn-default btn-sm sort-btn" data-sort="event-date">Event Date</button>
101101
</div>
102102

103+
<div class="col-xs-12 search-row">
104+
<div class="input-group search-bar">
105+
<span class="input-group-addon"><i class="fas fa-search"></i></span>
106+
<input type="text" id="search-input" class="form-control" placeholder="Search by name, venue, location…" autocomplete="off">
107+
<span class="input-group-btn">
108+
<button id="clear-search" class="btn btn-default" type="button" title="Clear search"><i class="fas fa-times"></i></button>
109+
</span>
110+
</div>
111+
</div>
112+
103113
</div>
104114

105115
</div>

static/css/styles.css

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,45 @@ h2 .evtname {
1111
opacity: 0.5;
1212
}
1313

14+
.search-row {
15+
margin-top: 16px;
16+
margin-bottom: 4px;
17+
}
18+
19+
.search-bar .input-group-addon {
20+
background: #fff;
21+
border-right: none;
22+
color: #007bff;
23+
font-size: 14px;
24+
}
25+
26+
.search-bar .form-control {
27+
border-left: none;
28+
box-shadow: none;
29+
font-size: 14px;
30+
}
31+
32+
.search-bar .form-control:focus {
33+
border-color: #007bff;
34+
box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.12);
35+
}
36+
37+
.search-bar .input-group-btn .btn {
38+
border-left: none;
39+
color: #aaa;
40+
box-shadow: none;
41+
height: 34px;
42+
padding-top: 6px;
43+
padding-bottom: 6px;
44+
font-size: 14px;
45+
line-height: 1.42857;
46+
}
47+
48+
.search-bar .input-group-btn .btn:hover {
49+
color: #555;
50+
background: #f8f9fa;
51+
}
52+
1453
.sort-label {
1554
margin-left: 10px;
1655
margin-right: 5px;

static/js/main.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,26 @@ $(function() {
246246
filter3: new Set()
247247
};
248248

249+
var searchQuery = '';
250+
249251
function updateConfList() {
250252
$(".conf").each(function () {
251253
let conf = $(this);
252254
let show = true;
253255

256+
// Check search query against name, description, date, and place
257+
if (searchQuery) {
258+
let text = (
259+
conf.find('.conf-title').text() + ' ' +
260+
conf.find('.meta').first().text() + ' ' +
261+
conf.find('.conf-date').text() + ' ' +
262+
conf.find('.conf-place').text()
263+
).toLowerCase();
264+
if (text.indexOf(searchQuery) === -1) {
265+
show = false;
266+
}
267+
}
268+
254269
// Check each filter group
255270
Object.keys(selectedFilters).forEach(filterGroup => {
256271
if (selectedFilters[filterGroup].size > 0) {
@@ -266,7 +281,6 @@ $(function() {
266281
}
267282
});
268283

269-
// Show or hide based on filter matching
270284
if (show) {
271285
conf.show();
272286
} else {
@@ -291,16 +305,27 @@ $(function() {
291305

292306
// Handle "Clear Filters" button click
293307
$("#clear-filters").click(function () {
294-
// Uncheck all checkboxes
295308
$(".filter-checkbox").prop("checked", false);
296-
297-
// Reset the selected filters
298309
selectedFilters = {
299310
filter1: new Set(),
300311
filter2: new Set(),
301312
filter3: new Set()
302313
};
314+
searchQuery = '';
315+
$('#search-input').val('');
316+
updateConfList();
317+
});
318+
319+
// Search input handler
320+
$('#search-input').on('input', function () {
321+
searchQuery = $(this).val().toLowerCase().trim();
322+
updateConfList();
323+
});
303324

325+
// Clear search button
326+
$('#clear-search').click(function () {
327+
searchQuery = '';
328+
$('#search-input').val('').focus();
304329
updateConfList();
305330
});
306331

0 commit comments

Comments
 (0)