feature/adds-admin-add-article #1
@@ -10,6 +10,7 @@ const nextConfig: NextConfig = {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
|
cacheComponents: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default nextConfig;
|
export default nextConfig;
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ interface ArticlePageProps {
|
|||||||
params: Promise<{ slug: string }>;
|
params: Promise<{ slug: string }>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ArticleContentProps {
|
||||||
|
params: Promise<{ slug: string }>;
|
||||||
|
}
|
||||||
|
|
||||||
function readingTime(text: string): number {
|
function readingTime(text: string): number {
|
||||||
const words = text.trim().split(/\s+/).length;
|
const words = text.trim().split(/\s+/).length;
|
||||||
return Math.max(1, Math.ceil(words / 200));
|
return Math.max(1, Math.ceil(words / 200));
|
||||||
@@ -64,7 +68,8 @@ const ArticleContentSkeleton = () => (
|
|||||||
</article>
|
</article>
|
||||||
);
|
);
|
||||||
|
|
||||||
const ArticleContent = async ({ slug }: { slug: string }) => {
|
const ArticleContent = async ({ params }: ArticleContentProps) => {
|
||||||
|
const { slug } = await params;
|
||||||
const article = await getArticleBySlug(slug);
|
const article = await getArticleBySlug(slug);
|
||||||
|
|
||||||
if (!article) notFound();
|
if (!article) notFound();
|
||||||
@@ -137,12 +142,10 @@ const ArticleContent = async ({ slug }: { slug: string }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const ArticlePage = async ({ params }: ArticlePageProps) => {
|
const ArticlePage = ({ params }: ArticlePageProps) => {
|
||||||
const { slug } = await params;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Suspense fallback={<ArticleContentSkeleton />}>
|
<Suspense fallback={<ArticleContentSkeleton />}>
|
||||||
<ArticleContent slug={slug} />
|
<ArticleContent params={params} />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -37,11 +37,14 @@ const ArticleListSkeleton = () => (
|
|||||||
);
|
);
|
||||||
|
|
||||||
interface ArticleListProps {
|
interface ArticleListProps {
|
||||||
page: number;
|
searchParams: Promise<{ page?: string; pageSize?: string }>;
|
||||||
pageSize: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const ArticleList = async ({ page, pageSize }: ArticleListProps) => {
|
const ArticleList = async ({ searchParams }: ArticleListProps) => {
|
||||||
|
const { page: pageParam, pageSize: pageSizeParam } = await searchParams;
|
||||||
|
const page = Math.max(1, Number(pageParam) || 1);
|
||||||
|
const pageSize = Number(pageSizeParam) || PAGE_SIZE;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: articles,
|
data: articles,
|
||||||
totalPages,
|
totalPages,
|
||||||
@@ -94,10 +97,6 @@ type HomeProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const Home = async ({ searchParams }: HomeProps) => {
|
const Home = async ({ searchParams }: HomeProps) => {
|
||||||
const { page: pageParam, pageSize: pageSizeParam } = await searchParams;
|
|
||||||
const page = Math.max(1, Number(pageParam) || 1);
|
|
||||||
const pageSize = Number(pageSizeParam) || PAGE_SIZE;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='container mx-auto w-full flex-1 px-4 py-12 md:py-16'>
|
<div className='container mx-auto w-full flex-1 px-4 py-12 md:py-16'>
|
||||||
<div className='mb-10 border-b border-border pb-8'>
|
<div className='mb-10 border-b border-border pb-8'>
|
||||||
@@ -109,7 +108,7 @@ const Home = async ({ searchParams }: HomeProps) => {
|
|||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
<Suspense fallback={<ArticleListSkeleton />}>
|
<Suspense fallback={<ArticleListSkeleton />}>
|
||||||
<ArticleList page={page} pageSize={pageSize} />
|
<ArticleList searchParams={searchParams} />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user