Skip to content

Commit

Permalink
Fix Route Handlers call
Browse files Browse the repository at this point in the history
  • Loading branch information
Kawtar Choubari committed Nov 1, 2023
1 parent bc76011 commit 98e3320
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
10 changes: 3 additions & 7 deletions components/mdx/post-views.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import { countFormatter } from "@/lib/utils";
import { countFormatter, getPostViews } from "@/lib/utils";
import { FaEye } from "react-icons/fa";

interface PostViewsProps {
slug: string;
}

export default async function PostViews({ slug }: PostViewsProps) {
// const response = await fetch(
// `${process.env.NEXT_PUBLIC_APP_URL}/api/views/${slug}`
// );
// const data = await response.json();
const data = await getPostViews(slug);

return (
<div className="text-sm mb-2 opacity-60 flex items-center">
<FaEye className="inline-block mr-2 text-base" />
<p className="italic">
0 views
{/* {data?.total && `${countFormatter(data.total)} views`} */}
{data?.total && `${countFormatter(data.total)} views`}
</p>
</div>
);
Expand Down
7 changes: 7 additions & 0 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ export const validateCaptcha = (response_key) => {
});
};

export async function getPostViews(slug: string) {
const response = await fetch(
`${process.env.NEXT_PUBLIC_APP_URL}/api/views/${slug}`
);
const data = await response.json();
return data;
}
export async function incrementPostViews(slug: string) {
await fetch(`${process.env.NEXT_PUBLIC_APP_URL}/api/views/${slug}`, {
method: "POST",
Expand Down

0 comments on commit 98e3320

Please sign in to comment.