Skip to content

Commit 28805bb

Browse files
Merge pull request steam-bell-92#1695 from Lakshayg136/fix/search-history-1677
fix: resolve non-functional search history and clear buttons
2 parents 5448a2e + 1eb13b8 commit 28805bb

5 files changed

Lines changed: 49 additions & 59 deletions

File tree

web-app/games.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,14 @@
158158
>
159159
<div class="spinner"></div>
160160
</div>
161-
<div class="recent-searches-section" id="recentSearchesSection">
161+
<div class="recent-searches-section" id="dropdownRecentSearchesSection">
162162
<div class="dropdown-section-title recent-searches-header">
163163
<span class="recent-searches-heading">
164164
<i class="fas fa-history" aria-hidden="true"></i>
165165
Recent Searches
166166
</span>
167167
</div>
168-
<div class="recent-searches-chips" id="recentSearchesList" role="list"></div>
168+
<div class="recent-searches-chips" id="dropdownRecentSearchesList" role="list"></div>
169169
</div>
170170
<div
171171
class="results-section"

web-app/index.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@
7272
<div class="search-loader" id="searchLoader" style="display: none">
7373
<div class="spinner"></div>
7474
</div>
75-
<div class="recent-searches-section" id="recentSearchesSection">
75+
<div class="recent-searches-section" id="dropdownRecentSearchesSection">
7676
<div class="dropdown-section-title">
7777
<span>Recent</span>
78-
<button id="clearRecentBtn" class="recent-clear-all-btn" aria-label="Clear recent searches">Clear
78+
<button id="clearRecentDropdownBtn" class="recent-clear-all-btn" aria-label="Clear recent searches">Clear
7979
All</button>
8080
</div>
81-
<div class="dropdown-list" id="recentSearchesList"></div>
81+
<div class="dropdown-list" id="dropdownRecentSearchesList"></div>
8282
</div>
8383
<div class="results-section" id="resultsSection" style="display: none">
8484
<div class="dropdown-section-title">Projects</div>
@@ -104,17 +104,17 @@
104104
</div>
105105
</div>
106106

107-
<div class="recent-searches-section" id="recentSearchesSection">
107+
<div class="recent-searches-section" id="sidebarRecentSearchesSection">
108108
<div class="dropdown-section-title recent-searches-header" style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;">
109109
<span class="recent-searches-heading" style="color: #e2e8f0; font-weight: 500;">
110110
<i class="fas fa-history" aria-hidden="true" style="margin-right: 6px; color: #a78bfa;"></i>
111111
Search History
112112
</span>
113-
<button id="clearRecentBtn" class="recent-clear-all-btn" aria-label="Clear recent searches" style="background: none; border: none; color: #ef4444; font-size: 0.85rem; cursor: pointer; display: flex; align-items: center; gap: 5px;">
113+
<button id="clearRecentSidebarBtn" class="recent-clear-all-btn" aria-label="Clear recent searches" style="background: none; border: none; color: #ef4444; font-size: 0.85rem; cursor: pointer; display: flex; align-items: center; gap: 5px;">
114114
<i class="fas fa-trash-alt"></i> Clear History
115115
</button>
116116
</div>
117-
<div class="recent-searches-chips" id="recentSearchesList" role="list"></div>
117+
<div class="recent-searches-chips" id="sidebarRecentSearchesList" role="list"></div>
118118
</div>
119119

120120
<div class="sidebar-menu-wrapper">

web-app/js/main.js

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,7 @@ function safeRun(fn) {
2020
console.error(e);
2121
}
2222
}
23-
// Import the initSearch function from your updated search module
24-
import { initSearch } from "./modules/search.js";
2523

