Skip to content

Commit

Permalink
product count on homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
RhysSullivan committed Oct 20, 2024
1 parent 30a03a1 commit 28fc436
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/app/(category-sidebar)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import { Link } from "@/components/ui/link";
import { db } from "@/db";
import { products } from "@/db/schema";
import { count } from "drizzle-orm";
import Image from "next/image";

export default async function Home() {
const collections = await db.query.collections.findMany({
with: {
categories: true,
},
orderBy: (collections, { asc }) => asc(collections.name),
});
const [collections, productCount] = await Promise.all([
db.query.collections.findMany({
with: {
categories: true,
},
orderBy: (collections, { asc }) => asc(collections.name),
}),
db.select({ count: count() }).from(products),
]);
let imageCount = 0;

return (
<div className="p-4">
<div className="w-full p-4">
<div className="mb-2 w-full flex-grow border-b-[1px] border-green-800 text-sm font-semibold text-black">
Explore {productCount.at(0)?.count} products
</div>
{collections.map((collection) => (
<div key={collection.name}>
<h2 className="text-xl font-semibold">{collection.name}</h2>
Expand Down

0 comments on commit 28fc436

Please sign in to comment.