Skip to content

Commit

Permalink
📦 NEW: add total roadmaps generated ticker
Browse files Browse the repository at this point in the history
  • Loading branch information
thatbeautifuldream committed Apr 28, 2024
1 parent a3cad37 commit 3a22ea8
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"dayjs": "^1.11.10",
"dotenv": "^16.4.5",
"embla-carousel-react": "^8.0.0",
"framer-motion": "^11.1.7",
"html-to-image": "^1.11.11",
"input-otp": "^1.2.0",
"lucide-react": "^0.358.0",
Expand Down
22 changes: 22 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/actions/roadmaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,8 @@ export const findSavedNodeDetails = async (
throw new Error("Failed to find saved node details");
}
};

export const getTotalRoadmapsGenerated = async () => {
const totalRoadmaps = await db.roadmap.count();
return totalRoadmaps;
};
2 changes: 0 additions & 2 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// import Confetti from "@/components/landing/roadmap-confetti";
import RoadmapHero from "@/components/landing/roadmap-hero";
import RoadmapFeatures from "@/components/landing/roadmap-features";
import RoadmapTestimonial from "@/components/testimonials/roadmap-testimonial";
Expand All @@ -9,7 +8,6 @@ import RoadmapFooter from "@/components/landing/roadmap-footer";
export default function Home() {
return (
<>
{/* <Confetti /> */}
<RoadmapHero />
<RoadmapFeatures />
<RoadmapTestimonial />
Expand Down
16 changes: 15 additions & 1 deletion src/components/landing/roadmap-hero.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import DotPattern from "@/components/ui/dot-pattern";
import { buttonVariants } from "@/components/ui/button";
import MarqueeDemo from "@/components/ui/marque-wrapper";
import { cn } from "@/lib/utils";
import { clerkClient } from "@clerk/nextjs";
Expand All @@ -8,6 +7,20 @@ import Image from "next/image";
import Link from "next/link";
import { Link as LinkWithViewTransitions } from "next-view-transitions";
import NeubrutalismButton from "@/components/ui/neobrutalism-button";
import TextTicker from "@/components/marketing/text-ticker";
import { getTotalRoadmapsGenerated } from "@/actions/roadmaps";

async function ToalUserTicker() {
const totalRoadmapCount = await getTotalRoadmapsGenerated();
return (
<div className="text-2xl font-semibold tabular-nums tracking-tight">
<div className="flex flex-row gap-2">
<TextTicker value={totalRoadmapCount} />
Roadmaps Generated!
</div>
</div>
);
}

async function UserAvatars() {
const users = await clerkClient.users.getUserList();
Expand Down Expand Up @@ -98,6 +111,7 @@ export default function RoadmapHero() {
))}
</div>
<UserAvatars />
<ToalUserTicker />
</div>
<div className="flex flex-col items-center gap-4 mb-6">
<p className="flex items-center text-sm">
Expand Down
40 changes: 40 additions & 0 deletions src/components/marketing/text-ticker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"use client";

import { useEffect, useRef } from "react";
import { useInView, useMotionValue, useSpring } from "framer-motion";

export default function TextTicker({
value,
direction = "up",
}: {
value: number;
direction?: "up" | "down";
}) {
const ref = useRef<HTMLSpanElement>(null);
const motionValue = useMotionValue(direction === "down" ? value : 0);
const springValue = useSpring(motionValue, {
damping: 100,
stiffness: 100,
});
const isInView = useInView(ref, { once: true, margin: "-100px" });

useEffect(() => {
if (isInView) {
motionValue.set(direction === "down" ? 0 : value);
}
}, [motionValue, isInView]);

useEffect(
() =>
springValue.on("change", (latest) => {
if (ref.current) {
ref.current.textContent = Intl.NumberFormat("en-US").format(
latest.toFixed(0),
);
}
}),
[springValue],
);

return <span ref={ref} />;
}

0 comments on commit 3a22ea8

Please sign in to comment.