Compare commits

...

7 commits

Author SHA1 Message Date
shadcn
1820cd8496 Merge branch 'main' into feat/stats
# Conflicts:
#	package.json
#	pnpm-lock.yaml
2022-12-22 20:30:51 +04:00
shadcn
46efd08c92 fix: update to latest canary 2022-12-06 10:40:50 +04:00
shadcn
71b27a0d9e chore: update to latest canary 2022-12-06 10:36:44 +04:00
shadcn
4567261e7f Merge branch 'main' into feat/stats
# Conflicts:
#	pnpm-lock.yaml
2022-12-06 10:33:24 +04:00
shadcn
b353447c52 chore: update to latest canary 2022-11-28 14:50:43 +04:00
shadcn
8a19e68dfd refactor: rename env var for planetscale db url 2022-11-27 21:21:23 +04:00
shadcn
c2de1aa372 feat: add the stats page 2022-11-27 20:46:06 +04:00
10 changed files with 326 additions and 11 deletions

View file

@ -17,6 +17,7 @@ GITHUB_ACCESS_TOKEN=
# Database (MySQL - PlanetScale)
# -----------------------------------------------------------------------------
DATABASE_URL="mysql://root:root@localhost:3306/taxonomy?schema=public"
PLANETSCALE_SERVERLESS_DATABASE_URL=
# -----------------------------------------------------------------------------
# Email (Postmark)

View file

