@@ -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- } ) ;
4124function debounce ( fn , ms ) {
4225 var timer ;
4326 return function ( ) {
@@ -874,8 +857,10 @@ document.addEventListener("DOMContentLoaded", function () {
874857var searchInput = document . querySelector ( ".sidebar-dock #searchInput" ) ;
875858var searchDropdown = document . getElementById ( "searchDropdown" ) ;
876859var 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" ) ;
879864var resultsList = document . getElementById ( "resultsList" ) ;
880865var resultsSection = document . getElementById ( "resultsSection" ) ;
881866var tipsSection = document . getElementById ( "tipsSection" ) ;
@@ -980,16 +965,17 @@ function openDropdown() {
980965// Render recent searches
981966function 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}
0 commit comments