Revert: Remove loading spinner - was slowing down page
Suspense boundary added complexity and extra queries, making pages slower. Removed the LoadingSpinner component and Suspense wrapping. Reverted to simpler, faster approach. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 4.5
parent
dc9bceb494
commit
234f03b4dd
@@ -161,7 +161,8 @@
|
||||
"Bash(curl -s \"http://127.0.0.1:3000/products/awd-hoodie\")",
|
||||
"Bash(git commit -m 'Fix: NavDropdown link navigation with stopPropagation *)",
|
||||
"Bash(git commit -m 'Feat: Remove all filters from products pages *)",
|
||||
"Bash(git commit -m 'Feat: Add loading spinner for made-to-order page *)"
|
||||
"Bash(git commit -m 'Feat: Add loading spinner for made-to-order page *)",
|
||||
"Bash(git commit -m 'Revert: Remove loading spinner - was slowing down page *)"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@ import { prisma } from '@/lib/prisma';
|
||||
import { toProductDTO } from '@/lib/product';
|
||||
import { fetchActivePromotions } from '@/lib/promotions';
|
||||
import ProductCard from '@/components/ProductCard';
|
||||
import LoadingSpinner from '@/components/LoadingSpinner';
|
||||
import { Suspense } from 'react';
|
||||
|
||||
type SearchParams = {
|
||||
page?: string;
|
||||
@@ -11,7 +9,8 @@ type SearchParams = {
|
||||
|
||||
const PRODUCTS_PER_PAGE = 20;
|
||||
|
||||
async function ProductsGrid({ currentPage }: { currentPage: number }) {
|
||||
export default async function ProductsPage({ searchParams }: { searchParams: SearchParams }) {
|
||||
const currentPage = Math.max(1, Number(searchParams.page) || 1);
|
||||
const activePromotions = await fetchActivePromotions();
|
||||
|
||||
const [rows, totalCount] = await Promise.all([
|
||||
@@ -27,13 +26,6 @@ async function ProductsGrid({ currentPage }: { currentPage: number }) {
|
||||
const products = rows.map((p) => toProductDTO(p, activePromotions, 'personalised'));
|
||||
const totalPages = Math.ceil(totalCount / PRODUCTS_PER_PAGE);
|
||||
|
||||
return { products, totalPages, totalCount, currentPage };
|
||||
}
|
||||
|
||||
export default async function ProductsPage({ searchParams }: { searchParams: SearchParams }) {
|
||||
const currentPage = Math.max(1, Number(searchParams.page) || 1);
|
||||
const totalCount = await prisma.product.count({ where: { showOnPersonalised: true } });
|
||||
|
||||
return (
|
||||
<div className="mx-auto max-w-6xl px-6 py-12">
|
||||
<div className="mb-12 flex items-baseline justify-between">
|
||||
@@ -43,17 +35,6 @@ export default async function ProductsPage({ searchParams }: { searchParams: Sea
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<Suspense fallback={<LoadingSpinner />}>
|
||||
<ProductsGridContent currentPage={currentPage} totalCount={totalCount} />
|
||||
</Suspense>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
async function ProductsGridContent({ currentPage, totalCount }: { currentPage: number; totalCount: number }) {
|
||||
const { products, totalPages } = await ProductsGrid({ currentPage });
|
||||
|
||||
return (
|
||||
<div>
|
||||
{products.length === 0 ? (
|
||||
<div className="border border-line bg-surface p-12 text-center">
|
||||
@@ -94,5 +75,6 @@ async function ProductsGridContent({ currentPage, totalCount }: { currentPage: n
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
export default function LoadingSpinner() {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-24">
|
||||
<div className="relative h-12 w-12">
|
||||
<div className="absolute inset-0 rounded-full border-4 border-line"></div>
|
||||
<div className="absolute inset-0 animate-spin rounded-full border-4 border-transparent border-t-ink"></div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user