@@ -105,10 +105,12 @@ export class ProblemMainHandler extends Handler {
105105 @param ( 'limit' , Types . PositiveInt , true )
106106 @param ( 'pjax' , Types . Boolean )
107107 @param ( 'quick' , Types . Boolean )
108- async get ( domainId : string , page = 1 , q = '' , limit : number , pjax = false , quick = false ) {
108+ @param ( 'sort' , Types . Range ( [ 'default' , 'recent' ] ) , true )
109+ async get ( domainId : string , page = 1 , q = '' , limit : number , pjax = false , quick = false , sortStrategy = 'default' ) {
109110 this . response . template = 'problem_main.html' ;
110111 if ( ! limit || limit > this . ctx . setting . get ( 'pagination.problem' ) || page > 1 ) limit = this . ctx . setting . get ( 'pagination.problem' ) ;
111112 this . queryContext . query = buildQuery ( this . user ) ;
113+ if ( sortStrategy === 'recent' ) this . queryContext . hint = 'basic' ;
112114 // eslint-disable-next-line ts/no-shadow
113115 const query = this . queryContext . query ;
114116 const psdict = { } ;
@@ -145,11 +147,15 @@ export class ProblemMainHandler extends Handler {
145147 }
146148 const sort = this . queryContext . sort ;
147149 await this . ctx . parallel ( 'problem/list' , query , this , sort ) ;
150+ const sortKey = ( {
151+ default : { sort : 1 , docId : 1 } ,
152+ recent : { docId : - 1 } ,
153+ } as const ) [ sortStrategy ] ;
148154 let [ pdocs , ppcount , pcount ] = this . queryContext . fail
149155 ? [ [ ] , 0 , 0 ]
150156 : await this . paginate (
151157 problem . getMulti ( domainId , query , quick ? [ 'title' , 'pid' , 'domainId' , 'docId' ] : undefined )
152- . sort ( { sort : 1 , docId : 1 } ) . hint ( this . queryContext . hint ) ,
158+ . sort ( sortKey ) . hint ( this . queryContext . hint ) ,
153159 sort . length ? 1 : page , limit ,
154160 ) ;
155161 if ( total ) {
@@ -169,7 +175,7 @@ export class ProblemMainHandler extends Handler {
169175 title : this . renderTitle ( this . translate ( 'problem_main' ) ) ,
170176 fragments : ( await Promise . all ( [
171177 this . renderHTML ( 'partials/problem_list.html' , {
172- page, ppcount, pcount, pdocs, psdict, qs : q ,
178+ page, ppcount, pcount, pdocs, psdict, qs : q , sort : sortStrategy ,
173179 } ) ,
174180 this . renderHTML ( 'partials/problem_stat.html' , { pcount, pcountRelation : this . queryContext . pcountRelation } ) ,
175181 this . renderHTML ( 'partials/problem_lucky.html' , { qs : q } ) ,
@@ -184,6 +190,7 @@ export class ProblemMainHandler extends Handler {
184190 pdocs,
185191 psdict,
186192 qs : q ,
193+ sort : sortStrategy ,
187194 } ;
188195 }
189196 }
0 commit comments