@@ -224,22 +224,22 @@ export const setPassword = (password: string) => {
224
224
cookieStorage . setItem ( "browser-password" , password )
225
225
}
226
226
227
- export const countMsg = ( filterType ?: ObjType ) => {
227
+ const getCountStr = (
228
+ objs : StoreObj [ ] ,
229
+ prefix : string ,
230
+ filterType ?: ObjType ,
231
+ ) => {
228
232
const t = useT ( )
229
- const selectedList = selectedObjs ( )
230
- const isSelected = selectedList . length > 0
231
- let objs = isSelected ? selectedList : objStore . objs
232
233
233
234
if ( filterType ) {
234
235
objs = objs . filter ( ( obj ) => obj . is_dir || obj . type === filterType )
235
236
}
236
237
238
+ if ( objs . length === 0 ) return ""
239
+
237
240
const folders = objs . filter ( ( o ) => o . is_dir ) . length
238
241
const files = objs . length - folders
239
-
240
- const vars = { folders : `${ folders } ` , files : `${ files } ` }
241
- const prefix = isSelected ? "selected" : "count"
242
-
242
+ const vars = { folders : folders . toString ( ) , files : files . toString ( ) }
243
243
const key =
244
244
folders && files
245
245
? `${ prefix } `
@@ -250,3 +250,22 @@ export const countMsg = (filterType?: ObjType) => {
250
250
: ""
251
251
return key ? t ( `home.obj.count.${ key } ` , vars ) : ""
252
252
}
253
+
254
+ export const countMsg = ( filterType ?: ObjType ) =>
255
+ getCountStr ( objStore . objs , "count" , filterType )
256
+
257
+ export const selectedMsg = ( filterType ?: ObjType ) => {
258
+ const selectedList = selectedObjs ( )
259
+ const isSelected = selectedList . length > 0
260
+
261
+ return isSelected ? getCountStr ( selectedList , "selected" , filterType ) : ""
262
+ }
263
+
264
+ export const smartCountMsg = ( filterType ?: ObjType ) => {
265
+ const selectedList = selectedObjs ( )
266
+ const isSelected = selectedList . length > 0
267
+
268
+ return isSelected
269
+ ? getCountStr ( selectedList , "selected" , filterType )
270
+ : countMsg ( filterType )
271
+ }
0 commit comments