File tree Expand file tree Collapse file tree 2 files changed +33
-9
lines changed
Expand file tree Collapse file tree 2 files changed +33
-9
lines changed Original file line number Diff line number Diff line change 11import { IconRefresh } from "@tabler/icons-react"
22
3+ import { queryClient } from "@/lib/clients"
34import { Button } from "@/components/ui/button"
45import { Spinner } from "@/components/ui/spinner"
56
7+ import { FETCH_LIST_ITEMS_QUERY_KEY } from "../../hooks"
68import { useKeys } from "../../hooks/use-keys"
79import { AddKeyModal } from "../add-key-modal"
8- import { DisplayDbSize } from "./db-size"
10+ import { DisplayDbSize , FETCH_DB_SIZE_QUERY_KEY } from "./db-size"
911import { Empty } from "./empty"
1012import { InfiniteScroll } from "./infinite-scroll"
1113import { KeysList } from "./keys-list"
@@ -23,7 +25,18 @@ export function Sidebar() {
2325 < div className = "flex h-10 items-center justify-between pl-1" >
2426 < DisplayDbSize />
2527 < 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+ >
2740 < Spinner isLoading = { query . isFetching } >
2841 < IconRefresh size = { 16 } />
2942 </ Spinner >
Original file line number Diff line number Diff line change @@ -24,15 +24,26 @@ const units = {
2424 second : 1000 ,
2525} as const
2626
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.
3028export function formatTime ( seconds : number ) {
29+ let milliseconds = seconds * 1000
30+ const parts = [ ]
31+
3132 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
3540 }
3641 }
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 ( " " )
3849}
You can’t perform that action at this time.
0 commit comments