Skip to content

Commit

Permalink
revalidate note and edit notes from dash
Browse files Browse the repository at this point in the history
  • Loading branch information
GraemeFulton committed Aug 26, 2024
1 parent 7aa9103 commit 0fd1ed1
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 32 deletions.
1 change: 1 addition & 0 deletions app/dashboard/published/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default async function AccountPage() {
currentTab="publish"
postStatus={["publish"]}
postType=""
edit={false}
/>
</div>
{/* <AccountPageWrapper userData={userData}/> */}
Expand Down
2 changes: 2 additions & 0 deletions components/Dashboard/PostCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ const PostCard = ({ post, refetch, user, edit }) => {
href={
edit === false && post.type == "article"
? `/post/${post.slug}`
: edit === false && post.type == "note"
? `/note/${post.slug}`
: edit === false && post.type == "tool"
? `/toolbox/${post.slug}`
: post.type == "article" && post.tools?.length
Expand Down
13 changes: 13 additions & 0 deletions pages/api/revalidate.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ export default async function handler(req, res) {
}
return res.json({ revalidated: true });
}
else if (
entry.type == "note" &&
(entry.status === "publish" || entry.publishedAt)
) {
const url = `/note/${entry.slug}`;

await res.revalidate(url);
if (process.env.NODE_ENV == "production") {
await purgeCloudFlareCache(url);
await clearAuthCache(entry.id);
}
return res.json({ revalidated: true });
}
//revalidate jobs
else if (entry.type == "job" && entry.publishedAt) {
console.log("revalidating job post :", entry.slug);
Expand Down
71 changes: 39 additions & 32 deletions pages/note/[slug].js
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,11 @@ export default function Post({

const ogImage = `${
process.env.NEXT_PUBLIC_HOME_URL
}/api/og-generator/og-note?title=${encodeURIComponent(title)}&author=${encodeURIComponent(
authorName
)}&date=${encodeURIComponent(date)}&avatar=${encodeURIComponent(avatar)}`;

}/api/og-generator/og-note?title=${encodeURIComponent(
title
)}&author=${encodeURIComponent(authorName)}&date=${encodeURIComponent(
date
)}&avatar=${encodeURIComponent(avatar)}`;

return (
<Layout
Expand All @@ -163,31 +164,6 @@ export default function Post({
maxWidth="max-w-full mx-auto -mt-[96px] bg-gray-100/20"
>
<div className="w-full h-full grid grid-cols-12 gap-1 mx-auto mx-auto bg-gray-100/20">
{user?.isAdmin && (
<div className="fixed bottom-0 mb-6 z-50 border border-gray-200 bg-white mr-20 right-0 p-2 px-3 rounded-full shadow-sm">
{/* <button className="p-1 px-3 text-sm text-white bg-purple-600 shadow rounded"> */}
<Link href={`/n/${post?.id}`}>
<div className="flex text-gray-700">
<PenLineSimple className="w-4 h-4 my-auto mr-2" />
<div className="my-auto text-sm">Edit</div>
</div>
</Link>
{/* </button> */}
</div>
)}
{!user?.isAdmin && user?.id == post?.attributes?.author?.data?.id ? (
<div className="fixed bottom-0 mb-6 z-50 border border-gray-200 bg-white mr-20 right-0 p-2 px-3 rounded-full shadow-sm">
{/* <button className="p-1 px-3 text-sm text-white bg-purple-600 shadow rounded"> */}
<Link href={`/n/${post?.id}`}>
<div className="flex text-gray-700">
<PenLineSimple className="w-4 h-4 my-auto mr-2" />
<div className="my-auto text-sm">Edit</div>
</div>
</Link>
{/* </button> */}
</div>
) : null}

{/* <Alert preview={preview} /> */}
<main className="gap-2 col-span-12 lg:col-span-12 px-0 ">
{/* {post?.id && process.env.NODE_ENV === "production" && (
Expand All @@ -206,8 +182,8 @@ export default function Post({
<div className="inset-0 z-0">
<div className="relative bg-white p-6 flex flex-col justify-start h-full z-10">
<div className="mb-6 text-xs flex font-medium text-gray-500 tracking-tight uppercase p-1 px-2 bg-gray-100 rounded-full w-fit">
<Note className="w-4 h-4 mr-1" />
<div className="text-[11px]">Note</div>
<Note className="w-4 h-4 mr-1" />
<div className="text-[11px]">Note</div>
</div>
<h1 className="text-[44px] tracking-tight mb-6 w-full leading-tight md:max-w-[90%] text-black/90 font-medium text-left drop-shadow-sm">
{title}
Expand Down Expand Up @@ -268,13 +244,44 @@ export default function Post({
</div>
) : null}

<div className="my-3 py-3 border-b border-t border-gray-200">
<div className="my-3 py-3 border-b border-t border-gray-200 flex justify-between">
<SocialShare
slug={post?.attributes?.slug}
title={title}
authorTwitter={author?.twitter}
postType="note"
/>
<div className="flex items-center">
{user?.isAdmin && (
<div className="border border-gray-200 bg-white mr-1 p-1 px-3 rounded-full shadow-sm">
{/* <button className="p-1 px-3 text-sm text-white bg-purple-600 shadow rounded"> */}
<Link href={`/n/${post?.id}`}>
<div className="flex text-gray-700">
<PenLineSimple className="w-4 h-4 my-auto mr-2" />
<div className="my-auto text-sm">
Edit
</div>
</div>
</Link>
{/* </button> */}
</div>
)}
{!user?.isAdmin &&
user?.id == post?.attributes?.author?.data?.id ? (
<div className="border border-gray-200 bg-white mr-1 p-1 px-3 rounded-full shadow-sm">
{/* <button className="p-1 px-3 text-sm text-white bg-purple-600 shadow rounded"> */}
<Link href={`/n/${post?.id}`}>
<div className="flex text-gray-700">
<PenLineSimple className="w-4 h-4 my-auto mr-2" />
<div className="my-auto text-sm">
Edit
</div>
</div>
</Link>
{/* </button> */}
</div>
) : null}
</div>
</div>
<div
className="max-w-full blog-content w-[44rem] mt-6 mx-auto"
Expand Down

0 comments on commit 0fd1ed1

Please sign in to comment.