Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

fixed duplicate StatsModal bug

Steven Teyc31a79108e67
diff --git a/components/home/globe.tsx b/components/home/globe.tsx
index 61d321033b..6a804f3c33 100644
--- a/components/home/globe.tsx
+++ b/components/home/globe.tsx
@@ -1,4 +1,7 @@
-import { useEffect, useRef, useState } from "react";
+import { useCallback, useEffect, useRef, useState } from "react";
+import Link from "next/link";
+import { useRouter } from "next/router";
+import { useStatsModal } from "@/components/stats/stats-modal";
import createGlobe from "cobe";
import { useSpring } from "react-spring";
import useSWR from "swr";
@@ -12,6 +15,10 @@ interface MarkerProps {
}
export default function Globe() {
+ const router = useRouter();
+ const { key: stats } = router.query;
+ const { setShowStatsModal } = useStatsModal();
+
const { data: markers } = useSWR<MarkerProps[]>(
"/api/edge/coordinates",
fetcher
@@ -76,7 +83,7 @@ export default function Globe() {
initial={{ scale: 0 }}
animate={{ scale: 1 }}
exit={{ scale: 0 }}
- className="group absolute left-0 right-0 mx-auto z-10 max-w-sm px-5 py-7 rounded-md bg-white border border-gray-200 shadow-md"
+ className="group absolute left-0 right-0 mx-auto z-10 max-w-sm px-5 py-7 rounded-md bg-white border border-gray-200 shadow-md bg-opacity-90 backdrop-blur-md"
>
<button
className="visible sm:invisible group-hover:visible absolute top-0 right-0 p-1 m-3 rounded-full float-right group hover:bg-gray-100 focus:outline-none active:scale-75 transition-all duration-75"
@@ -98,6 +105,16 @@ export default function Globe() {
</a>{" "}
in real time.
</p>
+ <Link
+ href={{ pathname: "/", query: { key: "github" } }}
+ as="/stats/github"
+ shallow
+ scroll={false}
+ >
+ <a className="rounded-full px-4 py-1.5 bg-black text-white hover:bg-white hover:text-black text-sm border border-black mx-auto mt-3 block max-w-fit">
+ View all stats
+ </a>
+ </Link>
</motion.div>
)}
</AnimatePresence>
diff --git a/components/home/link-card.tsx b/components/home/link-card.tsx
index d7318a25c1..c23211a02c 100644
--- a/components/home/link-card.tsx
+++ b/components/home/link-card.tsx
@@ -2,13 +2,11 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import BlurImage from "@/components/shared/blur-image";
import CopyButton from "@/components/shared/copy-button";
import { Chart, LoadingDots } from "@/components/shared/icons";
-import { useRouter } from "next/router";
import useSWR from "swr";
import { fetcher, nFormatter, linkConstructor } from "@/lib/utils";
import Link from "next/link";
import { motion, useMotionValue, useAnimation } from "framer-motion";
import { FRAMER_MOTION_LIST_ITEM_VARIANTS } from "@/lib/constants";
-import { useStatsModal } from "@/components/stats/stats-modal";
import { SimpleLinkProps } from "@/lib/types";
import toast from "react-hot-toast";
import { useDebouncedCallback } from "use-debounce";
@@ -31,29 +29,6 @@ export default function LinkCard({
fetcher
);
- const router = useRouter();
- const { key: stats } = router.query;
- const { setShowStatsModal, StatsModal } = useStatsModal();
-
- const onKeyDown = useCallback((e: KeyboardEvent) => {
- if (e.key === "Escape") {
- setShowStatsModal(false);
- }
- }, []);
-
- useEffect(() => {
- if (stats) {
- setShowStatsModal(true);
- } else {
- setShowStatsModal(false);
- }
- }, [stats]);
-
- useEffect(() => {
- document.addEventListener("keydown", onKeyDown);
- return () => document.removeEventListener("keydown", onKeyDown);
- }, [onKeyDown]);
-
const cardElem = useRef(null);
const x = useMotionValue(0);
@@ -135,7 +110,6 @@ export default function LinkCard({
whileTap={{ scale: 1.05 }}
className="cursor-grab active:cursor-grabbing flex items-center border border-gray-200 hover:border-black bg-white p-3 max-w-md rounded-md transition-[border-color]"
>
- <StatsModal />
<BlurImage
src={`https://logo.clearbit.com/${urlHostname}`}
alt={urlHostname}
diff --git a/components/stats/stats-modal.tsx b/components/stats/stats-modal.tsx
index 367029201a..05d94b496f 100644
--- a/components/stats/stats-modal.tsx
+++ b/components/stats/stats-modal.tsx
@@ -40,8 +40,7 @@ function StatsModalHelper({
className="sticky top-4 z-20 p-3 m-4 rounded-full float-right group hover:bg-gray-100 focus:outline-none active:scale-75 transition-all duration-75"
autoFocus={false}
onClick={() => {
- setShowStatsModal(false);
- router.push("/");
+ router.push("/", undefined, { scroll: false });
}}
>
<X className="w-6 h-6" />
diff --git a/pages/index.tsx b/pages/index.tsx
index 32cd66b3f7..18042d8332 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -1,7 +1,9 @@
import HomeLayout from "@/components/layout/home";
-import { useState } from "react";
+import { useCallback, useEffect, useState } from "react";
import Link from "next/link";
+import { useRouter } from "next/router";
import useLocalStorage from "@/lib/hooks/use-local-storage";
+import { useStatsModal } from "@/components/stats/stats-modal";
import LinkCard from "@/components/home/link-card";
import PlaceholderCard from "@/components/home/placeholder-card";
import {
@@ -9,6 +11,7 @@ import {
LoadingDots,
Twitter,
CheckCircleFill,
+ Chart,
} from "@/components/shared/icons";
import { motion } from "framer-motion";
import { SimpleLinkProps } from "@/lib/types";
@@ -19,8 +22,32 @@ import { Toaster } from "react-hot-toast";
import CountingNumbers from "@/components/shared/counting-numbers";
export default function Home() {
+ const router = useRouter();
+ const { key: stats } = router.query;
+ const { setShowStatsModal, StatsModal } = useStatsModal();
+
+ const onKeyDown = useCallback((e: KeyboardEvent) => {
+ if (e.key === "Escape") {
+ router.push("/", undefined, { scroll: false });
+ }
+ }, []);
+
+ useEffect(() => {
+ if (stats) {
+ setShowStatsModal(true);
+ } else {
+ setShowStatsModal(false);
+ }
+ }, [stats]);
+
+ useEffect(() => {
+ document.addEventListener("keydown", onKeyDown);
+ return () => document.removeEventListener("keydown", onKeyDown);
+ }, [onKeyDown]);
+
return (
<HomeLayout>
+ <StatsModal />
<Hero />
<Demo />
<Globe />
@@ -54,8 +81,8 @@ const Hero = () => {
</span>
</h1>
<p className="text-gray-600 text-xl sm:text-2xl mt-5">
- An open-source link shortener with built-in analytics and free custom
- domains.
+ Dub is an open-source link shortener with built-in analytics and free
+ custom domains.
</p>
<div className="mt-10 flex space-x-4 max-w-fit mx-auto">
@@ -190,10 +217,37 @@ const Demo = () => {
const Features = () => {
return (
- <div className="h-96 bg-blue-600">
- {/* <h2 className="text-3xl font-display font-semibold text-black mt-10">
- Features
- </h2> */}
+ <div className="bg-gray-50">
+ <MaxWidthWrapper className="py-20 text-center">
+ <div className="max-w-sm sm:max-w-md mx-auto my-10">
+ <h2 className="text-4xl sm:text-5xl leading-tight sm:leading-tight font-display font-extrabold text-black">
+ Fast.{" "}
+ <span className="text-transparent bg-clip-text bg-gradient-to-r from-purple-600 to-pink-600">
+ Powerful.
+ </span>{" "}
+ Open source.
+ </h2>
+ <p className="text-gray-600 sm:text-lg mt-5">
+ With Dub, you get the best of both worlds: a powerful link shortener
+ with built-in analytics, and the freedom to host it yourself.
+ </p>
+ </div>
+ <div className="grid grid-cols-1 sm:grid-cols-2 gap-10">
+ <div className="flex flex-col items-center">
+ <div className="flex items-center justify-center w-20 h-20 rounded-full bg-gradient-to-r from-purple-600 to-pink-600">
+ <Chart />
+ </div>
+ <h3 className="text-2xl font-display font-bold text-black mt-5">
+ Powerful analytics
+ </h3>
+
+ <p className="text-gray-600 text-center mt-3">
+ Dub provides powerful analytics for your links, including
+ geolocation, device, and browser information.
+ </p>
+ </div>
+ </div>
+ </MaxWidthWrapper>
</div>
);
};
@@ -241,15 +295,15 @@ const pricingItems = [
const Pricing = () => {
return (
<MaxWidthWrapper className="my-20 text-center">
- <div className="max-w-md mx-auto my-10">
- <h2 className="text-5xl font-display font-extrabold text-black">
+ <div className="max-w-sm sm:max-w-md mx-auto my-10">
+ <h2 className="text-4xl sm:text-5xl font-display font-extrabold text-black">
Simple,{" "}
<span className="text-transparent bg-clip-text bg-gradient-to-r from-blue-600 to-cyan-600">
affordable
</span>{" "}
pricing
</h2>
- <p className="text-gray-600 text-lg mt-5">
+ <p className="text-gray-600 sm:text-lg mt-5">
Start for free, no credit card required. Upgrade anytime.
</p>
</div>
@@ -257,6 +311,7 @@ const Pricing = () => {
{pricingItems.map(
({ plan, tagline, isPopular, price, features, cta, ctaLink }) => (
<div
+ key={plan}
className={`relative bg-white rounded-2xl ${
isPopular
? "border-2 border-blue-600 shadow-blue-200"