Skip to content

Commit

Permalink
feat: seed and revlidate
Browse files Browse the repository at this point in the history
  • Loading branch information
sadmann7 committed May 27, 2024
1 parent 7e392e5 commit 008096f
Show file tree
Hide file tree
Showing 43 changed files with 451 additions and 337 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"
import { toast } from "sonner"

import { deleteProduct, updateProduct } from "@/lib/actions/product"
import { getErrorMessage } from "@/lib/handle-error"
import {
deleteProduct,
updateProduct,
type getCategories,
type getSubcategories,
} from "@/lib/actions/product"
import { getErrorMessage } from "@/lib/handle-error"
} from "@/lib/queries/product"
import {
updateProductSchema,
type UpdateProductSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { products } from "@/db/schema"
import { env } from "@/env.js"
import { and, eq } from "drizzle-orm"

import { getCategories, getSubcategories } from "@/lib/actions/product"
import { getCategories, getSubcategories } from "@/lib/queries/product"
import {
Card,
CardContent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"
import { toast } from "sonner"

import { addProduct } from "@/lib/actions/product"
import { getErrorMessage } from "@/lib/handle-error"
import {
addProduct,
type getCategories,
type getSubcategories,
} from "@/lib/actions/product"
import { getErrorMessage } from "@/lib/handle-error"
} from "@/lib/queries/product"
import {
createProductSchema,
type CreateProductSchema,
Expand Down
2 changes: 1 addition & 1 deletion src/app/(dashboard)/store/[storeId]/products/new/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Metadata } from "next"
import { redirect } from "next/navigation"
import { env } from "@/env.js"

import { getCategories, getSubcategories } from "@/lib/actions/product"
import { getCategories, getSubcategories } from "@/lib/queries/product"
import { getCachedUser } from "@/lib/queries/user"
import {
Card,
Expand Down
2 changes: 1 addition & 1 deletion src/app/(lobby)/_components/category-card-skeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Skeleton } from "@/components/ui/skeleton"

export function CategoryCardSkeleton() {
return (
<Card className="h-full rounded-md">
<Card className="h-full rounded-lg">
<CardHeader className="flex-1">
<Skeleton className="h-6 w-20" />
<Skeleton className="h-4 w-5/6" />
Expand Down
11 changes: 7 additions & 4 deletions src/app/(lobby)/_components/category-card.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import * as React from "react"
import Link from "next/link"

import { getProductCount, type getCategories } from "@/lib/actions/product"
import {
getProductCountByCategory,
type getCategories,
} from "@/lib/queries/product"
import {
Card,
CardContent,
Expand All @@ -17,13 +20,13 @@ interface CategoryCardProps {
}

export function CategoryCard({ category }: CategoryCardProps) {
const productCountPromise = getProductCount({
const productCountPromise = getProductCountByCategory({
categoryId: category.id,
})

return (
<Link href={`/collections/${category.slug}`}>
<Card className="h-full rounded-md transition-colors hover:bg-muted/25">
<Card className="h-full rounded-lg transition-colors hover:bg-muted/25">
<CardHeader className="flex-1">
<CardTitle className="capitalize">{category.name}</CardTitle>
<CardDescription className="line-clamp-3 text-balance">
Expand All @@ -41,7 +44,7 @@ export function CategoryCard({ category }: CategoryCardProps) {
}

interface ProductCountProps {
productCountPromise: ReturnType<typeof getProductCount>
productCountPromise: ReturnType<typeof getProductCountByCategory>
}

async function ProductCount({ productCountPromise }: ProductCountProps) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/(lobby)/_components/lobby.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Link from "next/link"

import { siteConfig } from "@/config/site"
import type { getCategories, getFeaturedProducts } from "@/lib/actions/product"
import { type getGithubStars } from "@/lib/queries/github"
import type { getCategories, getFeaturedProducts } from "@/lib/queries/product"
import { type getFeaturedStores } from "@/lib/queries/store"
import { cn } from "@/lib/utils"
import { Badge } from "@/components/ui/badge"
Expand Down
2 changes: 1 addition & 1 deletion src/app/(lobby)/build-a-board/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { env } from "@/env.js"
import { CheckIcon, CircleIcon } from "@radix-ui/react-icons"

import { getCartItems } from "@/lib/actions/cart"
import { getProducts } from "@/lib/actions/product"
import { getProducts } from "@/lib/queries/product"
import { cn } from "@/lib/utils"
import { productsSearchParamsSchema } from "@/lib/validations/params"
import { BoardBuilder } from "@/components/board-builder"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Metadata } from "next"
import { env } from "@/env.js"

import { getProducts } from "@/lib/actions/product"
import { getProducts } from "@/lib/queries/product"
import { getStores } from "@/lib/queries/store"
import { toTitleCase, unslugify } from "@/lib/utils"
import { productsSearchParamsSchema } from "@/lib/validations/params"
Expand Down
4 changes: 1 addition & 3 deletions src/app/(lobby)/collections/[category]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Metadata } from "next"
import { env } from "@/env.js"
import type { SearchParams } from "@/types"

import { getProducts } from "@/lib/actions/product"
import { getProducts } from "@/lib/queries/product"
import { toTitleCase } from "@/lib/utils"
import { AlertCard } from "@/components/alert-card"
import {
Expand Down Expand Up @@ -35,8 +35,6 @@ export default async function CategoryPage({

const productsTransaction = await getProducts(searchParams)

console.log({ productsTransaction })

return (
<Shell>
<PageHeader>
Expand Down
4 changes: 2 additions & 2 deletions src/app/(lobby)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as React from "react"

import { getCategories, getFeaturedProducts } from "@/lib/actions/product"
import { getGithubStars } from "@/lib/queries/github"
import { getCategories, getFeaturedProducts } from "@/lib/queries/product"
import { getFeaturedStores } from "@/lib/queries/store"

import { Lobby } from "./_components/lobby"
import { LobbySkeleton } from "./_components/lobby-skeleton"

export default function IndexPage() {
export default async function IndexPage() {
/**
* To avoid sequential waterfall requests, multiple promises are passed to fetch data parallelly.
* These promises are also passed to the `Lobby` component, making them hot promises. This means they can execute without being awaited, further preventing sequential requests.
Expand Down
2 changes: 1 addition & 1 deletion src/app/(lobby)/products/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type Metadata } from "next"
import { env } from "@/env.js"
import type { SearchParams } from "@/types"

import { getProducts } from "@/lib/actions/product"
import { getProducts } from "@/lib/queries/product"
import { AlertCard } from "@/components/alert-card"
import {
PageHeader,
Expand Down
23 changes: 23 additions & 0 deletions src/app/api/revalidate/[tag]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { revalidateTag } from "next/cache"
import { env } from "@/env"
import { z } from "zod"

const schema = z.object({
params: z.object({
tag: z.string(),
}),
})

export async function POST(req: Request, context: z.infer<typeof schema>) {
if (env.NODE_ENV !== "development") {
return new Response("Not allowed", { status: 403 })
}

const {
params: { tag },
} = schema.parse(context)

revalidateTag(tag)

return new Response(`revalidated: ${tag}`, { status: 200 })
}
12 changes: 12 additions & 0 deletions src/app/api/revalidate/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { revalidatePath } from "next/cache"
import { env } from "@/env"

export async function GET() {
if (env.NODE_ENV !== "development") {
return Response.json({ message: "Not allowed" }, { status: 403 })
}

revalidatePath("/")

return new Response("revalidated everything", { status: 200 })
}
2 changes: 1 addition & 1 deletion src/components/product-card-skeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function ProductCardSkeleton({
}: ProductCardSkeletonProps) {
return (
<Card
className={cn("h-full overflow-hidden rounded-md", className)}
className={cn("h-full overflow-hidden rounded-lg", className)}
{...props}
>
<CardHeader className="border-b p-0">
Expand Down
2 changes: 1 addition & 1 deletion src/components/product-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function ProductCard({

return (
<Card
className={cn("size-full overflow-hidden rounded-md", className)}
className={cn("size-full overflow-hidden rounded-lg", className)}
{...props}
>
<Link aria-label={product.name} href={`/product/${product.id}`}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/products.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { queryConfig } from "@/config/query"
import {
type getCategories,
type getSubcategoriesByCategory,
} from "@/lib/actions/product"
} from "@/lib/queries/product"
import { cn, toTitleCase, truncate } from "@/lib/utils"
import { useDebounce } from "@/hooks/use-debounce"
import { Button } from "@/components/ui/button"
Expand Down
2 changes: 1 addition & 1 deletion src/components/store-card-skeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Skeleton } from "@/components/ui/skeleton"

export function StoreCardSkeleton() {
return (
<Card className="relative h-full rounded-md">
<Card className="relative h-full rounded-lg">
<Skeleton className="absolute right-4 top-4 h-4 w-20 rounded-sm px-2 py-0.5" />
<CardHeader>
<Skeleton className="h-4 w-1/2" />
Expand Down
2 changes: 1 addition & 1 deletion src/components/store-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function StoreCard({ store, href }: StoreCardProps) {

return (
<Link href={href}>
<Card className="relative h-full rounded-md transition-colors hover:bg-muted/25">
<Card className="relative h-full rounded-lg transition-colors hover:bg-muted/25">
{isUserStore ? (
<Tooltip>
<TooltipTrigger asChild>
Expand Down
3 changes: 2 additions & 1 deletion src/components/tables/products-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import { DotsHorizontalIcon } from "@radix-ui/react-icons"
import { type ColumnDef } from "@tanstack/react-table"
import { toast } from "sonner"

import { deleteProduct, type getCategories } from "@/lib/actions/product"
import { deleteProduct } from "@/lib/actions/product"
import { getErrorMessage } from "@/lib/handle-error"
import { type getCategories } from "@/lib/queries/product"
import { formatDate, formatPrice } from "@/lib/utils"
import { useDataTable } from "@/hooks/use-data-table"
import { Badge } from "@/components/ui/badge"
Expand Down
Loading

0 comments on commit 008096f

Please sign in to comment.