feat: refactor article components to use searchParams for pagination and improve content loading
This commit is contained in:
@@ -10,6 +10,10 @@ interface ArticlePageProps {
|
||||
params: Promise<{ slug: string }>;
|
||||
}
|
||||
|
||||
interface ArticleContentProps {
|
||||
params: Promise<{ slug: string }>;
|
||||
}
|
||||
|
||||
function readingTime(text: string): number {
|
||||
const words = text.trim().split(/\s+/).length;
|
||||
return Math.max(1, Math.ceil(words / 200));
|
||||
@@ -64,7 +68,8 @@ const ArticleContentSkeleton = () => (
|
||||
</article>
|
||||
);
|
||||
|
||||
const ArticleContent = async ({ slug }: { slug: string }) => {
|
||||
const ArticleContent = async ({ params }: ArticleContentProps) => {
|
||||
const { slug } = await params;
|
||||
const article = await getArticleBySlug(slug);
|
||||
|
||||
if (!article) notFound();
|
||||
@@ -137,12 +142,10 @@ const ArticleContent = async ({ slug }: { slug: string }) => {
|
||||
);
|
||||
};
|
||||
|
||||
const ArticlePage = async ({ params }: ArticlePageProps) => {
|
||||
const { slug } = await params;
|
||||
|
||||
const ArticlePage = ({ params }: ArticlePageProps) => {
|
||||
return (
|
||||
<Suspense fallback={<ArticleContentSkeleton />}>
|
||||
<ArticleContent slug={slug} />
|
||||
<ArticleContent params={params} />
|
||||
</Suspense>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user