@@ -75,7 +75,6 @@ import { updateSelectedFacetBucket } from './utils/facet-utils';
7575import chevronIcon from './assets/img/icons/chevron' ;
7676import { srOnlyStyle } from './styles/sr-only' ;
7777import { sha1 } from './utils/sha1' ;
78- import { log } from './utils/log' ;
7978import type { PlaceholderType } from './empty-placeholder' ;
8079import type { ManageBar } from './manage/manage-bar' ;
8180import type { SmartFacetBar } from './collection-facets/smart-facets/smart-facet-bar' ;
@@ -858,21 +857,14 @@ export class CollectionBrowser
858857 if ( this . suppressSortBar ) return nothing ;
859858
860859 // Determine the set of sortable fields that should be shown in the sort bar
861- let defaultViewSort = SortField . weeklyview ;
862- let defaultDateSort = SortField . date ;
863860 let sortFieldAvailability = defaultSortAvailability ;
864861
865- // We adjust the sort options for a couple of special cases...
862+ // We adjust the available sort options for a couple of special cases...
866863 if ( this . withinCollection ?. startsWith ( 'fav-' ) ) {
867- // When viewing a fav- collection, we include the Date Favorited option and show
868- // it as the default in the date dropdown.
869- defaultDateSort = SortField . datefavorited ;
864+ // When viewing a fav- collection, we include the Date Favorited option as the default
870865 sortFieldAvailability = favoritesSortAvailability ;
871866 } else if ( ! this . withinCollection && this . searchType === SearchType . TV ) {
872- // When viewing TV search results, we default the views dropdown to All-time Views
873- // and exclude several of the usual date sort options.
874- defaultViewSort = SortField . alltimeview ;
875- defaultDateSort = SortField . datearchived ;
867+ // When viewing TV search results, we exclude several of the usual date sort options.
876868 sortFieldAvailability = tvSortAvailability ;
877869 }
878870
@@ -883,16 +875,13 @@ export class CollectionBrowser
883875 <sor t- filter- bar
884876 .defaultSortField = ${ this . defaultSortField }
885877 .defaultSortDirection = ${ this . defaultSortDirection }
886- .defaultViewSort = ${ defaultViewSort }
887- .defaultDateSort = ${ defaultDateSort }
888878 .selectedSort = ${ this . selectedSort }
889879 .sortDirection = ${ this . sortDirection }
890880 .sortFieldAvailability = ${ sortFieldAvailability }
891881 .displayMode = ${ this . displayMode }
892882 .selectedTitleFilter = ${ this . selectedTitleFilter }
893883 .selectedCreatorFilter = ${ this . selectedCreatorFilter }
894884 .prefixFilterCountMap = ${ this . dataSource . prefixFilterCountMap }
895- .resizeObserver = ${ this . resizeObserver }
896885 .enableSortOptionsSlot = ${ this . enableSortOptionsSlot }
897886 .suppressDisplayModes = ${ this . suppressDisplayModes }
898887 @sortChanged = ${ this . userChangedSort }
@@ -1643,7 +1632,6 @@ export class CollectionBrowser
16431632 dataSource : CollectionBrowserDataSourceInterface ,
16441633 queryState : CollectionBrowserQueryState ,
16451634 ) : Promise < void > {
1646- log ( 'Installing data source & query state in CB:' , dataSource , queryState ) ;
16471635 if ( this . dataSource ) this . removeController ( this . dataSource ) ;
16481636 this . dataSource = dataSource ;
16491637 this . addController ( this . dataSource ) ;
@@ -1772,6 +1760,17 @@ export class CollectionBrowser
17721760 this . applyDefaultProfileSort ( ) ;
17731761 }
17741762
1763+ if ( changed . has ( 'withinCollection' ) && this . withinCollection ) {
1764+ // Set a sensible default collection sort while we load results, which we will later
1765+ // adjust based on any sort-by metadata once the response arrives.
1766+ if ( ! this . baseQuery ) {
1767+ this . defaultSortField = this . withinCollection . startsWith ( 'fav-' )
1768+ ? SortField . datefavorited
1769+ : SortField . weeklyview ;
1770+ this . defaultSortDirection = 'desc' ;
1771+ }
1772+ }
1773+
17751774 if ( changed . has ( 'baseQuery' ) ) {
17761775 this . emitBaseQueryChanged ( ) ;
17771776 }
@@ -2259,12 +2258,8 @@ export class CollectionBrowser
22592258 this . displayMode = restorationState . displayMode ;
22602259 if ( ! this . suppressURLSinParam && restorationState . searchType != null )
22612260 this . searchType = restorationState . searchType ;
2262- this . selectedSort =
2263- restorationState . selectedSort ??
2264- this . defaultSortField ??
2265- SortField . default ;
2266- this . sortDirection =
2267- restorationState . sortDirection ?? this . defaultSortDirection ?? null ;
2261+ this . selectedSort = restorationState . selectedSort ?? SortField . default ;
2262+ this . sortDirection = restorationState . sortDirection ?? null ;
22682263 this . selectedTitleFilter = restorationState . selectedTitleFilter ?? null ;
22692264 this . selectedCreatorFilter = restorationState . selectedCreatorFilter ?? null ;
22702265 this . selectedFacets = restorationState . selectedFacets ;
0 commit comments