@@ -523,6 +523,7 @@ function refreshLibrary(options) {
523
523
// Work out what we should be filtering, based on the URL
524
524
let searchType = "" ; // possible values: hash, chip, full, id
525
525
let searchValue = "" ; // the actual value to search for
526
+ let searchChip = "" ; // if a chip was selected, this is the one to use
526
527
527
528
if ( window . location . hash ) {
528
529
searchValue = decodeURIComponent ( window . location . hash . slice ( 1 ) ) . toLowerCase ( ) ;
@@ -539,17 +540,19 @@ function refreshLibrary(options) {
539
540
searchType = "full" ;
540
541
}
541
542
if ( searchParams . has ( "c" ) ) {
542
- searchValue = searchParams . get ( "c" ) . toLowerCase ( ) ;
543
- searchType = "chip" ;
543
+ searchChip = searchParams . get ( "c" ) . toLowerCase ( ) ;
544
544
}
545
545
}
546
- if ( searchType === "hash" && chips . indexOf ( searchValue ) >= 0 )
547
- searchType = "chip" ;
546
+ if ( searchType === "hash" && chips . indexOf ( searchValue ) >= 0 ) {
547
+ searchType = "" ;
548
+ searchValue = "" ;
549
+ searchChip = searchValue ;
550
+ }
548
551
// Update the 'chips' to match the current window location
549
552
let filtersContainer = document . querySelector ( "#librarycontainer .filter-nav" ) ;
550
553
filtersContainer . querySelector ( '.active' ) . classList . remove ( 'active' ) ;
551
- if ( searchType == "chip" ) {
552
- let hashFilter = filtersContainer . querySelector ( '.chip[filterid="' + searchValue + '"]' ) ;
554
+ if ( searchChip ) {
555
+ let hashFilter = filtersContainer . querySelector ( '.chip[filterid="' + searchChip + '"]' ) ;
553
556
if ( hashFilter ) hashFilter . classList . add ( 'active' ) ;
554
557
} else filtersContainer . querySelector ( '.chip[filterid]' ) . classList . add ( 'active' ) ;
555
558
// update the search box value
@@ -562,29 +565,28 @@ function refreshLibrary(options) {
562
565
// Now filter according to what was set
563
566
let visibleApps = appJSON . slice ( ) ; // clone so we don't mess with the original
564
567
let sortedByRelevance = false ;
568
+ // filter visibleApps by chip
569
+ let searchResult ; // array of { app:app, relevance:number }
570
+ if ( searchChip ) {
571
+ if ( searchChip == "favourites" ) {
572
+ visibleApps = visibleApps . filter ( app => app . id ?SETTINGS . favourites . filter ( e => e == app . id ) . length :0 ) ;
573
+ } else {
574
+ // Some chips represent a metadata "type" element:
575
+ // - the "Clocks" chip must show only apps with "type": "clock"
576
+ // - the "Widgets" chip must show only apps with "type": "widget"
577
+ // and so on.
578
+ // If the type is NOT in the array below then the search will be tag-based instead
579
+ // of type-based.
580
+ const supportedMetadataTypes = [ "clock" , "widget" , "launch" , "textinput" , "ram" ] ;
581
+ if ( supportedMetadataTypes . includes ( searchChip . toLowerCase ( ) ) )
582
+ visibleApps = visibleApps . filter ( app => ( app . type || "app" ) . toLowerCase ( ) == searchChip . toLowerCase ( ) ) ;
583
+ else
584
+ visibleApps = visibleApps . filter ( app => app . tags && app . tags . split ( ',' ) . includes ( searchChip ) ) ;
585
+ }
586
+ }
587
+ // Now do our search, put the values in searchResult
565
588
if ( searchValue ) {
566
- // Now do our search, put the values in searchResult
567
- let searchResult ; // array of { app:app, relevance:number }
568
- if ( searchType === "chip" ) {
569
- if ( searchValue == "favourites" ) {
570
- searchResult = visibleApps . map ( app => ( {
571
- app : app ,
572
- relevance : app . id ?SETTINGS . favourites . filter ( e => e == app . id ) . length :0
573
- } ) ) ;
574
- } else {
575
- // Some chips represent a metadata "type" element:
576
- // - the "Clocks" chip must show only apps with "type": "clock"
577
- // - the "Widgets" chip must show only apps with "type": "widget"
578
- // and so on.
579
- // If the type is NOT in the array below then the search will be tag-based instead
580
- // of type-based.
581
- const supportedMetadataTypes = [ "clock" , "widget" , "launch" , "textinput" , "ram" ] ;
582
- if ( supportedMetadataTypes . includes ( searchValue . toLowerCase ( ) ) )
583
- searchResult = visibleApps . map ( app => ( { app :app , relevance : ( app . type || "app" ) . toLowerCase ( ) == searchValue . toLowerCase ( ) ? 1 : 0 } ) ) ;
584
- else
585
- searchResult = visibleApps . map ( app => ( { app :app , relevance : ( app . tags && app . tags . split ( ',' ) . includes ( searchValue ) ) ? 1 : 0 } ) ) ;
586
- }
587
- } else if ( searchType === "hash" ) {
589
+ if ( searchType === "hash" ) {
588
590
sortedByRelevance = true ;
589
591
searchResult = visibleApps . map ( app => ( {
590
592
app : app ,
@@ -1140,9 +1142,13 @@ const searchInputChangedDebounced = debounce(function() {
1140
1142
refreshLibrary ( { dontChangeSearchBox :true } ) ;
1141
1143
} , 300 ) ;
1142
1144
librarySearchInput . addEventListener ( 'input' , evt => {
1143
- var searchValue = evt . target . value . toLowerCase ( ) ;
1145
+ let searchValue = evt . target . value . toLowerCase ( ) ;
1144
1146
// Update window URL
1145
- window . history . replaceState ( null , null , "?q=" + searchValue ) ;
1147
+ let c = "" ;
1148
+ let searchParams = new URLSearchParams ( window . location . search ) ;
1149
+ if ( searchParams . has ( "c" ) )
1150
+ c = `c=${ encodeURIComponent ( searchParams . get ( "c" ) . toLowerCase ( ) ) } &` ;
1151
+ window . history . replaceState ( null , null , `?${ c } q=${ encodeURIComponent ( searchValue ) } ` ) ;
1146
1152
searchInputChangedDebounced ( ) ;
1147
1153
} ) ;
1148
1154
0 commit comments