Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 14 additions & 29 deletions src/components/Community/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { type FC, useEffect, useState, useMemo } from "react";

Check warning on line 1 in src/components/Community/index.tsx

View workflow job for this annotation

GitHub Actions / lint

'useState' is defined but never used

Check warning on line 1 in src/components/Community/index.tsx

View workflow job for this annotation

GitHub Actions / lint

'useEffect' is defined but never used

Check warning on line 1 in src/components/Community/index.tsx

View workflow job for this annotation

GitHub Actions / lint

'React' is defined but never used
import SlotCounter from "react-slot-counter";
import "./LandingCommunity.css";
import { useCommunityStatsContext } from "@site/src/lib/statsProvider";
Expand All @@ -17,8 +17,6 @@
githubContributorsCount,
githubForksCount,
githubReposCount,
loading,
error,
} = useCommunityStatsContext();

const generateList = useMemo(
Expand Down Expand Up @@ -84,19 +82,14 @@
</span>
.
</h2>
{error && (
<div className="landing-community__error">
<small>⚠️ Stats may be cached or incomplete</small>
</div>
)}
</div>

<div className="landing-community__content">
<div className="landing-community__stats">
{generateList.map((item, index) => (
<div
key={index}
className={`landing-community__stat-item ${item.href ? "clickable" : ""} ${loading ? "loading" : ""}`}
className={`landing-community__stat-item ${item.href ? "clickable" : ""}`}
onClick={() => handleCardClick(item.href)}
role={item.href ? "button" : "presentation"}
tabIndex={item.href ? 0 : -1}
Expand All @@ -109,27 +102,19 @@
title={item.href ? `Click to visit ${item.label}` : item.label}
>
<div className="landing-community__stat-value">
{loading ? (
<div className="landing-community__loading">
<span className="loading-spinner">⏳</span>
</div>
) : (
<span>
<SlotCounter
value={item.stat}
duration={2}
animateOnVisible={{
triggerOnce: true,
rootMargin: "0px 0px -100px 0px",
}}
numberSlotClassName="slot-counter-number"
separatorClassName="slot-counter-separator"
/>
{item.href && (
<span className="external-link-icon">↗</span>
)}
</span>
)}
<span>
<SlotCounter
value={item.stat}
duration={2}
animateOnVisible={{
triggerOnce: true,
rootMargin: "0px 0px -100px 0px",
}}
numberSlotClassName="slot-counter-number"
separatorClassName="slot-counter-separator"
/>
{item.href && <span className="external-link-icon">↗</span>}
</span>
</div>
<div className="landing-community__stat-description">
{item.description}
Expand Down
34 changes: 22 additions & 12 deletions src/lib/statsProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/** @jsxImportSource react */
import React, {
createContext,
useCallback,
useContext,
useEffect,
useMemo,
useState,
ReactNode,
type ReactNode,
} from "react";
import { githubService, type GitHubOrgStats } from "../services/githubService";
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
Expand Down Expand Up @@ -166,12 +165,12 @@ export function CommunityStatsProvider({
} = useDocusaurusContext();
const token = customFields?.gitToken || "";

const [loading, setLoading] = useState(true);
const [loading, setLoading] = useState(false); // Start with false to avoid hourglass
const [error, setError] = useState<string | null>(null);
const [githubStarCount, setGithubStarCount] = useState(0);
const [githubContributorsCount, setGithubContributorsCount] = useState(0);
const [githubForksCount, setGithubForksCount] = useState(0);
const [githubReposCount, setGithubReposCount] = useState(0);
const [githubStarCount, setGithubStarCount] = useState(984); // Placeholder value - updated to match production
const [githubContributorsCount, setGithubContributorsCount] = useState(467); // Placeholder value - updated to match production
const [githubForksCount, setGithubForksCount] = useState(1107); // Placeholder value - updated to match production
const [githubReposCount, setGithubReposCount] = useState(10); // Placeholder value - updated to match production
const [githubDiscussionsCount, setGithubDiscussionsCount] = useState(0);
const [lastUpdated, setLastUpdated] = useState<Date | null>(null);

Expand Down Expand Up @@ -412,17 +411,28 @@ export function CommunityStatsProvider({

const fetchAllStats = useCallback(
async (signal: AbortSignal) => {
setLoading(true);
setError(null);

// Check cache first
// Check cache first and load it immediately without showing loading state
const now = Date.now();
if (cache.data && now - cache.timestamp < CACHE_DURATION) {
const isCacheValid = cache.data && now - cache.timestamp < CACHE_DURATION;

if (isCacheValid) {
// Use cached data immediately
setAllContributors(cache.data.contributors);
setLoading(false);
return;
}

// If cache is expired or empty, show cached data anyway but fetch fresh data
// This provides immediate content while updating in the background
if (cache.data) {
setAllContributors(cache.data.contributors);
setLoading(false); // Don't show loading state for background refresh
} else {
setLoading(true); // Only show loading on first load
}

setError(null);

if (!token) {
setError(
"GitHub token not found. Please set customFields.gitToken in docusaurus.config.js.",
Expand Down
Loading