26-
document.addEventListener("DOMContentLoaded", () => {
27-
// Other initializations...
28-
29-
// Initialize the search bar
30-
initSearch((query) => {
31-
// This callback runs whenever a search is triggered
32-
console.log("Searching for:", query);
33-
34-
// If you have a function that filters projects globally, call it here.
35-
// Example:
36-
// if (typeof window.applySearchFilter === 'function') {
37-
// window.applySearchFilter(query);
38-
// }
39-
});
40-
});
4124
function debounce(fn, ms) {
4225
var timer;
4326
return function () {
@@ -874,8 +857,10 @@ document.addEventListener("DOMContentLoaded", function () {
874857
var searchInput = document.querySelector(".sidebar-dock #searchInput");
875858
var searchDropdown = document.getElementById("searchDropdown");
876859
var searchLoader = document.getElementById("searchLoader");
877-
var recentSearchesList = document.getElementById("recentSearchesList");
878-
var recentSearchesSection = document.getElementById("recentSearchesSection");
860+
// Select all list containers and sections for dropdown and sidebar variants (including fallbacks)
861+
var recentSearchesLists = document.querySelectorAll("#recentSearchesList, #dropdownRecentSearchesList, #sidebarRecentSearchesList");
862+
var recentSearchesSections = document.querySelectorAll("#recentSearchesSection, #dropdownRecentSearchesSection, #sidebarRecentSearchesSection");
863+
var dropdownRecentSearchesSection = document.getElementById("dropdownRecentSearchesSection") || document.getElementById("recentSearchesSection");
879864
var resultsList = document.getElementById("resultsList");
880865
var resultsSection = document.getElementById("resultsSection");
881866
var tipsSection = document.getElementById("tipsSection");
@@ -980,16 +965,17 @@ function openDropdown() {
980965
// Render recent searches
981966
function renderRecentSearches() {
982967
if (noResultsMessage) noResultsMessage.style.display = "none";
983-
if (!recentSearchesSection) return;
968+
if (recentSearchesSections.length === 0) return;
984969

985-
if (recentSearchesList) {
986-
recentSearchesList.innerHTML = "";
970+
recentSearchesLists.forEach(function (listContainer) {
971+
if (!listContainer) return;
972+
listContainer.innerHTML = "";
987973

988974
if (recentSearches.length === 0) {
989975
var emptyEl = document.createElement("p");
990976
emptyEl.className = "recent-searches-empty";
991977
emptyEl.textContent = "No recent searches yet. Start exploring projects!";
992-
recentSearchesList.appendChild(emptyEl);
978+
listContainer.appendChild(emptyEl);
993979
} else {
994980
recentSearches.slice(0, 5).forEach(function (search) {
995981
var chip = document.createElement("div");
@@ -1030,32 +1016,36 @@ function renderRecentSearches() {
10301016
renderRecentSearches();
10311017
});
10321018

1033-
recentSearchesList.appendChild(chip);
1019+
listContainer.appendChild(chip);
10341020
});
10351021
}
1022+
});
10361023

1037-
// Clear recent button
1038-
var headerClearBtn = document.getElementById("clearRecentBtn");
1039-
if (headerClearBtn) {
1040-
headerClearBtn.style.display = recentSearches.length ? "inline-flex" : "none";
1041-
headerClearBtn.onclick = function (e) {
1042-
e.stopPropagation();
1043-
if (!recentSearches || recentSearches.length === 0) return;
1044-
showConfirm(
1045-
"Clear all recent searches? This cannot be undone.",
1046-
function () {
1047-
recentSearches = [];
1048-
localStorage.setItem("recentSearches", JSON.stringify(recentSearches));
1049-
renderRecentSearches();
1050-
closeDropdown();
1051-
},
1052-
function () {}
1053-
);
1054-
};
1055-
}
1056-
}
1024+
// Clear recent buttons
1025+
var clearRecentBtns = document.querySelectorAll("#clearRecentBtn, #clearRecentDropdownBtn, #clearRecentSidebarBtn");
1026+
clearRecentBtns.forEach(function (btn) {
1027+
if (!btn) return;
1028+
btn.style.display = recentSearches.length ? "inline-flex" : "none";
1029+
btn.onclick = function (e) {
1030+
e.stopPropagation();
1031+
if (!recentSearches || recentSearches.length === 0) return;
1032+
showConfirm(
1033+
"Clear all recent searches? This cannot be undone.",
1034+
function () {
1035+
recentSearches = [];
1036+
localStorage.setItem("recentSearches", JSON.stringify(recentSearches));
1037+
renderRecentSearches();
1038+
closeDropdown();
1039+
},
1040+
function () {}
1041+
);
1042+
};
1043+
});
10571044

1058-
recentSearchesSection.style.display = "block";
1045+
recentSearchesSections.forEach(function (section) {
1046+
if (!section) return;
1047+
section.style.display = "block";
1048+
});
10591049
if (resultsSection) resultsSection.style.display = "none";
10601050
if (tipsSection) tipsSection.style.display = "block";
10611051
}
@@ -1073,7 +1063,7 @@ function renderSuggestions(query) {
10731063

10741064
if (matches.length === 0) {
10751065
if (resultsSection) resultsSection.style.display = "none";
1076-
if (recentSearchesSection) recentSearchesSection.style.display = "none";
1066+
if (dropdownRecentSearchesSection) dropdownRecentSearchesSection.style.display = "none";
10771067
if (tipsSection) tipsSection.style.display = "block";
10781068
if (noResultsMessage) {
10791069
noResultsMessage.style.display = "block";
@@ -1137,7 +1127,7 @@ function renderSuggestions(query) {
11371127
}
11381128

11391129
if (resultsSection) resultsSection.style.display = "block";
1140-
if (recentSearchesSection) recentSearchesSection.style.display = "none";
1130+
if (dropdownRecentSearchesSection) dropdownRecentSearchesSection.style.display = "none";
11411131
if (tipsSection) tipsSection.style.display = "none";
11421132
selectedSuggestionIndex = -1;
11431133
}

web-app/math.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,14 @@
161161
>
162162
<div class="spinner"></div>
163163
</div>
164-
<div class="recent-searches-section" id="recentSearchesSection">
164+
<div class="recent-searches-section" id="dropdownRecentSearchesSection">
165165
<div class="dropdown-section-title recent-searches-header">
166166
<span class="recent-searches-heading">
167167
<i class="fas fa-history" aria-hidden="true"></i>
168168
Recent Searches
169169
</span>
170170
</div>
171-
<div class="recent-searches-chips" id="recentSearchesList" role="list"></div>
171+
<div class="recent-searches-chips" id="dropdownRecentSearchesList" role="list"></div>
172172
</div>
173173
<div
174174
class="results-section"

web-app/utilities.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,14 @@
158158
>
159159
<div class="spinner"></div>
160160
</div>
161-
<div class="recent-searches-section" id="recentSearchesSection">
161+
<div class="recent-searches-section" id="dropdownRecentSearchesSection">
162162
<div class="dropdown-section-title recent-searches-header">
163163
<span class="recent-searches-heading">
164164
<i class="fas fa-history" aria-hidden="true"></i>
165165
Recent Searches
166166
</span>
167167
</div>
168-
<div class="recent-searches-chips" id="recentSearchesList" role="list"></div>
168+
<div class="recent-searches-chips" id="dropdownRecentSearchesList" role="list"></div>
169169
</div>
170170
<div
171171
class="results-section"

0 commit comments

Comments
 (0)