@@ -12,13 +12,16 @@ const formatStarCount = (count: number) => {
12
12
if ( count >= 1000000 ) {
13
13
return ( count / 1000000 ) . toFixed ( 1 ) . replace ( / \. 0 $ / , '' ) + 'M'
14
14
} else if ( count >= 1000 ) {
15
- return ( count / 1000 ) . toFixed ( 1 ) . replace ( / \. 0 $ / , '' ) + 'k'
15
+ const rounded = Math . round ( count / 100 ) / 10 // Round to the nearest decimal
16
+ return rounded . toFixed ( 1 ) . replace ( / \. 0 $ / , '' ) + 'k'
16
17
}
17
- return count
18
+ return count . toString ( )
18
19
}
19
20
20
- const GitHubStarCount = ( { className } : { className ?: string } ) => {
21
- const [ starCount , setStarCount ] = useState ( 1100 )
21
+ const DEFAULT_STAR_COUNT = 1150
22
+
23
+ const GitHubStarCount = ( { className } : { className : string } ) => {
24
+ const [ starCount , setStarCount ] = useState ( DEFAULT_STAR_COUNT )
22
25
23
26
useEffect ( ( ) => {
24
27
const fetchStarCount = async ( ) => {
@@ -27,11 +30,12 @@ const GitHubStarCount = ({ className }: { className?: string }) => {
27
30
const cachedTimestamp = localStorage . getItem ( STAR_COUNT_TIMESTAMP_KEY )
28
31
const currentTime = new Date ( ) . getTime ( )
29
32
30
- // Check if cached data exists and is still valid
31
33
if (
32
34
cachedStarCount &&
33
35
cachedTimestamp &&
34
- currentTime - parseInt ( cachedTimestamp ) < CACHE_DURATION
36
+ currentTime - parseInt ( cachedTimestamp ) < CACHE_DURATION &&
37
+ // Ensure cached value is at least the new default value
38
+ parseInt ( cachedStarCount ) >= DEFAULT_STAR_COUNT
35
39
) {
36
40
setStarCount ( JSON . parse ( cachedStarCount ) )
37
41
} else {
0 commit comments