server all the actions!

This commit is contained in:
2025-02-08 12:37:41 -05:00
parent fa5edc003f
commit 37375b766f
27 changed files with 689 additions and 707 deletions
-43
View File
@@ -1,43 +0,0 @@
"use client";
import useSWRImmutable from "swr/immutable";
import { useErrorBoundary } from "react-error-boundary";
import commaNumber from "comma-number";
import Loading from "../Loading";
import fetcher from "../../lib/helpers/fetcher";
import type { PageStats } from "../../types";
export type HitCounterProps = {
slug: string;
};
const HitCounter = ({ slug }: HitCounterProps) => {
const { showBoundary } = useErrorBoundary();
// use immutable SWR to avoid double (or more) counting views:
// https://swr.vercel.app/docs/revalidation#disable-automatic-revalidations
const { data, error } = useSWRImmutable<PageStats>(
`/api/count/?${new URLSearchParams({
slug,
})}`,
fetcher
);
// fail somewhat silently, see error boundary in PostMeta component
if (error) {
showBoundary(`${error}`);
return null;
}
// show spinning loading indicator if data isn't fetched yet
if (!data) {
return <Loading boxes={3} width={20} />;
}
// we have data!
return (
<span title={`${commaNumber(data.hits)} ${data.hits === 1 ? "view" : "views"}`}>{commaNumber(data.hits)}</span>
);
};
export default HitCounter;
-2
View File
@@ -1,2 +0,0 @@
export * from "./HitCounter";
export { default } from "./HitCounter";