mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2026-06-05 20:15:31 -04:00
fix: don't pre-render view and comment count components
- Introduced a new PostStats component to handle view and comment counts, replacing the previous async implementation with a client-side approach. - Updated CommentCount component to use client-side state management for fetching comment counts. - Removed unnecessary caching logic from view and comment fetching functions. - Simplified date formatting by moving it inline, enhancing performance and readability.
This commit is contained in:
@@ -1,8 +1,31 @@
|
||||
import { env } from "@/lib/env";
|
||||
import { getCommentCounts } from "@/lib/server/comments";
|
||||
"use client";
|
||||
|
||||
const CommentCount = async ({ slug }: { slug: string }) => {
|
||||
const count = await getCommentCounts(slug);
|
||||
import { useEffect, useState } from "react";
|
||||
import { env } from "@/lib/env";
|
||||
import { getCommentCount } from "@/lib/server/comments";
|
||||
|
||||
const CommentCount = ({ slug }: { slug: string }) => {
|
||||
const [count, setCount] = useState<number | null>(null);
|
||||
const [error, setError] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
getCommentCount(slug)
|
||||
.then((result: number) => {
|
||||
setCount(result);
|
||||
})
|
||||
.catch((err: unknown) => {
|
||||
console.error("[comment-count] error:", err);
|
||||
setError(true);
|
||||
});
|
||||
}, [slug]);
|
||||
|
||||
if (error) {
|
||||
return <span title="Error getting comments">?</span>;
|
||||
}
|
||||
|
||||
if (count === null) {
|
||||
return <span className="motion-safe:animate-pulse">0</span>;
|
||||
}
|
||||
|
||||
return (
|
||||
<span
|
||||
|
||||
Reference in New Issue
Block a user