Skip to content

Commit a760b67

Browse files
authored
Merge pull request recodehive#943 from rahulrr-coder/fix/loading-animation
[Fix] Loading animation
2 parents 3f6ad06 + f929347 commit a760b67

File tree

2 files changed

+36
-41
lines changed

2 files changed

+36
-41
lines changed

src/components/Community/index.tsx

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ export const LandingCommunity: FC<Props> = ({ className }) => {
1717
githubContributorsCount,
1818
githubForksCount,
1919
githubReposCount,
20-
loading,
21-
error,
2220
} = useCommunityStatsContext();
2321

2422
const generateList = useMemo(
@@ -84,19 +82,14 @@ export const LandingCommunity: FC<Props> = ({ className }) => {
8482
</span>
8583
.
8684
</h2>
87-
{error && (
88-
<div className="landing-community__error">
89-
<small>⚠️ Stats may be cached or incomplete</small>
90-
</div>
91-
)}
9285
</div>
9386

9487
<div className="landing-community__content">
9588
<div className="landing-community__stats">
9689
{generateList.map((item, index) => (
9790
<div
9891
key={index}
99-
className={`landing-community__stat-item ${item.href ? "clickable" : ""} ${loading ? "loading" : ""}`}
92+
className={`landing-community__stat-item ${item.href ? "clickable" : ""}`}
10093
onClick={() => handleCardClick(item.href)}
10194
role={item.href ? "button" : "presentation"}
10295
tabIndex={item.href ? 0 : -1}
@@ -109,27 +102,19 @@ export const LandingCommunity: FC<Props> = ({ className }) => {
109102
title={item.href ? `Click to visit ${item.label}` : item.label}
110103
>
111104
<div className="landing-community__stat-value">
112-
{loading ? (
113-
<div className="landing-community__loading">
114-
<span className="loading-spinner"></span>
115-
</div>
116-
) : (
117-
<span>
118-
<SlotCounter
119-
value={item.stat}
120-
duration={2}
121-
animateOnVisible={{
122-
triggerOnce: true,
123-
rootMargin: "0px 0px -100px 0px",
124-
}}
125-
numberSlotClassName="slot-counter-number"
126-
separatorClassName="slot-counter-separator"
127-
/>
128-
{item.href && (
129-
<span className="external-link-icon"></span>
130-
)}
131-
</span>
132-
)}
105+
<span>
106+
<SlotCounter
107+
value={item.stat}
108+
duration={2}
109+
animateOnVisible={{
110+
triggerOnce: true,
111+
rootMargin: "0px 0px -100px 0px",
112+
}}
113+
numberSlotClassName="slot-counter-number"
114+
separatorClassName="slot-counter-separator"
115+
/>
116+
{item.href && <span className="external-link-icon"></span>}
117+
</span>
133118
</div>
134119
<div className="landing-community__stat-description">
135120
{item.description}

src/lib/statsProvider.tsx

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
/** @jsxImportSource react */
21
import React, {
32
createContext,
43
useCallback,
54
useContext,
65
useEffect,
76
useMemo,
87
useState,
9-
ReactNode,
8+
type ReactNode,
109
} from "react";
1110
import { githubService, type GitHubOrgStats } from "../services/githubService";
1211
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
@@ -166,12 +165,12 @@ export function CommunityStatsProvider({
166165
} = useDocusaurusContext();
167166
const token = customFields?.gitToken || "";
168167

169-
const [loading, setLoading] = useState(true);
168+
const [loading, setLoading] = useState(false); // Start with false to avoid hourglass
170169
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
175174
const [githubDiscussionsCount, setGithubDiscussionsCount] = useState(0);
176175
const [lastUpdated, setLastUpdated] = useState<Date | null>(null);
177176

@@ -412,17 +411,28 @@ export function CommunityStatsProvider({
412411

413412
const fetchAllStats = useCallback(
414413
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
419415
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
421420
setAllContributors(cache.data.contributors);
422421
setLoading(false);
423422
return;
424423
}
425424

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+
426436
if (!token) {
427437
setError(
428438
"GitHub token not found. Please set customFields.gitToken in docusaurus.config.js.",

0 commit comments

Comments
 (0)