cleaned code from logs and some comments
This commit is contained in:
@@ -108,7 +108,7 @@ export default function CategoryFilters({
|
||||
}}
|
||||
/>
|
||||
|
||||
<Button variant="outline" className="w-full rounded-xl" onClick={onReset}>
|
||||
<Button variant="outline" className="w-full rounded-lg cursor-pointer" onClick={onReset}>
|
||||
{translations.reset}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -28,7 +28,7 @@ export default function CategoryFiltersSheet({
|
||||
<Sheet open={isOpen} onOpenChange={onOpenChange}>
|
||||
<SheetTrigger asChild>
|
||||
<Button
|
||||
className="bg-[#005bff] hover:bg-[#0041c4] sm:hidden fixed bottom-20 right-4 rounded-xl font-bold gap-2 z-10 shadow-lg"
|
||||
className="bg-[#005bff] hover:bg-[#0041c4] sm:hidden fixed bottom-20 right-4 rounded-lg cursor-pointer font-bold gap-2 z-10 shadow-lg"
|
||||
size="lg"
|
||||
>
|
||||
{filterLabel}
|
||||
@@ -40,7 +40,7 @@ export default function CategoryFiltersSheet({
|
||||
<SheetTitle>{filterLabel}</SheetTitle>
|
||||
<button
|
||||
onClick={() => onOpenChange(false)}
|
||||
className="absolute top-4 right-4 rounded-md ring-offset-background transition-opacity hover:opacity-100"
|
||||
className="absolute top-4 right-4 rounded-md cursor-pointer ring-offset-background transition-opacity hover:opacity-100"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
<span className="sr-only">{closeLabel}</span>
|
||||
|
||||
@@ -106,22 +106,19 @@ export default function CategoryPageClient({
|
||||
}
|
||||
}, [selectedCategory?.id]);
|
||||
|
||||
// Update products list - BU KISIM ÖNEMLİ!
|
||||
// Update products list
|
||||
useEffect(() => {
|
||||
if (productsData?.data) {
|
||||
setAllProducts((prev) => {
|
||||
// İlk sayfa ise direkt replace et
|
||||
if (currentPage === 1) {
|
||||
return productsData.data;
|
||||
}
|
||||
|
||||
// Sonraki sayfalar için deduplicate et
|
||||
const existingIds = new Set(prev.map((p) => p.id));
|
||||
const newProducts = productsData.data.filter(
|
||||
(p: Product) => !existingIds.has(p.id)
|
||||
);
|
||||
|
||||
// Eğer yeni ürün yoksa, return prev (gereksiz re-render önlenir)
|
||||
if (newProducts.length === 0) {
|
||||
return prev;
|
||||
}
|
||||
@@ -129,16 +126,13 @@ export default function CategoryPageClient({
|
||||
return [...prev, ...newProducts];
|
||||
});
|
||||
}
|
||||
}, [productsData?.data, currentPage]); // productsData yerine productsData.data
|
||||
}, [productsData?.data, currentPage]);
|
||||
|
||||
// hasMore hesaplama - BU KISIM DA ÖNEMLİ!
|
||||
const hasMore = useMemo(() => {
|
||||
if (!productsData?.pagination) return false;
|
||||
|
||||
// pagination.next_page_url varsa devam et
|
||||
if (productsData.pagination.next_page_url) return true;
|
||||
|
||||
// Alternatif olarak: current_page < last_page kontrolü
|
||||
if (
|
||||
productsData.pagination.current_page &&
|
||||
productsData.pagination.last_page
|
||||
@@ -148,7 +142,6 @@ export default function CategoryPageClient({
|
||||
);
|
||||
}
|
||||
|
||||
// Alternatif 2: hasMorePages flag'i varsa
|
||||
if (productsData.pagination.hasMorePages !== undefined) {
|
||||
return productsData.pagination.hasMorePages;
|
||||
}
|
||||
@@ -158,7 +151,6 @@ export default function CategoryPageClient({
|
||||
|
||||
const loadMoreData = useCallback(() => {
|
||||
if (!hasMore || isFetching) return;
|
||||
console.log("Loading page:", currentPage + 1); // Debug için
|
||||
setCurrentPage((prev) => prev + 1);
|
||||
}, [hasMore, isFetching, currentPage]);
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ interface CategoryProductsGridProps {
|
||||
products: Product[];
|
||||
hasMore: boolean;
|
||||
onLoadMore: () => void;
|
||||
isFetching?: boolean; // Yeni prop - loading durumu için
|
||||
isFetching?: boolean;
|
||||
translations: {
|
||||
loading: string;
|
||||
no_results: string;
|
||||
@@ -46,7 +46,6 @@ export default function CategoryProductsGrid({
|
||||
endMessage={
|
||||
products.length > 0 && !hasMore ? (
|
||||
<div className="text-center py-4 text-gray-500 text-sm">
|
||||
{/* Opsiyonel: "Tüm ürünler yüklendi" mesajı */}
|
||||
</div>
|
||||
) : null
|
||||
}
|
||||
@@ -68,7 +67,6 @@ export default function CategoryProductsGrid({
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* İlk yükleme için skeleton göster */}
|
||||
{isFetching && products.length === 0 && (
|
||||
<div className="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-3 mt-3">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
|
||||
Reference in New Issue
Block a user