@@ -17,22 +17,68 @@ import {
1717 Group ,
1818 Grid ,
1919} from "@mantine/core" ;
20- import { IconBrandReact , IconBrandSolidjs , IconBrandSvelte , IconBrandVue , IconSparkles } from "@tabler/icons-react" ;
21- import { useMemo , useState } from "react" ;
20+ import {
21+ IconBrandReact ,
22+ IconBrandSolidjs ,
23+ IconBrandSvelte ,
24+ IconBrandVue ,
25+ IconSparkles ,
26+ IconStar ,
27+ IconDownload ,
28+ } from "@tabler/icons-react" ;
29+ import { useMemo , useState , useEffect } from "react" ;
2230
2331import { MainContentDiffAdvance , MainContentDiffConfig , MainContentDiffExample } from "../../components/MainContent" ;
2432
2533import type { DiffFile } from "@git-diff-view/react" ;
2634
35+ interface StatsData {
36+ stars : number ;
37+ downloads : number ;
38+ loading : boolean ;
39+ }
40+
41+ const formatNumber = ( num : number ) : string => {
42+ if ( num >= 1000000 ) return ( num / 1000000 ) . toFixed ( 1 ) + "M" ;
43+ if ( num >= 1000 ) return ( num / 1000 ) . toFixed ( 1 ) + "K" ;
44+ return num . toString ( ) ;
45+ } ;
46+
2747export const MainContent = ( ) => {
2848 const theme = useMantineTheme ( ) ;
2949
3050 const [ d , setD ] = useState < DiffFile > ( ) ;
51+ const [ stats , setStats ] = useState < StatsData > ( { stars : 0 , downloads : 0 , loading : true } ) ;
3152
3253 const { colorScheme } = useMantineColorScheme ( ) ;
3354
3455 const color = useMemo ( ( ) => alpha ( getThemeColor ( "yellow" , theme ) , 0.5 ) , [ theme ] ) ;
3556
57+ useEffect ( ( ) => {
58+ const fetchStats = async ( ) => {
59+ try {
60+ // Fetch GitHub stars
61+ const githubRes = await fetch ( "https://api.github.com/repos/MrWangJustToDo/git-diff-view" ) ;
62+ const githubData = await githubRes . json ( ) ;
63+
64+ // Fetch NPM downloads (last month)
65+ const npmRes = await fetch ( "https://api.npmjs.org/downloads/point/last-month/@git-diff-view/core" ) ;
66+ const npmData = await npmRes . json ( ) ;
67+
68+ setStats ( {
69+ stars : githubData . stargazers_count || 0 ,
70+ downloads : npmData . downloads || 0 ,
71+ loading : false ,
72+ } ) ;
73+ } catch ( error ) {
74+ console . error ( "Failed to fetch stats:" , error ) ;
75+ setStats ( { stars : 0 , downloads : 0 , loading : false } ) ;
76+ }
77+ } ;
78+
79+ fetchStats ( ) ;
80+ } , [ ] ) ;
81+
3682 return (
3783 < Box className = "min-h-screen" >
3884 < Container size = "xl" >
@@ -43,15 +89,27 @@ export const MainContent = () => {
4389 < div className = "absolute -inset-8 rounded-full bg-gradient-to-r from-blue-500/20 via-purple-500/20 to-pink-500/20 blur-3xl" />
4490 ) }
4591 < div className = "relative" >
46- < Badge
47- size = "lg"
48- variant = "gradient"
49- gradient = { { from : "blue" , to : "cyan" , deg : 90 } }
50- leftSection = { < IconSparkles size = { 16 } /> }
51- className = "mb-4"
52- >
53- Open Source
54- </ Badge >
92+ < Group justify = "center" gap = "xs" className = "mb-4" >
93+ < Badge
94+ size = "lg"
95+ variant = "gradient"
96+ gradient = { { from : "blue" , to : "cyan" , deg : 90 } }
97+ leftSection = { < IconSparkles size = { 16 } /> }
98+ >
99+ Open Source
100+ </ Badge >
101+ < Badge
102+ size = "lg"
103+ variant = "light"
104+ color = "yellow"
105+ leftSection = { < IconStar size = { 16 } fill = "currentColor" /> }
106+ >
107+ { stats . loading ? "..." : formatNumber ( stats . stars ) }
108+ </ Badge >
109+ < Badge size = "lg" variant = "light" color = "blue" leftSection = { < IconDownload size = { 16 } /> } >
110+ { stats . loading ? "..." : formatNumber ( stats . downloads ) }
111+ </ Badge >
112+ </ Group >
55113
56114 < Title
57115 order = { 1 }
@@ -114,6 +172,8 @@ export const MainContent = () => {
114172 Feature-rich diff viewer with GitHub-style UI, easy to integrate and highly customizable.
115173 </ Highlight >
116174 </ Box >
175+
176+ < Space h = "xl" />
117177 </ Box >
118178
119179 < Divider my = "xl" className = "opacity-30" />
@@ -169,7 +229,7 @@ export const MainContent = () => {
169229 { /* Right Side - Diff Preview */ }
170230 < Grid . Col span = { { base : 12 , md : 8 } } >
171231 < Box
172- className = "sticky top-4 h-[calc(100vh-120px)] transform-gpu overflow-hidden rounded-xl border-2 border-solid shadow-2xl transition-all"
232+ className = "sticky top-4 h-[calc(100vh-120px)] transform-gpu overflow-hidden rounded-xl border-2 border-solid transition-all"
173233 style = { {
174234 borderColor : colorScheme === "light" ? "var(--mantine-color-gray-2)" : "var(--mantine-color-dark-4)" ,
175235 backgroundColor : colorScheme === "light" ? "white" : "var(--mantine-color-dark-7)" ,
0 commit comments