@ -65,7 +65,10 @@ export default async function IndexPage() {
</div>
</section>
<hr className="border-slate-200" />
<section className="container grid justify-center gap-6 py-8 md:py-12 lg:py-24">
<section
id="features"
className="container grid justify-center gap-6 py-8 md:py-12 lg:py-24"
>
<div className="mx-auto flex flex-col gap-4 md:max-w-[52rem]">
<h2 className="text-3xl font-bold leading-[1.1] tracking-tighter sm:text-3xl md:text-6xl">
Features
@ -76,7 +79,7 @@ export default async function IndexPage() {
Next.js 13 app dir.
</p>
</div>
<div className="grid justify-center gap-4 sm:grid-cols-2 md:max-w-[56rem] md:grid-cols-3">
<div className="grid justify-center gap-4 sm:grid-cols-2 md:max-w-[60rem] md:grid-cols-3">
<div className="relative overflow-hidden rounded-lg border border-slate-200 bg-white p-2 shadow-2xl">
<div className="flex h-[180px] flex-col justify-between rounded-md bg-[#000000] p-6 text-slate-200">
<svg viewBox="0 0 24 24" className="h-12 w-12 fill-current">

View file

@ -4,7 +4,7 @@ import { Icons } from "@/components/icons"
export default function PricingPage() {
return (
<section className="container flex flex-col gap-6 py-8 md:max-w-[64rem] md:py-12 lg:py-24">
<section className="container flex flex-col gap-6 py-8 md:py-12 lg:py-24">
<div className="mx-auto flex w-full flex-col gap-4 md:max-w-[52rem]">
<h2 className="text-3xl font-bold leading-[1.1] tracking-tighter sm:text-3xl md:text-6xl">
Simple, transparent pricing
@ -13,7 +13,7 @@ export default function PricingPage() {
Unlock all features including unlimited posts for your blog.
</p>
</div>
<div className="grid w-full items-start gap-10 rounded-lg border border-slate-200 p-10 md:grid-cols-[1fr_200px]">
<div className="grid w-full items-start gap-10 md:max-w-[60rem] mx-auto rounded-lg border border-slate-200 p-10 md:grid-cols-[1fr_200px]">
<div className="grid gap-6">
<h3 className="text-xl font-bold sm:text-2xl">
What&apos;s included in the PRO plan

View file

@ -0,0 +1,89 @@
import { planetScale } from "@/lib/planetscale"
import { Stat } from "@/components/stat"
export const runtime = "experimental-edge"
export const revalidate = 60
async function getStats() {
const { rows } = await planetScale.execute(
"SELECT (SELECT count(id) FROM users) as users, (SELECT count(id) FROM posts) as posts, (SELECT count(id) FROM users WHERE stripe_subscription_id IS NOT NULL) as paid"
)
if (!rows?.length) {
return null
}
const [stats] = rows
// Row has type Record<string, any> | any[] no matter what's passed for as?.
// This is a temporary type guard.
// @see https://github.com/planetscale/database-js/issues/71.
if (!Array.isArray(stats)) {
return {
users: stats.users,
posts: stats.posts,
paid: stats.paid,
}
}
return null
}
export default async function StatsPage() {
const stats = await getStats()
return (
<section className="container flex flex-col gap-6 py-8 md:py-12 lg:py-24">
<div className="mx-auto flex w-full flex-col gap-4 md:max-w-[52rem]">
<h2 className="text-3xl font-bold leading-[1.1] tracking-tighter sm:text-3xl md:text-6xl">
Edge Runtime and PlanetScale
</h2>
<p className="leading-normal text-slate-700 sm:text-lg sm:leading-7">
This page is using the Edge Runtime with data fetched using
PlanetScale Serverless driver.
</p>
</div>
{stats && (
<div className="mx-auto grid md:grid-cols-3 md:max-w-[60rem] gap-4 w-full">
<Stat to={stats.users} text="Registered Users">
<svg className="w-[100px] h-[50px]" viewBox="0 0 100 50">
<path
d="M 0,49.974220545611345 C 1,49.39782978143856 3,48.279166261974524 5,47.092266724747404 C 7,45.905367187520284 8,44.77689718027033 10,44.039722859475745 C 12,43.30254853868116 13,44.4035292286622 15,43.406395120774484 C 17,42.409261012886766 18,39.50667673800428 20,39.05405232003717 C 22,38.601427902070064 23,41.3204657996938 25,41.14327303093893 C 27,40.96608026218406 28,40.08553363545408 30,38.1680884762628 C 32,36.25064331707153 33,31.631270797123182 35,31.556047234982554 C 37,31.480823672841925 38,37.44460608445381 40,37.79197066555967 C 42,38.139335246665524 43,34.852023380673145 45,33.29287014051185 C 47,31.73371690035056 48,32.25013422451495 50,29.99620446475321 C 52,27.74227470499147 53,23.698614423588413 55,22.023221341703156 C 57,20.3478282598179 58,22.71277059447314 60,21.619239055326922 C 62,20.525707516180702 63,17.473809687078493 65,16.555563645972065 C 67,15.637317604865636 68,19.089509738453057 70,17.02800884979478 C 72,14.966507961136504 73,9.005619982434723 75,6.248059202680686 C 77,3.490498422926649 78,0.4473451192676121 80,3.2402049510245945 C 82,6.033064782781577 83,19.21628237791182 85,20.212358361465597 C 87,21.208434345019374 88,10.554114470549631 90,8.22058486879348 C 92,5.88705526703733 94,8.479885255906572 95,8.544710352684845"
fill="none"
stroke-width="3px"
className="stroke-slate-900"
/>
</svg>
</Stat>
<Stat to={stats.paid} text="Paid Users">
<svg className="w-[100px] h-[50px]" viewBox="0 0 100 50">
<path
d="M 0,49.94765273880501 C 1,49.385097989476996 3,48.221275238783086 5,47.13487899216492 C 7,46.04848274554676 8,44.956321893609484 10,44.515671505714174 C 12,44.075021117818864 13,46.17688016754378 15,44.931627052688384 C 17,43.68637393783299 18,40.118877503844125 20,38.289405931437216 C 22,36.459934359030306 23,36.8406347605897 25,35.78426919065382 C 27,34.727903620717946 28,34.28600949541689 30,33.00757808175783 C 32,31.729146668098767 33,30.30486025149646 35,29.392112122358515 C 37,28.47936399322057 38,29.10753025329817 40,28.4438374360681 C 42,27.780144618838033 43,27.47796597839575 45,26.073648036208183 C 47,24.669330094020616 48,21.90541722307717 50,21.422247725130255 C 52,20.93907822718334 53,21.846642924967878 55,23.65780054647361 C 57,25.46895816797934 58,29.59770889528233 60,30.478035832658914 C 62,31.358362770035498 63,30.083954103126885 65,28.059435233356524 C 67,26.034916363586163 68,23.634298391316904 70,20.355441483807105 C 72,17.076584576297307 73,10.613809929890508 75,11.66515069580754 C 77,12.716491461724573 78,23.133010474791526 80,25.612145313392272 C 82,28.09128015199302 83,25.972735523268547 85,24.06082488881126 C 87,22.14891425435398 88,19.361441322345048 90,16.052592141105855 C 92,12.743742959866662 94,9.223781614313411 95,7.5165789826153"
fill="none"
stroke-width="3px"
className="stroke-slate-900"
/>
</svg>
</Stat>
<Stat to={stats.posts} text="Total Posts">
<svg className="w-[100px] h-[50px]" viewBox="0 0 100 50">
<path
d="M 0,49.68634390054976 C 1,49.14994240565811 3,47.831186591337946 5,47.00433642609152 C 7,46.17748626084509 8,46.35993791120191 10,45.55209307431762 C 12,44.744248237433325 13,43.56397629839403 15,42.96511224167007 C 17,42.36624818494611 18,44.01252563293295 20,42.5577727906978 C 22,41.103019948462645 23,36.56863627977745 25,35.691348030494304 C 27,34.81405978121116 28,38.91405222442457 30,38.17133154428206 C 32,37.42861086413955 33,33.81838901472956 35,31.977744629781736 C 37,30.13710024483391 38,29.010220623139396 40,28.968109619542933 C 42,28.92599861594647 43,32.327547816049744 45,31.767189611799417 C 47,31.20683140754909 48,27.92632953123746 50,26.1663185982913 C 52,24.406307665345143 53,24.381120950272056 55,22.96713494706863 C 57,21.553148943865203 58,20.472775986524404 60,19.096388582274173 C 62,17.720001178023942 63,17.21985330044139 65,16.085197925817475 C 67,14.95054255119356 68,11.189441812098853 70,13.423111709154604 C 72,15.656781606210355 73,25.015222396994087 75,27.25354741109623 C 77,29.49187242519837 78,26.476600952247182 80,24.614736779665314 C 82,22.752872607083447 83,21.550198999674265 85,17.94422654818689 C 87,14.338254096699515 88,10.3366076745192 90,6.584874522228439 C 92,2.8331413699376786 94,0.6654235338321559 95,-0.8144392132669154"
fill="none"
stroke-width="3px"
className="stroke-slate-900"
/>
</svg>
</Stat>
</div>
)}
<div className="mx-auto flex w-full flex-col gap-4 md:max-w-[52rem]">
<p className="leading-normal text-slate-700 sm:leading-7">
The numbers are pulled from the production database.{" "}
<em>The charts are for illustrative purposes only.</em>
</p>
</div>
</section>
)
}

64
components/stat.tsx Normal file
View file

@ -0,0 +1,64 @@
"use client"
import * as React from "react"
import { useMotionValue, useSpring } from "framer-motion"
import { cn, formatNumber } from "@/lib/utils"
interface StatProps extends React.HTMLAttributes<HTMLDivElement> {
from?: number
to: number
text?: string
}
export function Stat({
from = 0,
to,
text,
className,
children,
...props
}: StatProps) {
const ref = React.useRef<HTMLHeadingElement>(null)
const value = useMotionValue(0)
const spring = useSpring(value)
React.useEffect(() => {
value.set(to)
}, [value, to])
React.useEffect(
() =>
spring.onChange((value) => {
if (ref?.current) {
ref.current.textContent = formatNumber(value.toFixed(0))
}
}),
[spring]
)
return (
<div
className={cn(
"border border-slate-200 rounded-md grid grid-cols-[1fr_100px] gap-4 items-center p-6",
className
)}
{...props}
>
<div className="space-y-2">
<h2
ref={ref}
className="text-5xl lg:text-6xl tracking-tighter font-bold"
>
{from}
</h2>
{text && (
<p className={cn("text-sm text-slate-600", className)} {...props}>
{text}
</p>
)}
</div>
{children}
</div>
)
}

View file

@ -4,8 +4,7 @@ export const marketingConfig: MarketingConfig = {
mainNav: [
{
title: "Features",
href: "/features",
disabled: true,
href: "/#features",
},
{
title: "Pricing",
@ -15,14 +14,13 @@ export const marketingConfig: MarketingConfig = {
title: "Blog",
href: "/blog",
},
{
title: "Stats",
href: "/stats",
},
{
title: "Documentation",
href: "/docs",
},
{
title: "Contact",
href: "/contact",
disabled: true,
},
],
}

5
lib/planetscale.ts Normal file
View file

@ -0,0 +1,5 @@
import { connect } from "@planetscale/database"
export const planetScale = connect({
url: process.env.PLANETSCALE_SERVERLESS_DATABASE_URL,
})

View file

@ -14,6 +14,10 @@ export function formatDate(input: string | number): string {
})
}
export function formatNumber(input: number | bigint) {
return Intl.NumberFormat("en-US").format(input)
}
export function absoluteUrl(path: string) {
return `${process.env.NEXT_PUBLIC_APP_URL}${path}`
}

View file

@ -28,6 +28,7 @@
"@hookform/resolvers": "^2.9.10",
"@next-auth/prisma-adapter": "^1.0.4",
"@next/font": "^13.0.3",
"@planetscale/database": "^1.4.0",
"@prisma/client": "^4.5.0",
"@radix-ui/react-alert-dialog": "^1.0.2",
"@radix-ui/react-avatar": "^1.0.1",
@ -39,6 +40,7 @@
"clsx": "^1.2.1",
"contentlayer": "^0.2.9",
"date-fns": "^2.29.3",
"framer-motion": "^7.6.12",
"lucide-react": "^0.92.0",
"next": "^13.1.0",
"next-auth": "^4.18.7",

View file

@ -15,6 +15,7 @@ specifiers:
"@hookform/resolvers": ^2.9.10
"@next-auth/prisma-adapter": ^1.0.4
"@next/font": ^13.0.3
"@planetscale/database": ^1.4.0
"@prisma/client": ^4.5.0
"@radix-ui/react-alert-dialog": ^1.0.2
"@radix-ui/react-avatar": ^1.0.1
@ -33,6 +34,7 @@ specifiers:
date-fns: ^2.29.3
eslint: 8.21.0
eslint-config-next: ^13.0.0
framer-motion: ^7.6.12
husky: ^8.0.2
lucide-react: ^0.92.0
mdast-util-toc: ^6.1.0
@ -83,6 +85,7 @@ dependencies:
"@hookform/resolvers": 2.9.10_react-hook-form@7.39.5
"@next-auth/prisma-adapter": 1.0.5_oxrzh4zbpojkypzd3tdxppynue
"@next/font": 13.0.4
"@planetscale/database": 1.5.0
"@prisma/client": 4.6.1_prisma@4.6.1
"@radix-ui/react-alert-dialog": 1.0.2_bb2bxwco6ptpubzwpazr52qf6i
"@radix-ui/react-avatar": 1.0.1_biqbaboplfbrettd7655fr4n2y
@ -94,6 +97,7 @@ dependencies:
clsx: 1.2.1
contentlayer: 0.2.9_esbuild@0.14.54
date-fns: 2.29.3
framer-motion: 7.6.19_biqbaboplfbrettd7655fr4n2y
lucide-react: 0.92.0_sh5qlbywuemxd2y3xkrw2y2kr4
next: 13.1.0_biqbaboplfbrettd7655fr4n2y
next-auth: 4.18.7_idzega45vxhfgiuuxa3rl6d5b4
@ -685,6 +689,25 @@ packages:
}
dev: false
/@emotion/is-prop-valid/0.8.8:
resolution:
{
integrity: sha512-u5WtneEAr5IDG2Wv65yhunPSMLIpuKsbuOktRojfrEiEvRyC85LgPMZI63cr7NUqT8ZIGdSVg8ZKGxIug4lXcA==,
}
requiresBuild: true
dependencies:
"@emotion/memoize": 0.7.4
dev: false
optional: true
/@emotion/memoize/0.7.4:
resolution:
{
integrity: sha512-Ja/Vfqe3HpuzRsG1oBtWTHk2PGZ7GR+2Vz5iYGelAw8dx32K0y7PjVuxK6z1nMpZOqAFsRUPCkK1YjJ56qJlgw==,
}
dev: false
optional: true
/@esbuild-plugins/node-resolve/0.1.4_esbuild@0.14.54:
resolution:
{
@ -930,6 +953,71 @@ packages:
- supports-color
dev: false
/@motionone/animation/10.15.1:
resolution:
{
integrity: sha512-mZcJxLjHor+bhcPuIFErMDNyrdb2vJur8lSfMCsuCB4UyV8ILZLvK+t+pg56erv8ud9xQGK/1OGPt10agPrCyQ==,
}
dependencies:
"@motionone/easing": 10.15.1
"@motionone/types": 10.15.1
"@motionone/utils": 10.15.1
tslib: 2.4.1
dev: false
/@motionone/dom/10.13.1:
resolution:
{
integrity: sha512-zjfX+AGMIt/fIqd/SL1Lj93S6AiJsEA3oc5M9VkUr+Gz+juRmYN1vfvZd6MvEkSqEjwPQgcjN7rGZHrDB9APfQ==,
}
dependencies:
"@motionone/animation": 10.15.1
"@motionone/generators": 10.15.1
"@motionone/types": 10.15.1
"@motionone/utils": 10.15.1
hey-listen: 1.0.8
tslib: 2.4.1
dev: false
/@motionone/easing/10.15.1:
resolution:
{
integrity: sha512-6hIHBSV+ZVehf9dcKZLT7p5PEKHGhDwky2k8RKkmOvUoYP3S+dXsKupyZpqx5apjd9f+php4vXk4LuS+ADsrWw==,
}
dependencies:
"@motionone/utils": 10.15.1
tslib: 2.4.1
dev: false
/@motionone/generators/10.15.1:
resolution:
{
integrity: sha512-67HLsvHJbw6cIbLA/o+gsm7h+6D4Sn7AUrB/GPxvujse1cGZ38F5H7DzoH7PhX+sjvtDnt2IhFYF2Zp1QTMKWQ==,
}
dependencies:
"@motionone/types": 10.15.1
"@motionone/utils": 10.15.1
tslib: 2.4.1
dev: false
/@motionone/types/10.15.1:
resolution:
{
integrity: sha512-iIUd/EgUsRZGrvW0jqdst8st7zKTzS9EsKkP+6c6n4MPZoQHwiHuVtTQLD6Kp0bsBLhNzKIBlHXponn/SDT4hA==,
}
dev: false
/@motionone/utils/10.15.1:
resolution:
{
integrity: sha512-p0YncgU+iklvYr/Dq4NobTRdAPv9PveRDUXabPEeOjBLSO/1FNB2phNTZxOxpi1/GZwYpAoECEa0Wam+nsmhSw==,
}
dependencies:
"@motionone/types": 10.15.1
hey-listen: 1.0.8
tslib: 2.4.1
dev: false
/@next-auth/prisma-adapter/1.0.5_oxrzh4zbpojkypzd3tdxppynue:
resolution:
{
@ -1378,6 +1466,14 @@ packages:
tslib: 2.4.1
dev: true
/@planetscale/database/1.5.0:
resolution:
{
integrity: sha512-Qwh7Or1W5dB5mZ9EQqDkgvkDKhBBmQe58KIVUy0SGocNtr5fP4JAWtvZ6EdLAV6C6hVpzNlCA2xIg9lKTswm1Q==,
}
engines: { node: ">=16" }
dev: false
/@prisma/client/4.6.1_prisma@4.6.1:
resolution:
{
@ -4623,6 +4719,35 @@ packages:
}
dev: true
/framer-motion/7.6.19_biqbaboplfbrettd7655fr4n2y:
resolution:
{
integrity: sha512-U+ogwGwNw6Y+pdq6GZB5xvnvLDlq3FTmcKaG5MCUjXuqRLrjKbKTqN4iwZISv3ajwUfgNHM6+tu31LRbYfF9YQ==,
}
peerDependencies:
react: ^18.0.0
react-dom: ^18.0.0
dependencies:
"@motionone/dom": 10.13.1
framesync: 6.1.2
hey-listen: 1.0.8
react: 18.2.0
react-dom: 18.2.0_react@18.2.0
style-value-types: 5.1.2
tslib: 2.4.0
optionalDependencies:
"@emotion/is-prop-valid": 0.8.8
dev: false
/framesync/6.1.2:
resolution:
{
integrity: sha512-jBTqhX6KaQVDyus8muwZbBeGGP0XgujBRbQ7gM7BRdS3CadCZIHiawyzYLnafYcvZIh5j8WE7cxZKFn7dXhu9g==,
}
dependencies:
tslib: 2.4.0
dev: false
/fs-constants/1.0.0:
resolution:
{
@ -5137,6 +5262,13 @@ packages:
space-separated-tokens: 2.0.2
dev: true
/hey-listen/1.0.8:
resolution:
{
integrity: sha512-COpmrF2NOg4TBWUJ5UVyaCU2A88wEMkUPK4hNqyCkqHbxT92BbvfjoSozkAIIm6XhicGlJHhFdullInrdhwU8Q==,
}
dev: false
/hosted-git-info/2.8.9:
resolution:
{
@ -8752,6 +8884,16 @@ packages:
inline-style-parser: 0.1.1
dev: false
/style-value-types/5.1.2:
resolution:
{
integrity: sha512-Vs9fNreYF9j6W2VvuDTP7kepALi7sk0xtk2Tu8Yxi9UoajJdEVpNpCov0HsLTqXvNGKX+Uv09pkozVITi1jf3Q==,
}
dependencies:
hey-listen: 1.0.8
tslib: 2.4.0
dev: false
/styled-jsx/5.1.1_react@18.2.0:
resolution:
{
@ -9043,6 +9185,13 @@ packages:
}
dev: true
/tslib/2.4.0:
resolution:
{
integrity: sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==,
}
dev: false
/tslib/2.4.1:
resolution:
{