|
1 | | -/** @jsxImportSource react */ |
2 | 1 | import React, { |
3 | 2 | createContext, |
4 | 3 | useCallback, |
5 | 4 | useContext, |
6 | 5 | useEffect, |
7 | 6 | useMemo, |
8 | 7 | useState, |
9 | | - ReactNode, |
| 8 | + type ReactNode, |
10 | 9 | } from "react"; |
11 | 10 | import { githubService, type GitHubOrgStats } from "../services/githubService"; |
12 | 11 | import useDocusaurusContext from "@docusaurus/useDocusaurusContext"; |
@@ -166,12 +165,12 @@ export function CommunityStatsProvider({ |
166 | 165 | } = useDocusaurusContext(); |
167 | 166 | const token = customFields?.gitToken || ""; |
168 | 167 |
|
169 | | - const [loading, setLoading] = useState(true); |
| 168 | + const [loading, setLoading] = useState(false); // Start with false to avoid hourglass |
170 | 169 | const [error, setError] = useState<string | null>(null); |
171 | | - const [githubStarCount, setGithubStarCount] = useState(0); |
172 | | - const [githubContributorsCount, setGithubContributorsCount] = useState(0); |
173 | | - const [githubForksCount, setGithubForksCount] = useState(0); |
174 | | - const [githubReposCount, setGithubReposCount] = useState(0); |
| 170 | + const [githubStarCount, setGithubStarCount] = useState(984); // Placeholder value - updated to match production |
| 171 | + const [githubContributorsCount, setGithubContributorsCount] = useState(467); // Placeholder value - updated to match production |
| 172 | + const [githubForksCount, setGithubForksCount] = useState(1107); // Placeholder value - updated to match production |
| 173 | + const [githubReposCount, setGithubReposCount] = useState(10); // Placeholder value - updated to match production |
175 | 174 | const [githubDiscussionsCount, setGithubDiscussionsCount] = useState(0); |
176 | 175 | const [lastUpdated, setLastUpdated] = useState<Date | null>(null); |
177 | 176 |
|
@@ -412,17 +411,28 @@ export function CommunityStatsProvider({ |
412 | 411 |
|
413 | 412 | const fetchAllStats = useCallback( |
414 | 413 | async (signal: AbortSignal) => { |
415 | | - setLoading(true); |
416 | | - setError(null); |
417 | | - |
418 | | - // Check cache first |
| 414 | + // Check cache first and load it immediately without showing loading state |
419 | 415 | const now = Date.now(); |
420 | | - if (cache.data && now - cache.timestamp < CACHE_DURATION) { |
| 416 | + const isCacheValid = cache.data && now - cache.timestamp < CACHE_DURATION; |
| 417 | + |
| 418 | + if (isCacheValid) { |
| 419 | + // Use cached data immediately |
421 | 420 | setAllContributors(cache.data.contributors); |
422 | 421 | setLoading(false); |
423 | 422 | return; |
424 | 423 | } |
425 | 424 |
|
| 425 | + // If cache is expired or empty, show cached data anyway but fetch fresh data |
| 426 | + // This provides immediate content while updating in the background |
| 427 | + if (cache.data) { |
| 428 | + setAllContributors(cache.data.contributors); |
| 429 | + setLoading(false); // Don't show loading state for background refresh |
| 430 | + } else { |
| 431 | + setLoading(true); // Only show loading on first load |
| 432 | + } |
| 433 | + |
| 434 | + setError(null); |
| 435 | + |
426 | 436 | if (!token) { |
427 | 437 | setError( |
428 | 438 | "GitHub token not found. Please set customFields.gitToken in docusaurus.config.js.", |
|
0 commit comments