File tree 2 files changed +33
-9
lines changed
2 files changed +33
-9
lines changed Original file line number Diff line number Diff line change 1
1
import { IconRefresh } from "@tabler/icons-react"
2
2
3
+ import { queryClient } from "@/lib/clients"
3
4
import { Button } from "@/components/ui/button"
4
5
import { Spinner } from "@/components/ui/spinner"
5
6
7
+ import { FETCH_LIST_ITEMS_QUERY_KEY } from "../../hooks"
6
8
import { useKeys } from "../../hooks/use-keys"
7
9
import { AddKeyModal } from "../add-key-modal"
8
- import { DisplayDbSize } from "./db-size"
10
+ import { DisplayDbSize , FETCH_DB_SIZE_QUERY_KEY } from "./db-size"
9
11
import { Empty } from "./empty"
10
12
import { InfiniteScroll } from "./infinite-scroll"
11
13
import { KeysList } from "./keys-list"
@@ -23,7 +25,18 @@ export function Sidebar() {
23
25
< div className = "flex h-10 items-center justify-between pl-1" >
24
26
< DisplayDbSize />
25
27
< div className = "flex gap-1" >
26
- < Button className = "h-7 w-7 px-0" onClick = { refetch } >
28
+ < Button
29
+ className = "h-7 w-7 px-0"
30
+ onClick = { ( ) => {
31
+ refetch ( )
32
+ queryClient . invalidateQueries ( {
33
+ queryKey : [ FETCH_LIST_ITEMS_QUERY_KEY ] ,
34
+ } )
35
+ queryClient . invalidateQueries ( {
36
+ queryKey : [ FETCH_DB_SIZE_QUERY_KEY ] ,
37
+ } )
38
+ } }
39
+ >
27
40
< Spinner isLoading = { query . isFetching } >
28
41
< IconRefresh size = { 16 } />
29
42
</ Spinner >
Original file line number Diff line number Diff line change @@ -24,15 +24,26 @@ const units = {
24
24
second : 1000 ,
25
25
} as const
26
26
27
- // 130 -> 2 minutes
28
- // 7800 -> 2 hours
29
- /** 130 is "2 minutes", 5 is "5 seconds" */
27
+ // 2h 10m, 1d 2h, 1 year 2 months, 3 years 4 months etc.
30
28
export function formatTime ( seconds : number ) {
29
+ let milliseconds = seconds * 1000
30
+ const parts = [ ]
31
+
31
32
for ( const [ unit , value ] of Object . entries ( units ) ) {
32
- const interval = ( seconds * 1000 ) / value
33
- if ( interval >= 1 ) {
34
- return `${ Math . floor ( interval ) } ${ unit } ${ interval > 1 && unit !== "min" ? "s" : "" } `
33
+ if ( milliseconds >= value ) {
34
+ const amount = Math . floor ( milliseconds / value )
35
+ const plural = amount > 1 ? "s" : ""
36
+ const label =
37
+ unit === "month" ? ` month${ plural } ` : unit === "year" ? ` year${ plural } ` : unit [ 0 ]
38
+ parts . push ( `${ amount } ${ label } ` )
39
+ milliseconds %= value
35
40
}
36
41
}
37
- return "just now"
42
+
43
+ // If no parts (e.g., 0ms), default to "0s"
44
+ if ( parts . length === 0 ) {
45
+ parts . push ( "0s" )
46
+ }
47
+
48
+ return parts . slice ( 0 , 2 ) . join ( " " )
38
49
}
You can’t perform that action at this time.
0 commit comments