1414
1515import React from "react" ;
1616import { Avatar , Button , Card , Col , Empty , Input , Row , Segmented , Select , Spin , Tag , Tooltip , Typography } from "antd" ;
17- import { CopyOutlined , InfoCircleOutlined , LinkOutlined , RobotOutlined , SortAscendingOutlined , SortDescendingOutlined } from "@ant-design/icons" ;
17+ import { CopyOutlined , EyeOutlined , ForkOutlined , InfoCircleOutlined , LinkOutlined , RobotOutlined , SortAscendingOutlined , SortDescendingOutlined , StarOutlined } from "@ant-design/icons" ;
1818import * as StoreBackend from "./backend/StoreBackend" ;
1919import * as Setting from "./Setting" ;
2020import i18next from "i18next" ;
@@ -38,8 +38,8 @@ class StoreHubPage extends React.Component {
3838 filterSubject : "" ,
3939 filterGrade : "" ,
4040 filterTopic : "" ,
41- sortField : "" ,
42- sortOrder : "asc " ,
41+ sortField : "starCount " ,
42+ sortOrder : "desc " ,
4343 } ;
4444 }
4545
@@ -117,7 +117,13 @@ class StoreHubPage extends React.Component {
117117 }
118118
119119 if ( sortField ) {
120+ const numericFields = [ "starCount" , "watchCount" , "forkCount" ] ;
120121 result . sort ( ( a , b ) => {
122+ if ( numericFields . includes ( sortField ) ) {
123+ const va = a [ sortField ] || 0 ;
124+ const vb = b [ sortField ] || 0 ;
125+ return sortOrder === "asc" ? va - vb : vb - va ;
126+ }
121127 let va , vb ;
122128 if ( sortField === "displayName" ) {
123129 va = ( a . displayName || a . name || "" ) . toLowerCase ( ) ;
@@ -139,8 +145,10 @@ class StoreHubPage extends React.Component {
139145 }
140146
141147 hasActiveFilters ( ) {
142- const { searchText, filterSubject, filterGrade, filterTopic, sortField} = this . state ;
143- return ! ! ( searchText || filterSubject || filterGrade || filterTopic || sortField ) ;
148+ const { searchText, filterSubject, filterGrade, filterTopic, sortField, sortOrder} = this . state ;
149+ // The default "most starred" sort is not considered an active filter.
150+ const nonDefaultSort = sortField !== "starCount" || sortOrder !== "desc" ;
151+ return ! ! ( searchText || filterSubject || filterGrade || filterTopic || nonDefaultSort ) ;
144152 }
145153
146154 resetFilters ( ) {
@@ -149,8 +157,8 @@ class StoreHubPage extends React.Component {
149157 filterSubject : "" ,
150158 filterGrade : "" ,
151159 filterTopic : "" ,
152- sortField : "" ,
153- sortOrder : "asc " ,
160+ sortField : "starCount " ,
161+ sortOrder : "desc " ,
154162 } ) ;
155163 }
156164
@@ -197,7 +205,9 @@ class StoreHubPage extends React.Component {
197205 const isFiltered = this . hasActiveFilters ( ) ;
198206
199207 const sortFieldOptions = [
200- { value : "" , label : i18next . t ( "general:Sort" ) } ,
208+ { value : "starCount" , label : i18next . t ( "store:Stars" ) } ,
209+ { value : "watchCount" , label : i18next . t ( "store:Watchers" ) } ,
210+ { value : "forkCount" , label : i18next . t ( "store:Forks" ) } ,
201211 { value : "displayName" , label : i18next . t ( "general:Display name" ) } ,
202212 { value : "author" , label : i18next . t ( "general:Author" ) } ,
203213 { value : "affiliation" , label : i18next . t ( "store:Affiliation" ) } ,
@@ -354,6 +364,11 @@ class StoreHubPage extends React.Component {
354364 ) : (
355365 < div style = { { height : 60 } } />
356366 ) }
367+ < div style = { { display : "flex" , alignItems : "center" , gap : 14 , marginBottom : 10 , color : "var(--ant-color-text-secondary)" , fontSize : 12 } } >
368+ < Tooltip title = { i18next . t ( "store:Stars" ) } > < span > < StarOutlined /> { store . starCount || 0 } </ span > </ Tooltip >
369+ < Tooltip title = { i18next . t ( "store:Watchers" ) } > < span > < EyeOutlined /> { store . watchCount || 0 } </ span > </ Tooltip >
370+ < Tooltip title = { i18next . t ( "store:Forks" ) } > < span > < ForkOutlined /> { store . forkCount || 0 } </ span > </ Tooltip >
371+ </ div >
357372 < div
358373 style = { {
359374 display : "flex" ,
0 commit comments