1
1
import { useState , useEffect } from 'react' ;
2
- import { fetchGitHubRepoStats , extractGitHubInfo , formatNumber , type GitHubRepoStats } from '@/lib/utils' ;
2
+ import { fetchGitHubRepoStats , extractGitHubInfo , formatNumber , formatRelativeTime , type GitHubRepoStats } from '@/lib/utils' ;
3
3
4
4
interface GitHubStatsProps {
5
5
url : string ;
@@ -81,32 +81,59 @@ export function GitHubStats({ url, authorName, authorLink }: GitHubStatsProps) {
81
81
</ div >
82
82
) }
83
83
84
- { /* Stats (stars/forks) - only show if not fetch failed */ }
84
+ { /* Stats (stars/forks/last updated ) - only show if not fetch failed */ }
85
85
{ ! fetchFailed && (
86
- < div className = "flex items-center space-x-3 text-sm text-muted-foreground animate-fade-in" onClick = { e => e . stopPropagation ( ) } >
87
- { loading ? (
88
- < div className = "flex items-center space-x-3" >
89
- < div className = "w-16 h-5 bg-muted animate-pulse rounded" > </ div >
90
- < div className = "w-16 h-5 bg-muted animate-pulse rounded" > </ div >
91
- </ div >
92
- ) : (
93
- < >
94
- < div className = "flex items-center space-x-1" title = { `${ stats ?. stars } stars` } >
95
- < svg
96
- xmlns = "http://www.w3.org/2000/svg"
97
- viewBox = "0 0 24 24"
98
- fill = "none"
99
- stroke = "currentColor"
100
- strokeWidth = "2"
101
- strokeLinecap = "round"
102
- strokeLinejoin = "round"
103
- className = "h-4 w-4"
104
- >
105
- < polygon points = "12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2" > </ polygon >
106
- </ svg >
107
- < span > { formatNumber ( stats ?. stars || 0 ) } </ span >
86
+ < div className = "flex flex-col items-end space-y-1" >
87
+ < div className = "flex items-center space-x-3 text-sm text-muted-foreground animate-fade-in" onClick = { e => e . stopPropagation ( ) } >
88
+ { loading ? (
89
+ < div className = "flex items-center space-x-3" >
90
+ < div className = "w-16 h-5 bg-muted animate-pulse rounded" > </ div >
91
+ < div className = "w-16 h-5 bg-muted animate-pulse rounded" > </ div >
108
92
</ div >
109
- < div className = "flex items-center space-x-1" title = { `${ stats ?. forks } forks` } >
93
+ ) : (
94
+ < >
95
+ < div className = "flex items-center space-x-1" title = { `${ stats ?. stars } stars` } >
96
+ < svg
97
+ xmlns = "http://www.w3.org/2000/svg"
98
+ viewBox = "0 0 24 24"
99
+ fill = "none"
100
+ stroke = "currentColor"
101
+ strokeWidth = "2"
102
+ strokeLinecap = "round"
103
+ strokeLinejoin = "round"
104
+ className = "h-4 w-4"
105
+ >
106
+ < polygon points = "12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2" > </ polygon >
107
+ </ svg >
108
+ < span > { formatNumber ( stats ?. stars || 0 ) } </ span >
109
+ </ div >
110
+ < div className = "flex items-center space-x-1" title = { `${ stats ?. forks } forks` } >
111
+ < svg
112
+ xmlns = "http://www.w3.org/2000/svg"
113
+ viewBox = "0 0 24 24"
114
+ fill = "none"
115
+ stroke = "currentColor"
116
+ strokeWidth = "2"
117
+ strokeLinecap = "round"
118
+ strokeLinejoin = "round"
119
+ className = "h-4 w-4"
120
+ >
121
+ < path d = "M9 21v-6" > </ path >
122
+ < path d = "M15 15v6" > </ path >
123
+ < circle cx = "9" cy = "6" r = "3" > </ circle >
124
+ < circle cx = "15" cy = "18" r = "3" > </ circle >
125
+ < path d = "M12 9A6 6 0 0 0 6 15h6a6 6 0 0 0 6-6" > </ path >
126
+ </ svg >
127
+ < span > { formatNumber ( stats ?. forks || 0 ) } </ span >
128
+ </ div >
129
+ </ >
130
+ ) }
131
+ </ div >
132
+
133
+ { /* Last updated time */ }
134
+ { ! loading && stats ?. lastUpdated && (
135
+ < div className = "text-xs text-muted-foreground animate-fade-in" title = { `Last updated: ${ new Date ( stats . lastUpdated ) . toLocaleString ( ) } ` } >
136
+ < div className = "flex items-center space-x-1" >
110
137
< svg
111
138
xmlns = "http://www.w3.org/2000/svg"
112
139
viewBox = "0 0 24 24"
@@ -115,17 +142,14 @@ export function GitHubStats({ url, authorName, authorLink }: GitHubStatsProps) {
115
142
strokeWidth = "2"
116
143
strokeLinecap = "round"
117
144
strokeLinejoin = "round"
118
- className = "h-4 w-4 "
145
+ className = "h-3.5 w-3.5 "
119
146
>
120
- < path d = "M9 21v-6" > </ path >
121
- < path d = "M15 15v6" > </ path >
122
- < circle cx = "9" cy = "6" r = "3" > </ circle >
123
- < circle cx = "15" cy = "18" r = "3" > </ circle >
124
- < path d = "M12 9A6 6 0 0 0 6 15h6a6 6 0 0 0 6-6" > </ path >
147
+ < circle cx = "12" cy = "12" r = "10" > </ circle >
148
+ < polyline points = "12 6 12 12 16 14" > </ polyline >
125
149
</ svg >
126
- < span > { formatNumber ( stats ?. forks || 0 ) } </ span >
150
+ < span > Updated { formatRelativeTime ( stats . lastUpdated ) } </ span >
127
151
</ div >
128
- </ >
152
+ </ div >
129
153
) }
130
154
</ div >
131
155
) }
0 commit comments