-
Notifications
You must be signed in to change notification settings - Fork 5
feat(website): add dynamic stats from npm and GitHub APIs #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Create useStats hook to fetch real-time version, downloads, and stars - Replace hardcoded values in App.tsx stats bar with dynamic data - Replace hardcoded version in Hero.tsx badge with dynamic data - Add 5-minute cache to reduce API calls - Fallback to default values if APIs fail
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📝 WalkthroughWalkthroughThe changes introduce a new Changes
Sequence DiagramsequenceDiagram
participant Component as App/Hero Component
participant Hook as useStats Hook
participant Cache as localStorage
participant NPM as npm API
participant GH as GitHub API
Component->>Hook: Invoke useStats()
Hook->>Cache: Check cached stats & TTL validity
alt Cache valid
Cache-->>Hook: Return cached stats
Hook-->>Component: Return stats (loading: false)
else Cache expired/missing
Hook->>NPM: Fetch version (registry/skillkit/latest)
Hook->>NPM: Fetch downloads (last-month)
Hook->>GH: Fetch stargazers_count (repos/rohitg00/skillkit)
par Concurrent requests
NPM-->>Hook: version data
NPM-->>Hook: downloads data
GH-->>Hook: stars data
end
Hook->>Cache: Update cache with new stats
Hook-->>Component: Return stats (loading: false)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@docs/skillkit/hooks/useStats.ts`:
- Around line 81-92: The checks for API values use truthiness and drop valid
zeroes; update the logic in useStats where npmResponse and githubResponse are
handled so you explicitly check for null/undefined rather than truthiness: when
npmResponse is fulfilled and ok, verify npmData.downloads != null (or typeof
npmData.downloads === 'number') before calling formatDownloads and assigning
downloads; likewise when githubResponse is fulfilled and ok, check
githubData.stargazers_count != null (or typeof githubData.stargazers_count ===
'number') before assigning stars; reference the variables/functions npmResponse,
npmData.downloads, formatDownloads, githubResponse, githubData.stargazers_count,
downloads, and stars to locate and change the conditionals.
🧹 Nitpick comments (1)
docs/skillkit/components/Hero.tsx (1)
3-65: Avoid duplicate stats fetches by liftinguseStatsto App and passing props.Both App and Hero invoke the hook, causing two concurrent API fetches on first load. Consider fetching once in App and passing the version into Hero.
♻️ Proposed refactor
-import { useStats } from '../hooks/useStats'; +interface HeroProps { + version: string; +} -export function Hero(): React.ReactElement { +export function Hero({ version }: HeroProps): React.ReactElement { const [copied, setCopied] = useState(false); const [visibleLines, setVisibleLines] = useState(0); const [typingIndex, setTypingIndex] = useState(0); const [currentText, setCurrentText] = useState(''); - const stats = useStats();- <span className="text-xs font-mono text-zinc-400">v{stats.version}</span> + <span className="text-xs font-mono text-zinc-400">v{version}</span>- <Hero /> + <Hero version={stats.version} />Also applies to: 129-132
- Fix duplicate API calls: remove useStats from Hero, pass version as prop from App - Fix falsy checks: use typeof checks for downloads and stargazers_count to correctly handle zero values instead of showing defaults
Summary
useStatshook to fetch real-time version, downloads, and stars from npm and GitHub APIsChanges
docs/skillkit/hooks/useStats.ts- Custom React hook for fetching statsdocs/skillkit/App.tsx- Use dynamic stats in stats bardocs/skillkit/components/Hero.tsx- Use dynamic version in badgeTest plan
Summary by CodeRabbit
Release Notes