Skip to content

Commit 77e19dd

Browse files
committed
Fix unresponsive UI caused by null DOM references
1 parent b0f4ef2 commit 77e19dd

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

web-app/js/main.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const themeToggle = document.getElementById('themeToggle');
33
const themeColorMeta = document.getElementById('themeColorMeta');
44
const html = document.documentElement;
55
const mainContent = document.getElementById('main-content');
6+
let recentSearches = [];
67

78
function prefersReducedMotion() {
89
return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
@@ -171,14 +172,21 @@ function highlightMatch(text, query) {
171172

172173
// Render recent searches
173174
function renderRecentSearches() {
174-
if (recentSearches.length === 0) {
175-
recentSearchesSection.style.display = 'none';
176-
tipsSection.style.display = 'block';
177-
resultsSection.style.display = 'none';
178-
return;
175+
if (recentSearchesSection) {
176+
recentSearchesSection.style.display = 'none';
177+
}
178+
179+
if (tipsSection) {
180+
tipsSection.style.display = 'block';
181+
}
182+
183+
if (resultsSection) {
184+
resultsSection.style.display = 'none';
179185
}
180186

187+
if (recentSearchesList) {
181188
recentSearchesList.innerHTML = '';
189+
}
182190
recentSearches.slice(0, 5).forEach((search) => {
183191
const item = document.createElement('div');
184192
item.className = 'dropdown-recent-item';
@@ -212,11 +220,15 @@ function renderRecentSearches() {
212220
recentSearchesList.appendChild(item);
213221
});
214222

223+
if (recentSearchesSection && resultsSection && tipsSection) {
215224
recentSearchesSection.style.display = 'block';
216225
resultsSection.style.display = 'none';
217226
tipsSection.style.display = 'block';
218227
}
219228

229+
230+
}
231+
220232
function applyCategoryFilter(category) {
221233
projectCards.forEach((card) => {
222234
if (category === 'all' || card.getAttribute('data-category') === category) {

0 commit comments

Comments
 (0)