Skip to content
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

also use dynamic count on landing page #1085

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion pcweb/components/docpage/navbar/buttons/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def github() -> rx.Component:
rx.flex(
get_icon(icon="github_navbar", class_name="shrink-0 !text-slate-9"),
rx.text(
GithubStarState.stars,
GithubStarState.stars_short,
class_name="font-small",
),
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",
Expand Down
9 changes: 6 additions & 3 deletions pcweb/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ async def fetch_count():
with contextlib.suppress(Exception):
global REFLEX_STAR_COUNT
data = httpx.get(GITHUB_API_URL).json()
count = int(data["stargazers_count"])
REFLEX_STAR_COUNT = round(count / 1000)
REFLEX_STAR_COUNT = int(data["stargazers_count"])
await asyncio.sleep(3600)
except asyncio.CancelledError:
pass
Expand All @@ -27,4 +26,8 @@ async def fetch_count():
class GithubStarState(rx.State):
@rx.var(cache=True, interval=60)
def stars(self) -> str:
return f"{REFLEX_STAR_COUNT}K"
return f"{REFLEX_STAR_COUNT}"

@rx.var(cache=True, interval=60)
def stars_short(self) -> str:
return f"{round(REFLEX_STAR_COUNT/1000)}K"
23 changes: 18 additions & 5 deletions pcweb/pages/index/views/stats.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import reflex as rx
from pcweb.components.icons import get_icon
from pcweb.constants import GITHUB_STARS
from pcweb.github import GithubStarState


def stat_card(stat: str, text: str, icon: str, class_name: str = "") -> rx.Component:
return rx.box(
Expand All @@ -10,15 +11,27 @@ def stat_card(stat: str, text: str, icon: str, class_name: str = "") -> rx.Compo
class_name="flex flex-row gap-2 items-center",
),
rx.text(stat, class_name="font-x-large text-slate-12"),
class_name="flex flex-col gap-2 w-full p-10 items-center lg:items-start" + " " + class_name,
class_name="flex flex-col gap-2 w-full p-10 items-center lg:items-start"
+ " "
+ class_name,
)


def stats_grid() -> rx.Component:
return rx.box(
stat_card(stat=f"{GITHUB_STARS:,}+", text="Stars", icon="star", class_name="lg:!border-l !border-slate-3"),
stat_card(stat="150+", text="Contributors", icon="fork"),
stat_card(stat="5,500+", text="Discord", icon="discord_navbar", class_name="lg:!border-r !border-slate-3"),
stat_card(
stat=f"{GithubStarState.stars:,}",
text="Stars",
icon="star",
class_name="lg:!border-l !border-slate-3",
),
stat_card(stat="150+", text="Contributors", icon="fork"),
stat_card(
stat="5,500+",
text="Discord",
icon="discord_navbar",
class_name="lg:!border-r !border-slate-3",
),
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",
)

Expand Down
Loading