Skip to content

Commit 751ab10

Browse files
authored
also use dynamic count on landing page (#1085)
1 parent 11a6ab4 commit 751ab10

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

pcweb/components/docpage/navbar/buttons/github.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def github() -> rx.Component:
99
rx.flex(
1010
get_icon(icon="github_navbar", class_name="shrink-0 !text-slate-9"),
1111
rx.text(
12-
GithubStarState.stars,
12+
GithubStarState.stars_short,
1313
class_name="font-small",
1414
),
1515
class_name="text-slate-9 flex-row gap-2 hover:bg-slate-3 flex justify-center rounded-[10px] border border-slate-5 bg-slate-1 transition-bg cursor-pointer shadow-large py-0.5 px-3 items-center h-8",

pcweb/github.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ async def fetch_count():
1717
with contextlib.suppress(Exception):
1818
global REFLEX_STAR_COUNT
1919
data = httpx.get(GITHUB_API_URL).json()
20-
count = int(data["stargazers_count"])
21-
REFLEX_STAR_COUNT = round(count / 1000)
20+
REFLEX_STAR_COUNT = int(data["stargazers_count"])
2221
await asyncio.sleep(3600)
2322
except asyncio.CancelledError:
2423
pass
@@ -27,4 +26,8 @@ async def fetch_count():
2726
class GithubStarState(rx.State):
2827
@rx.var(cache=True, interval=60)
2928
def stars(self) -> str:
30-
return f"{REFLEX_STAR_COUNT}K"
29+
return f"{REFLEX_STAR_COUNT}"
30+
31+
@rx.var(cache=True, interval=60)
32+
def stars_short(self) -> str:
33+
return f"{round(REFLEX_STAR_COUNT/1000)}K"

pcweb/pages/index/views/stats.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import reflex as rx
22
from pcweb.components.icons import get_icon
3-
from pcweb.constants import GITHUB_STARS
3+
from pcweb.github import GithubStarState
4+
45

56
def stat_card(stat: str, text: str, icon: str, class_name: str = "") -> rx.Component:
67
return rx.box(
@@ -10,15 +11,27 @@ def stat_card(stat: str, text: str, icon: str, class_name: str = "") -> rx.Compo
1011
class_name="flex flex-row gap-2 items-center",
1112
),
1213
rx.text(stat, class_name="font-x-large text-slate-12"),
13-
class_name="flex flex-col gap-2 w-full p-10 items-center lg:items-start" + " " + class_name,
14+
class_name="flex flex-col gap-2 w-full p-10 items-center lg:items-start"
15+
+ " "
16+
+ class_name,
1417
)
1518

1619

1720
def stats_grid() -> rx.Component:
1821
return rx.box(
19-
stat_card(stat=f"{GITHUB_STARS:,}+", text="Stars", icon="star", class_name="lg:!border-l !border-slate-3"),
20-
stat_card(stat="150+", text="Contributors", icon="fork"),
21-
stat_card(stat="5,500+", text="Discord", icon="discord_navbar", class_name="lg:!border-r !border-slate-3"),
22+
stat_card(
23+
stat=f"{GithubStarState.stars:,}",
24+
text="Stars",
25+
icon="star",
26+
class_name="lg:!border-l !border-slate-3",
27+
),
28+
stat_card(stat="150+", text="Contributors", icon="fork"),
29+
stat_card(
30+
stat="5,500+",
31+
text="Discord",
32+
icon="discord_navbar",
33+
class_name="lg:!border-r !border-slate-3",
34+
),
2235
class_name="grid grid-cols-1 lg:grid-cols-3 gap-0 grid-rows-1 w-full divide-slate-3 lg:divide-x !border-t-0 divide-y lg:divide-y-0",
2336
)
2437

0 commit comments

Comments
 (0)