From d63feef43c7332bc5406278007e74a8dd3b28927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20P=C4=99dzich?= Date: Sat, 16 Sep 2023 10:33:24 +0200 Subject: [PATCH] Refactor cat card and cat profile components --- src/components/CatCard.astro | 42 ++++++++++++++++----------------- src/pages/[...page].astro | 16 ++++++------- src/pages/cats/[...catId].astro | 8 ++++--- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/components/CatCard.astro b/src/components/CatCard.astro index 5e12ed5..7544225 100644 --- a/src/components/CatCard.astro +++ b/src/components/CatCard.astro @@ -28,10 +28,6 @@ const { cat } = Astro.props; diff --git a/src/pages/[...page].astro b/src/pages/[...page].astro index 1091230..3deb476 100644 --- a/src/pages/[...page].astro +++ b/src/pages/[...page].astro @@ -14,20 +14,20 @@ export async function getStaticPaths() { (a, b) => b.data.dateAdded.valueOf() - a.data.dateAdded.valueOf() ); - const NUM_CATS_PER_PAGE = 18; - const maxPageNum = Math.ceil(allCats.length / NUM_CATS_PER_PAGE); + const CATS_PER_PAGE = 18; + const maxPageNum = Math.ceil(allCats.length / CATS_PER_PAGE); // Create an array of integers in range from 1 to maxPageNum inclusive: - const allPageNums = [...Array(maxPageNum + 1).keys()].slice(1); + const pageNums = [...Array(maxPageNum + 1).keys()].slice(1); - return allPageNums.map((pageNum) => ({ + return pageNums.map((pageNum) => ({ params: { page: pageNum === 1 ? undefined : pageNum.toString() }, props: { cats: allCats.slice( - NUM_CATS_PER_PAGE * (pageNum - 1), - NUM_CATS_PER_PAGE * pageNum + CATS_PER_PAGE * (pageNum - 1), + CATS_PER_PAGE * pageNum ), - pageNums: allPageNums + pageNums } })); } @@ -52,7 +52,7 @@ const currentPageNum = Number(page || '1'); { pageNums.map((num) => ( {num} diff --git a/src/pages/cats/[...catId].astro b/src/pages/cats/[...catId].astro index 9f42bc8..94afaf3 100644 --- a/src/pages/cats/[...catId].astro +++ b/src/pages/cats/[...catId].astro @@ -3,18 +3,20 @@ import { getCollection, type CollectionEntry } from 'astro:content'; import BaseLayout from '../../layouts/BaseLayout.astro'; -type Props = CollectionEntry<'cats'>; +export interface Props { + cat: CollectionEntry<'cats'>; +} export async function getStaticPaths() { const cats = await getCollection('cats'); return cats.map((cat) => ({ params: { catId: cat.id }, - props: cat + props: { cat } })); } -const cat = Astro.props; +const { cat } = Astro.props; const title = `${cat.data.owner.name}'s ${cat.data.name}`; ---